Allow using remote Chrome with puppeteer
Puppeteer allows connecting to chrome via a web socket or URL.
See: Puppeteer docs
This would disallow using args (they'd have to be added on the browser-side), though.
Proposal:
Add a remoteOptions key to engineOptions (or maybe a separate remote: bool flag, too?); when this is filled, use await puppeteer.connect() instead of puppeteer.launch().
Use cases:
- It would be beneficial mainly for dockerized environments, as it would be more in-line with the docker way (one process per container).
3 things...
-
thank you for this post. You are awesome for putting in this effort
-
there is already an internal parameter you can use to detect or set remote mode. Search for the switch case that parses for "moby" -- it's around there.
-
what are potential regressions for existing users? How should this be rilled out? There is currently a request to add a dockerArgs to the config. Should this be part of the same release?
-
This is a great project, even if I don't contribute code I hope I can add value with these feature ideas. :)
-
The
--moby/--dockerarg seems to create a backstop container and run the tests in that. In contrast, my proposal is only about where chrome runs (and only for puppeteer, although chromy might also support such a thing, I didn't check), be it docker or some remote server. They can be used together and would make the--moby(and regular runs) less resource intensive (given there's a remote chrome instance which is set up to accept connections). -
I don't really see any potential regressions. According to the docs,
connect()˙returns the sameBrowserinstance aslaunch(), everything else should be handled by puppeteer internally, so the only 3 things that need to be changed (pseudocode alert):
- Add a new function e.g
getBrowser(options)that should be something likeif (isRemote) { return await puppeteer.connect(...)) } else { return await puppeteer.launch(...); }and replace currentp.launch()usages with it - Add a new function e.g
releaseBrowser(options, browser)that could be something likeif (isRemote) { return await browser.disconnect(...); } else { return await browser.close() }and replace currentbrowser.close()usages with it - Add new parameters (which, when omitted, default to the current functionality)
Disclaimer: this is just headcanon, an actual implementation might be more difficult. :)
Thinking of it, another use case would be scalability (e.g in CI/CD when having lots of tests). Backstop on its own doesn't really use a lot of resources, the main hogs are the browsers. Having the ability to move the resource-intensive stuff to a different machine should help with this.
Wow. That just made my head explode. 🤯
- The --moby/--docker arg seems to create a backstop container and run the tests in that. In contrast, my proposal is only about where chrome runs (and only for puppeteer, although chromy might also support such a thing, I didn't check), be it docker or some remote server. They can be used together and would make the --moby (and regular runs) less resource intensive (given there's a remote chrome instance which is set up to accept connections).
Very cool idea. Would be fantastic if someone wants to build it.
Created a PR for it (note, I'm mhavelant, this is only my personal account, the other one is my work account). :)
This is cool -- thank you! I have some changes on the npm canary branch that need to be released. I will try to get those out next week, then we can merge these and put it out on the canary branch. More later. Cheers!
@garris is this still going to be merged?
I'm interested in this as well. I'd like to leverage a service such as browserless.io instead of maintaining my own puppeteer locally. Happy to help with rebasing/amending the PR if it can be merged.