gildas-lormeau / single-file-cli

CLI tool for saving a faithful copy of a complete web page in a single HTML file (based on SingleFile)
GNU Affero General Public License v3.0
539 stars 57 forks source link

Add support for loading browser extensions #83

Closed sissbruecker closed 2 months ago

sissbruecker commented 2 months ago

One thing I'd like to be able to do is run single-file together with a Chrome extension like uBlock Origin, so that:

Traditionally running extensions in headless Chrome was not possible, however somewhat recently a new headless mode was introduced that allows you to do pretty much anything you can do with a headful (?) Chrome instance, such as running extensions: https://developer.chrome.com/docs/chromium/new-headless

Adding support for this would require two configuration options:

I did try patching single-file-cli with these changes, and was able to get the extension loaded (requires an up-to-date Chromium as well). While I can deploy my app with a patched version of single-file, it would be great if this could be added to the core. I'm up for contributing these changes if we can align on an API / specific option naming.

gildas-lormeau commented 2 months ago

Thank you, I applied the suggested changes but I did not change --headless to --headless=new because it breaks the support of frames (tested with https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe).

sissbruecker commented 2 months ago

Thanks! Can confirm that overriding the --headless option works now. That should be enough to get me started.

That iframe issue is a bit worrying, maybe I'll have to make using the extension optional. Let's see.

gildas-lormeau commented 2 months ago

For the record, I've looked at what's wrong with using --headless=new. In fact, this problem can also be reproduced by not launching Chrome in headless mode. For some reason that escapes me as I write this reply, window.postMessage() does not work as expected, i.e. messages are not received by listeners in frames. At worst, it should be possible to emulate it or rely on an alternative API that would only be used when single-file-core is used by single-file-cli though. This API would be proprietary and exposed by single-file-cli (to single-file-core).

gildas-lormeau commented 2 months ago

For the record, the frame issue is fixed in the version v2.0.33.

sissbruecker commented 2 months ago

It does work now, thanks for following up on that. In general, using single-file with the new headless mode seems to work very well, haven't observed any other issues so far.

gildas-lormeau commented 2 months ago

@sissbruecker Thank you for the feedback