Skip to content

Instantly share code, notes, and snippets.

@hendrixroa
Last active March 9, 2023 21:42
Show Gist options
  • Save hendrixroa/ee4f4500de13ec1303e1a74bc6c88a35 to your computer and use it in GitHub Desktop.
Save hendrixroa/ee4f4500de13ec1303e1a74bc6c88a35 to your computer and use it in GitHub Desktop.
Get page function to open a headless browser window
public async getPage() {
if (!this.browser) {
await this.initBrowser();
}
const page = await this.browser.newPage();
// Avoiding Bot detection
const userAgent =
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Safari/537.36';
await page.setUserAgent(userAgent);
page.on('console', msg => {
this.emit('console', msg.text());
});
return page;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment