qq15725 / modern-screenshot

📸 Quickly generate image from DOM node using HTML5 canvas and SVG
https://toolpkg.com/html-to-image
MIT License
504 stars 36 forks source link

html元素中包含emoji表情时,生成报错 #35

Closed lujihong closed 1 year ago

lujihong commented 1 year ago

Steps To Reproduce

html元素中包含emoji表情时,生成报错:String contained illegal UTF-16 sequence.

IOS 16.5.1 微信 8.0.39

lujihong commented 1 year ago

修改以下代码就没问题了: function de(e) { const t = new XMLSerializer().serializeToString(e) .replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/ug, ""); //方法一:去掉\uD800-\uDFFF //.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/ug, ""); //方法二:注释掉全部 return data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}; }

qq15725 commented 1 year ago

这段代码是过滤掉 xml 中 null 控制符的,估计是误伤两个 unicode 组成的 emoji 了,可以提供下异常的 emoji

lujihong commented 1 year ago

😊😘 我随便测试了几个emoji都有问题

qq15725 commented 1 year ago
image

https://modern-screenshot.vercel.app/

这两个 emoji 我浏览器是没问题,看是环境问题还是其他 emoji ,最好是把整段有问题的提供下

qq15725 commented 1 year ago

v4.4.27 支持了只启用部分特性

domToPng({
  features: {
    // 不启用移除控制符
    removeControlCharacter: false,
  }
})
lujihong commented 1 year ago

我在MAC 端测试没问题,在安卓端测试也没问题,在IOS 16.5.1 微信8.0.39端测试就不行

jeremiecarlson commented 8 months ago

I have the same issue - iOS only - no issue on desktop Safari Using domToBlob in my use case. Setting removeControlCharacter to true/false makes no difference to the error

jeremiecarlson commented 8 months ago

Using the vercel demo app you can reproduce: Running iPhone 15 simulator on iOS 17.2

Screenshot 2023-12-13 at 1 30 56 PM