简体   繁体   中英

Playwright close unnumbered page

I use code

const {chromium} = require('playwright');
(async () => {
    const userDataDir = '\NewData';
    const browser = await chromium.launchPersistentContext(userDataDir,{headless:false});
    const page = await browser.newPage();
    await page.goto('https://www.google.com/')
})()

But the browser runs one blank tab before opening google, I think this is because I wrote the cookies incorrectly, but I have no desire to rewrite them. How can I close the first tab?

Saving the context won't prevent the browser from leaving that empty tab. If you don't want to see it you can use it instead of creating a new one.

const context = await chromium.launchPersistentContext(userDataDir,{headless:false});
const [ page ] = context.pages();
await page.goto('https://www.google.com/')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM