Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Image fails to render #18

Closed
Us3r-gitHub opened this issue Nov 29, 2024 · 4 comments
Closed

[BUG]: Image fails to render #18

Us3r-gitHub opened this issue Nov 29, 2024 · 4 comments

Comments

@Us3r-gitHub
Copy link

Describe the bug
I recently discovered this library and wanted to try it out. I looked at the provided playground, but I encountered an issue where the image is not rendering correctly.

Screenshots
playground
image

@Us3r-gitHub Us3r-gitHub changed the title [BUG]: Image not rendered [BUG]: Image fails to render Nov 29, 2024
@siaikin
Copy link
Owner

siaikin commented Nov 29, 2024

Thank you very much for the bugs you found.

This is an issue with the example on stackbilz, I'll look at it later. Before that, you can check out the documentation https://vue-to-print.netlify.app/

@siaikin
Copy link
Owner

siaikin commented Nov 30, 2024

@Us3r-gitHub
Copy link
Author

Thanks for the fix!

Is StackBlitz a known issue for this?

@siaikin
Copy link
Owner

siaikin commented Dec 2, 2024

This should be an issue with Chrome.

Check out this w3c/ServiceWorker#765 and this w3c/ServiceWorker#765 (comment). In simple terms, service workers can't intercept requests for iframes in Chrome, even if they're from the same origin.

vue-to-print uses an iframe to print partial html, and Stackblitz uses a service worker to intercept requests. These two points meet the trigger conditions of the above question. So you can see that images loaded from "local" in StackBlitz can't be displayed (because requests for "local" images can't be intercepted).

CodeSandbox doesn't use service workers, so I switched to him.

Tested and found that StackBlitz's example works fine on Firefox and Safari.

这应该是 Chrome 的问题。

查看这个 w3c/ServiceWorker#765 和 这个 w3c/ServiceWorker#765 (comment) 。简单来说,在 Chrome 中 Service Worker 无法拦截 iframe 的请求(即使是同源的)。

vue-to-print 使用 iframe 来实现打印 html 的局部内容,并且 Stackblitz 使用 Service Worker 拦截请求。这两点满足和上述问题的触发条件。所以你可以看到在 StackBlitz 中从“本地”加载的图片无法显示(因为无法拦截到“本地”图片的请求)。

CodeSandbox 不使用 Service Worker ,因此我切换到他。

经过测试,StackBlitz 的示例在 Firefox 和 Safari 上能够正常工作。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants