【问题标题】:Playwright close unnumbered page剧作家关闭未编号的页面
【发布时间】:2021-06-28 00:27:42
【问题描述】:

我使用代码

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/')
})()

但是浏览器在打开谷歌之前会运行一个空白标签, 我想这是因为我写错了cookie,但我不想重写它们。如何关闭第一个选项卡?

【问题讨论】:

    标签: javascript node.js webautomation playwright


    【解决方案1】:

    保存上下文不会阻止浏览器离开该空白选项卡。如果你不想看到它,你可以使用它而不是创建一个新的。

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

    【讨论】:

      猜你喜欢
      • 2022-01-01
      • 2021-12-17
      • 2023-03-13
      • 1970-01-01
      • 2021-08-23
      • 2021-04-20
      • 2021-07-20
      • 2023-01-24
      • 2022-07-20
      相关资源
      最近更新 更多