Puppeteer
Puppeteer is well-supported by browserless, and is easy to upgrade an existing service or app to use it. In order to use the browserless service, simply change the following:
Before browserless
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Remember to catch errors and close!
})();
After browserless
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.connect({
browserWSEndpoint: `wss://chrome.browserless.io/`,
});
const page = await browser.newPage();
// Remember to catch errors and close!
})();
Please note that if you're running the docker container to replace the location of wss://chrome.browserless.io/
to wherever your container is running.
Specifying launch flags
You can specify launch-arguments through query-string parameters inside the browserWSEndpoint
. As an example, if you want to start the browser with a pre-defined width and height you can specify it like so:
Setting width and height
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.connect({
browserWSEndpoint: `wss://chrome.browserless.io?--window-size=1200,900`,
});
const page = await browser.newPage();
// Remember to catch errors and close!
})();