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

Relative and file:// imports with <image src> don't work #104

Open
kleinesfilmroellchen opened this issue Jul 12, 2021 · 1 comment
Open

Comments

@kleinesfilmroellchen
Copy link

svgexport creates a pseudo-page on about:blank and then dumps the previously modified and grabbed SVG contents in there, in order to get a proper HTML with a screenshottable div. However, this means that (1) the new page is at an isolated location, and (2) the page is not loaded with the file:// protocol like local SVG files are usually.

This leads to two problems with SVGs that use the <image> tag to import other SVGs or images.

  • If the images use a relative import, that's broken. The images will just not show up.
  • If the images use a file:// protocol, even if the path is absolute, it also doesn't work. The images are replaced by a "file missing" icon and my guess is that the browser forbids the about:blank page to load stuff with the file:// protocol.

A fix would be to create an empty HTML file in the current location with a random name (and error out if it exists), then navigate to that. This would both allow the file:// URLs as well as relative imports. The file should of course be deleted before the program ends. I have had success with a workaround that changes render.js line 162 to use a local "sacrificial" HTML file.

To be clear: this is an issue with the way svgexport uses puppeteer, not an issue with puppeteer itself. All of this is expected Chromium behavior.

@mlantin
Copy link

mlantin commented Dec 21, 2022

I've come up against this issue too. Thank you for the suggested fix. I also got around it by using a "use" tag and an internal blob of image data. Definitely not ideal but it worked.

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