1

How do you run playwright with already installed local firefox?

NOTE!: I need to be able to specify the executable as I'm actually developing firefox so I may have a custom build. But, step one is getting it to run with an official build.

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();

but I get a bunch of errors

❯ node .\test.mjs
node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

browserType.launch: Browser.enable): Browser closed.
==================== Browser output: ====================
<launching> C:\Program Files\Mozilla Firefox\firefox.exe -no-remote -wait-for-browser -foreground -profile C:\Users\gregg\AppData\Local\Temp\playwright_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 Files\Mozilla Firefox\firefox.exe -no-remote -wait-for-browser -foreground -profile C:\Users\gregg\AppData\Local\Temp\playwright_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'
}

Tried MacOS as well as Window (of course on MacOS the path is different). This process works fine with Chrome

gman
  • 100,619
  • 31
  • 269
  • 393

2 Answers2

0

I believe your FF doesn't match the version Playwright supports,

The latest Playwright 1.29.2 supports 107, while the current FF is 108.

https://github.com/microsoft/playwright/issues/19337#issuecomment-1342247868

unickq
  • 1,497
  • 12
  • 18
0

gman, Playwright actually uses a specially patched version of of the stable build of Firefox. This means that you can't use any of the installed versions that you might have alongside.

Let me quote the official documentation.

Playwright's Firefox version matches the recent Firefox Stable build. Playwright doesn't work with the branded version of Firefox since it relies on patches. Instead you can test against the recent Firefox Stable build.

Wrapping up, you have to use the Firefox that comes with your Playwright

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()
});

Good luck! If you prefer to use the real Firefox, you can simply try Puppeteer instead of Playwright, which has very similar features for automation.

  • Sadly that makes it useless to use for developing sites that are planning to use upcoming browser features :( – gman Apr 11 '23 at 00:03
  • True. You can always fallback into Puppeteer if you need other browsers. But I agree, it would be great if they allow you to use any browser freely. – Manuel Caballero Apr 11 '23 at 13:36
  • Playwright should contribute these patches back to firefox then so that an already installed stable firefox could be used. – bdrx Jun 12 '23 at 20:53