Skip to content

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

@kleinesfilmroellchen

Description

@kleinesfilmroellchen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions