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

Raj*_*h G 17 javascript webautomation node.js playwright

我想使用铬而不是铬。我可以通过提供可执行路径在 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` });
})();
Run Code Online (Sandbox Code Playgroud)

har*_*ded 9

您需要选择其中一种口味。但是一旦您选择了 Chromium 浏览器类型,您仍然可以将 an 传递executablePath给该launch函数。


Gaj*_*ije 9

在 1.19 中你可以使用 chrome。

browser = playwright.chromium.launch(channel="chrome")
Run Code Online (Sandbox Code Playgroud)

或者您可以简单地将其放入剧作家配置文件中,例如:

////
    use: {
        headless: true,
        viewport: { width: 1600, height: 1000},
        ignoreHTTPSErrors: true,
        trace: 'on',
        screenshot: 'on',
        channel: "chrome",
        video: 'on'
    },
    ////
Run Code Online (Sandbox Code Playgroud)

更多关于https://playwright.dev/python/docs/browsers