html2canvas 在 Firefox 中有效,但在 Chrome 中无效

发布于 2025-01-14 01:36:26 字数 1269 浏览 3 评论 0原文

我正在捕获 iframe 中存在的 Scorm 内容的屏幕截图,我在 Firefox 中获得屏幕截图,但在 Chrome 中却没有,问题似乎出在渲染到画布时的图像路径/URL。
我比较了结果来自两个浏览器的 logging: true
而且我发现 chrome 中的图像路径已更改,这就是它在 chrome 中不起作用的原因。
我该如何解决这个问题?帮助我......

var iframeEle = document.querySelector("iframe").contentWindow.document.body;//working

console.log(iframeEle);

// $('#saveReport').on('click', function(){
    html2canvas(iframeEle, {
        //background: '#fff',
       // height: window.innerHeight,
        //windowHeight: window.innerHeight,
        logging: true,
       
        onrendered: function(canvas){
            // before_imgData = canvas.toDataURL('image/png');
            before_imgData = canvas.toDataURL('image/jpeg');
        }
    });

firefox 浏览器日志:
当我检查渲染图像的路径时,它是正确的。 输入图片此处描述


Chrome 浏览器日志:
在 Chrome 中,图像路径不正确,因为它由浏览器的当前 url 组成,这就是为什么无法正确捕获的原因。
我认为这是 chrome 相对路径的问题,而不是 firefox 的问题。

在此处输入图像描述

I am capturing the screenshot of the Scorm content present inside the iframe, I am getting screenshot in the firefox but not in chrome, it seems like issue is with images path/url while rendering into the canvas.
I have compared the result of logging: true from both browser.
And I found that images path in the chrome is changed that's why it is not working in chrome.
How can i solve this? help me........

var iframeEle = document.querySelector("iframe").contentWindow.document.body;//working

console.log(iframeEle);

// $('#saveReport').on('click', function(){
    html2canvas(iframeEle, {
        //background: '#fff',
       // height: window.innerHeight,
        //windowHeight: window.innerHeight,
        logging: true,
       
        onrendered: function(canvas){
            // before_imgData = canvas.toDataURL('image/png');
            before_imgData = canvas.toDataURL('image/jpeg');
        }
    });

Log for firefox browser :
when I checked path of images for rendering it is correct.
enter image description here

Log for chrome browser :
in chrome the path for images is not right as it consist of current url of browser thats why is not capturing correctly.
I think it is issue of relative path for chrome and not for firefox.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文