Puppeteer
BrowserCloud supports puppeteer. The latter can be successfully used provided that the appropriate app or service are updated. To use the BrowserCloud service just change the below-mentioned:
local Chrome
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Remember to catch errors and close!
})();
cloud Chrome
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.connect({
browserWSEndpoint: `wss://chrome-v2.browsercloud.io?token=MY-TOKEN`,
});
const page = await browser.newPage();
// Remember to catch errors and close!
})();
Launch options
In the browserWSEndpoint
there is an opportunity to detail launch-arguments through query-string parameters. So, specify it the way shown below in case you need to launch the browser with the pre-determined height and width:
Setting width and height
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.connect({
browserWSEndpoint: `wss://chrome-v2.browsercloud.io?token=MY-TOKEN&--window-size=1200,900`,
});
const page = await browser.newPage();
// Remember to catch errors and close!
})();
Using BrowserCloud built-in proxy servers
Add parameter &--proxy-server=browsercloud-proxies
to browserWSEndpoint
string to use built-in proxies
Puppeteer & Bright Data / Luminati
Puppeteer & BrightData / Luminati
Please note that many proxies only support Chromium revisions in less than puppeteer 1.18.0. This is due to Chromium dropping support for Proxy-Authorization headers. Check your proxies documentation for how to properly authenticate, and ensure that you don't need to set a Proxy-Authorization header.
Add --proxy-server=https://my-proxy.com
to endpoint URL to use your proxies for any framework
const puppeteer = require('puppeteer')
async function run() {
try {
browser = await puppeteer.connect({
browserWSEndpoint:
'wss://chrome-v2.browsercloud.io?token=BROWSERCLOUD_TOKEN'+
'&--proxy-server=http://zproxy.lum-superproxy.io:22225',
});
const page = await browser.newPage();
await page.authenticate({
username: 'PROXY_LOGIN',
password: 'PROXY_PASSWORD'
});
await page.goto('https://iplocation.com/');
await page.setViewport({ width: 1900, height: 1080 });
await page.screenshot({ path: `./image.jpeg` });
} catch (err) {
console.log(`❌ Error: ${err.message}`);
} finally {
await browser.close();
console.log(`🎉 Screenshots captured.`);
}
}
run();