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

Add support for loading browser extensions #83

Closed
sissbruecker opened this issue Apr 13, 2024 · 6 comments
Closed

Add support for loading browser extensions #83

sissbruecker opened this issue Apr 13, 2024 · 6 comments

Comments

@sissbruecker
Copy link
Contributor

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

  • the saved HTML doesn't contain any ads
  • with some tweaking of uBlock0, it also removes cookie consent banners

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:

  • Allow using --headless=new instead of --headless
  • Allow removing the --disable-extensions browser arg that single-file applies by default

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
Copy link
Owner

gildas-lormeau commented Apr 13, 2024

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
Copy link
Contributor Author

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
Copy link
Owner

gildas-lormeau commented Apr 14, 2024

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
Copy link
Owner

gildas-lormeau commented Apr 16, 2024

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

@sissbruecker
Copy link
Contributor Author

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
Copy link
Owner

@sissbruecker Thank you for the feedback

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