Comments (6)
没有出现一条 Failed image load
的警告吗?多半是包含 <foreign-object>
的 svg 元素转 svg+xml
作为图像后解码异常了
可以尝试使用 window.modernScreenshot.domToForeignObjectSvg
将 dom 转成包含 <foreign-object>
的 svg 元素
function svgToDataUrl(svg: SVGElement) {
const xhtml = new XMLSerializer()
.serializeToString(svg)
// https://www.w3.org/TR/xml/#charsets
// eslint-disable-next-line no-control-regex
.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/ug, '')
return `data:image/svg+xml;charset=utf-8,${ encodeURIComponent(xhtml) }`
}
然后通过这个 svgToDataUrl
把 url 贴出来(数据可能有点大)或者直接 Chrome 点开(svg+xml 浏览器会提示异常)
from modern-screenshot.
This page contains the following errors:
error on line 9 at column 339: Opening and ending tag mismatch: style line 1 and body
Below is a rendering of the page up to the first error.
mbinedExtensions.20230421_043143.js:68 Not allowed to navigate top frame to data URL:
window.modernScreenshot.domToForeignObjectSvg(runtimeElement)
.then(data =>{
return svgToDataUrl(data);
})
.then(dataUrl => {
console.log("svg to url:" + dataUrl);
const link = document.createElement('a');
link.href = dataUrl;
link.click();
})
.catch(function (error){
console.error("dom to foreign obj:"+error);
});
这个是新的报错。 url有142k。
from modern-screenshot.
function svgToDataUrl(svg) {
const xhtml = new XMLSerializer()
.serializeToString(svg)
// https://www.w3.org/TR/xml/#charsets
// eslint-disable-next-line no-control-regex
.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/ug, '');
console.log(xhtml);
return `data:image/svg+xml;charset=utf-8,${ encodeURIComponent(xhtml) }`
}
发现生成的xml,不合法。在debug哪里导致的。
from modern-screenshot.
This page contains the following errors:
error on line 9 at column 339: Opening and ending tag mismatch: style line 1 and body
Below is a rendering of the page up to the first error.
只能根据查看当前 svg+xml
已渲染的片段推断下文那一处异常的
本质还是因为 new XMLSerializer().serializeToString()
序列化的 xml
还不是完全可用的(无解)
看能否提供 data-url 或者 line 9 at column 339
部分上下文的截图
from modern-screenshot.
image-to-canvas.ts 中
context2d?.drawImage(loaded, 0, 0, canvas.width, canvas.height)
画的就是这个 xml 序列化后的 svg+xml data-uri 所以需要查看 xml 因为什么引发的浏览器解析异常
from modern-screenshot.
终于将bug找出来了,是我code里面的bug,button里面多了一个“,页面显示正确,也不报错。但就是导致这个转xml出错。多谢。
from modern-screenshot.
Related Issues (20)
- 请问如何生成底色为白色的图片🙋🏻♀️
- 圆角无法画出
- Checkbox, Radio, Select not rendering their state HOT 1
- 截取的图片顶部偏移、和左偏移很大
- Unexpected wrap caused by lost floating point precision HOT 1
- 使用domToPng在特定的OPPO Find X3等机型上,对包含图片类的dom截图处理后发现图片区域为灰色 HOT 1
- Anyway to omit so many console warnings?
- Text with both background-clip and color set occasionally fails to display in Firefox
- Remove
- 能不能不要加载css中的所有字体
- Question: is it possible for me to x, y locations of the cloned nodes and its children? HOT 1
- Fonts not getting exported in the img ? HOT 1
- 新版火狐浏览器下内容多时使用domToCanvas提示Failed image load ,图片黑屏 HOT 1
- onCloneNode回调内修改样式以及追加dom元素后,截图没有效果,应当等待onCloneNode回调执行完毕后,再继续执行截图
- Im getting low quality when exporting with domToJpeg and domToBlob
- 内容显示偏移
- 文字的字体没有在截图的图片中 HOT 2
- 如何添加多个dom节点,实现模块化截图 HOT 1
- CSS attr() in pseudo-elements doesn't work in Firefox
- Threads not closing after converting DOM to image
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modern-screenshot.