Skip to content

Firefox fails to launch when using webExt.cmd.run in NodeJS #2993

@rnwst

Description

@rnwst

Is this a feature request or a bug?

Bug.

What is the current behavior?

When running webExt.cmd.run in a NodeJS script, Firefox fails to open, and web-ext fails with the following error:

file:///path-to-extension/node_modules/web-ext/lib/firefox/remote.js:92
      throw new WebExtError(`installTemporaryAddon: Error: ${message}`);
            ^
WebExtError: installTemporaryAddon: Error: Error: Could not install add-on at '.': [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.initWithPath]"  nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)"  location: "JS frame :: resource://devtools/server/actors/addon/addons.js :: installTemporaryAddon :: line 31"  data: no]
    at RemoteFirefox.installTemporaryAddon (file:///path-to-extension/node_modules/web-ext/lib/firefox/remote.js:92:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async FirefoxDesktopExtensionRunner.startFirefoxInstance (file:///path-to-extension/node_modules/web-ext/lib/extension-runners/firefox-desktop.js:216:27)
    at async FirefoxDesktopExtensionRunner.run (file:///path-to-extension/node_modules/web-ext/lib/extension-runners/firefox-desktop.js:49:5)
    at async Promise.all (index 0)
    at async MultiExtensionRunner.run (file:///path-to-extension/node_modules/web-ext/lib/extension-runners/index.js:66:5)
    at async run (file:///path-to-extension/node_modules/web-ext/lib/cmd/run.js:177:3)

Node.js v21.4.0

Everything works as expected when passing target: chromium as an option, and Chromium launches with the extension loaded. The issue only occurs in Firefox. There are also no issues when web-ext is run via the command line, and Firefox launches as expected:

npx web-ext run --source-dir=.

The issue only occurs when using web-ext in a NodeJS script.

Steps to reproduce

  1. This bug appears to be independent of the extension used. One should therefore be able to reproduce this bug with any minimal extension. To create a MRE, I used one of the example extensionslons:
git clone git clone https://github.com/mdn/webextensions-examples.git && cd webextensions-examples/beastify
  1. Create the file package.json with the following contents:
{
  "type": "module",
  "devDependencies": {
    "web-ext": "^7.9.0"
  }
}
  1. Run npm install.
  2. Create a file run.js with the following contents:
import webExt from 'web-ext';

webExt.cmd.run({sourceDir: '.'});
  1. Run node run.js and observe the above error.
  2. Execute npx web-ext run --source-dir=. and observe that Firefox launches without issue.
  3. Modify the file run.js to have the following contents:
import webExt from 'web-ext';

webExt.cmd.run({sourceDir: '.', target: 'chromium'});
  1. Run node run.js again and observe that Chromium launches without issue.

What is the expected or desired behavior?

Firefox should launch as it does when running npx web-ext from the command line.

Version information (for bug reports)

  • Firefox version: Mozilla Firefox 120.0.1
  • Your OS and version: Arch Linux
  • Output of commands node --version && npm --version && npx web-ext --version:
v21.4.0
10.2.5
7.9.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions