Skip to content

Instantly share code, notes, and snippets.

@marios88
Created June 19, 2022 12:25
Show Gist options
  • Save marios88/60746bb5c062e7d7c45c729c5888dd63 to your computer and use it in GitHub Desktop.
Save marios88/60746bb5c062e7d7c45c729c5888dd63 to your computer and use it in GitHub Desktop.
Puppeteer Opera open newPage
operaNewPage = async function(browser) {
const browserPages = await browser.pages();
//count pages
console.log((await browser.pages()).length);
const pageCount = (await browser.pages()).length;
const mainPage = (await browser.pages())[0];
await mainPage.evaluate( function (){
window.open('about:blank');
});
while((await browser.pages()).length === pageCount){
//sleep
console.log((await browser.pages()).length);
//await exports.delay(1000);
}
//return last element of array
let page = (await browser.pages())[(await browser.pages()).length - 1];
return new Promise((resolve) => {
resolve(page);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment