如何在已经安装了本地firefox的情况下运行剧作家?
注意!:我需要能够指定可执行文件,因为我实际上正在开发firefox,所以我可能有一个自定义构建。但是,第一步是让它在正式版本中运行。
I tried this
// test.mjs
import { firefox } from 'playwright-core';
const executablePath = "C:\Program Files\Mozilla Firefox\firefox.exe";
async function main() {
const browser = await firefox.launch({
executablePath,
headless: false,
});
}
main();
但是我得到了一堆错误
❯ node .test.mjs
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^
browserType.launch: Browser.enable): Browser closed.
==================== Browser output: ====================
<launching> C:Program FilesMozilla Firefoxfirefox.exe -no-remote -wait-for-browser -foreground -profile C:UsersgreggAppDataLocalTempplaywright_firefoxdev_profile-SMZBOF -juggler-pipe -silent
<launched> pid=10684
[pid=10684] <process did exit: exitCode=0, signal=null>
[pid=10684] starting temporary directories cleanup
=========================== logs ===========================
<launching> C:Program FilesMozilla Firefoxfirefox.exe -no-remote -wait-for-browser -foreground -profile C:UsersgreggAppDataLocalTempplaywright_firefoxdev_profile-SMZBOF -juggler-pipe -silent
<launched> pid=10684
[pid=10684] <process did exit: exitCode=0, signal=null>
[pid=10684] starting temporary directories cleanup
============================================================
at main (file:///C:/Users/gregg/src/gpuweb/cts/test.mjs:6:33)
at file:///C:/Users/gregg/src/gpuweb/cts/test.mjs:13:1 {
name: 'Error'
}
尝试了MacOS和windows(当然在MacOS上路径不同)。这个过程在Chrome
上运行良好我相信你的FF与剧作家支持的版本不匹配,
最新的剧作家1.29.2支持107,而目前的FF是108。
https://github.com/microsoft/playwright/issues/19337 issuecomment - 1342247868
gman,剧作家实际上使用的是Firefox稳定版本的特殊补丁版本。这意味着你不能使用
安装的任何版本。让我引用一下官方文件。
剧作家的Firefox版本匹配最近的Firefox稳定版构建。剧作家不支持品牌版本的Firefox因为它依赖于补丁。相反,你可以用最近的Firefox稳定版。
总结,你必须使用你的剧作家自带的Firefox
const { firefox } = require('playwright');
firefox.launch({ headless: false }).then(async browser => {
const page = await browser.newPage()
await page.goto('https://www.brokenbrowser.com', { waitUntil: 'networkidle' });
//await browser.close()
});
祝你好运!如果你更喜欢使用真正的Firefox,你可以简单地尝试Puppeteer而不是剧作家,它具有非常相似的自动化功能。