johnfactotum / foliate

Read e-books in style
https://johnfactotum.github.io/foliate/
GNU General Public License v3.0
5.29k stars 259 forks source link

setting background picture via user-stylesheet.css/allow to load local resource #1177

Closed drmhessler closed 6 months ago

drmhessler commented 7 months ago

Hi guys. As a rather new user of foliate with the new gtk4 engine, and a passionate digital bookworm, I would like to insert an opaqued background picture general to all my books. How/In which folder I have to insert a background picture to be loaded via user-stylesheet.css? body { background-image: url("file"); } in user-stylesheet.css? Trying file=file:///correct_path results in "Not allowed to load local resource".

Version:

johnfactotum commented 7 months ago

I don't think it's possible. The page is served from a custom URI scheme, and I believe file: images are blocked unless the page itself is a local file.

It could switch to using local files, but the main reason it uses a custom URI scheme now is that ES6 modules need to be from the same origin, and browsers treat each local file as a different origin. So to do that it would need to use a bundler, which I would like to avoid. Allowing the book to load local files, even just images, could also be problematic in terms of security.

Probably a solution would be to have a dedicated directory in the config directory that is loaded by the function that handles the custom URI scheme.

For now you should be able to use data: URLs to work around the issue.