如何在 Playwright 中使用已安装的 chrome 版本?

2024-05-02

我想使用铬而不是铬。我可以通过提供可执行路径在 puppeteer 中实现相同的目的。在 playwright 中它不起作用,因为浏览器类型参数仅支持“chromium、webkit、firefox”

const { chromium } = require('playwright');
(async () => {
    const browser = await chromium.launch({
        headless: false,
        executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
    });
    const context = await browser.newContext();
    const page = await context.newPage();
    await page.goto('http://whatsmyuseragent.org/');
    await page.screenshot({ path: `example-${browserType}.png` });
})();

您需要选择其中一种口味。但是一旦您选择了 Chromium 浏览器类型,您仍然可以通过executablePath to the launch https://playwright.dev/docs/api/class-browsertype#browser-type-launch功能。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Playwright 中使用已安装的 chrome 版本? 的相关文章

随机推荐