8

我想用铬代替铬。我可以通过提供可执行路径在 puppeteer 中实现相同的目标。在剧作家中,它不起作用,因为浏览器类型参数仅支持 '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` });
})();

4

2 回答 2

6

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

于 2020-06-09T11:59:08.260 回答
1

在 1.19 中,您可以使用 chrome。

browser = playwright.chromium.launch(channel="chrome")

或者你可以简单地将它放在你的剧作家配置文件中,如:

////
    use: {
        headless: true,
        viewport: { width: 1600, height: 1000},
        ignoreHTTPSErrors: true,
        trace: 'on',
        screenshot: 'on',
        channel: "chrome",
        video: 'on'
    },
    ////

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

于 2022-02-19T18:16:27.073 回答