Skip to content

feat: initial support for Safari rendering of images#992

Merged
acabal merged 2 commits into
masterfrom
safari-image-rendering
Jul 16, 2026
Merged

feat: initial support for Safari rendering of images#992
acabal merged 2 commits into
masterfrom
safari-image-rendering

Conversation

@robinwhittleton

Copy link
Copy Markdown
Member

There isn’t any safaridriver support for headless mode yet unfortunately.

This produces reasonable quality images, but I haven’t found any way of setting the rendering DPI or window size yet: everything seems really limited compared to Firefox / Chrome.

There isn’t any safaridriver support for headless mode yet unfortunately.
@acabal

acabal commented Jul 16, 2026

Copy link
Copy Markdown
Member

Thanks! Interesting that safari options are so limited. So a Safari window will pop up while se build is rendering?

If that's the case then we should probably add code to prefer Firefox/Chrome if they're installed before falling back to Safari. I don't know if installed_browsers.browsers() orders its results in any way so we'd have to loop through that first to remove Safari if Firefox/Chrome are installed.

@acabal

acabal commented Jul 16, 2026

Copy link
Copy Markdown
Member

Or, the more I think about it, if we can't get Safari headless and it literally pops up multiple windows while processing an ebook, maybe we should just decline to support Safari for now? It seems like it would be pretty annoying to be running a terminal task and a series of windows pops up randomly.

@acabal

acabal commented Jul 16, 2026

Copy link
Copy Markdown
Member

Also just to be clear, in terms of se build the browser is only invoked if there are non-boilerplate SVGs, so https://github.com/standardebooks/edgar-allan-poe_the-narrative-of-arthur-gordon-pym-of-nantucket and https://github.com/standardebooks/lewis-carroll_a-tangled-tale are a good test cases for that.

We also have to confirm that se compare-versions correctly screenshots differences in Safari, because the way Firefox and Chrome screenshot elements differs. So there will probably have to be custom Safari code for that.

@robinwhittleton

Copy link
Copy Markdown
Member Author

I was assuming this was just for local test builds, but I guess white label builds might happen in Safari.

Either way, if I’m reading the code right, installed_browsers just iterates over a big list of possible browsers it knows about and checks if they’re installed: https://github.com/undeflorate/installed_browsers/blob/master/installed_browsers/mac.py. If a user has Chrome or Firefox installed then Safari won’t be picked. But I guess if they have Brave or Opera and Safari then it’ll go Safari. I’ll add some code to push Safari to the end.

Either way, on my M2 Macbook Air, building Nantucket is under half a second of Safari window time.

@acabal

acabal commented Jul 16, 2026

Copy link
Copy Markdown
Member

I was assuming this was just for local test builds, but I guess white label builds might happen in Safari.

This is for the whole toolset - anyone building an ebook that has non-boilerplate SVGs will be affected, since se build uses browser.py to start a browser instance to render SVGs.

Either way, if I’m reading the code right, installed_browsers just iterates over a big list of possible browsers it knows about and checks if they’re installed:

Yes, but the problem is that I don't know if/how the browsers are ordered. If they're unordered, then Safari might come first and it could return a Safari instance instead of a Firefox instance.

I'm still not sure if we should have a window pop up at all... that is very unexpected for a CLI and annoying in any case, because someone could be typing or clicking when it pops up. And the windows might pop up multiple times if there are multiple SVGs to process.

If we can't get Safari to work in a headless mode, then let's put this on the back burner for now. I think a popup window is too annoying and we can just ask them to install Firefox/Chrome instead. I assumed headless Safari was possible since so many developers are on Macs, but perhaps not.

…due to lack of options.
@robinwhittleton

Copy link
Copy Markdown
Member Author

OK, up to you. I’ve pushed a commit that moves Safari to the end of the list anyway, so it’ll only run if a user only has Safari and no other browsers installed.

@acabal
acabal merged commit bb315e4 into master Jul 16, 2026
2 checks passed
@acabal

acabal commented Jul 16, 2026

Copy link
Copy Markdown
Member

OK, I'll merge it in for now and let me think about it. I might comment it out with a note so if/when Safari can be used in headless mode we can just uncomment the code.

@acabal

acabal commented Jul 16, 2026

Copy link
Copy Markdown
Member

Were you able to confirm that se compare-versions also works as expected, e.g. the full file is rendered, differences are highlighted, and there are no crashes? https://github.com/standardebooks/honore-de-balzac_father-goriot_ellen-marriage is a good test case

@robinwhittleton

Copy link
Copy Markdown
Member Author

Ah, right, hadn’t realised that was a thing. I’ll add a fix for that in a separate PR.

@robinwhittleton
robinwhittleton deleted the safari-image-rendering branch July 17, 2026 06:00
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

Successfully merging this pull request may close these issues.

2 participants