question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature request] Support browser extension loading in Firefox

See original GitHub issue

I’m trying to perform extension automation using playwright against Firefox. Below is my sample code

import {
    firefox
} from 'playwright';

const extensionPath = "/Users/ashok_mb/Documents/xBP/Learner/playwright_spike/ff_extn/extension.xpi"
const userDataDir = '/Users/ashok_mb/Library/Application\ Support/Firefox/Profiles/data_dir';
firefox.launch({
            headless: false,
            firefoxUserPrefs: {
                "xpinstall.signatures.required": false,
                "extensions.langpacks.signatures.required": false,
            },
            args: [
                `--disable-extensions-except=${extensionPath}`,
                `--load-extension=${extensionPath}`
            ]
        });

With above code, the browser launches, but does not load extension with it. Can someone please advice on how to launch Firefox with extension using playwright code ?

Please help. Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

13reactions
aslushnikovcommented, Feb 11, 2022

UPDATE: this doesn’t work for the new versions of Firefox. See & upvote https://github.com/microsoft/playwright/issues/7297

~Actually, you can run Firefox Extensions with Playwright, but it requires a little bit of a trickery:~ ~- using web-ext to actually run firefox with permissions~ ~- parsing firefox stdout to get juggler endpoint~ ~- using endpoint to connect playwright onto it~

~The full repository is here: aslushnikov/demo-playwright-with-firefox-web-extension~

~The script to run a webextension:~

const path = require('path');
const {firefox} = require('playwright');
const webExt = require('web-ext').default;

(async () => {
  // 1. Enable verbose logging and start capturing logs.
  webExt.util.logger.consoleStream.makeVerbose();
  webExt.util.logger.consoleStream.startCapturing();

  // 2. Launch firefox
  const runner = await webExt.cmd.run({
    sourceDir: path.join(__dirname, 'webextension'),
    firefox: firefox.executablePath(),
    args: [`-juggler=1234`],
  }, {
    shouldExitProgram: false,
  });

  // 3. Parse firefox logs and extract juggler endpoint.
  const JUGGLER_MESSAGE = `Juggler listening on`;
  const message = webExt.util.logger.consoleStream.capturedMessages.find(msg => msg.includes(JUGGLER_MESSAGE));
  const wsEndpoint = message.split(JUGGLER_MESSAGE).pop();

  // 4. Connect playwright and start driving browser.
  const browser = await firefox.connect({ wsEndpoint });
  const page = await browser.newPage();
  await page.goto('https://mozilla.org');
  // .... go on driving ....
})();

~Hope it helps!~

5reactions
aslushnikovcommented, Jul 8, 2020

I can raise a feature request if required. Thanks!

@mukunduashok Yeah, please raise a feature request. We’ve heard there’s some interest for web extensions, but it’s unclear how many developers actually care and if it’s worth investing there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I want to make a feature request. How to do it properly ...
You can press the ESC key to stop the page loading. ... Maybe there is already an extension with this feature and in...
Read more >
Permission request messages for Firefox extensions
This is an extension asking your permission to tap into Firefox's inner framework (via APIs) to alter your browser's behavior.
Read more >
Experimental features in Firefox - Mozilla - MDN Web Docs
This page lists Firefox's experimental and partially implemented features, including those for proposed or cutting-edge web platform ...
Read more >
Chrome incompatibilities - Mozilla - MDN Web Docs
Extensions built with WebExtension APIs are designed to be compatible with Chrome and Opera extensions. As far as possible, extensions ...
Read more >
Your first extension - Mozilla - MDN Web Docs
The most interesting key here is content_scripts , which tells Firefox to load a script into Web pages whose URL matches a specific...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found