web-ext icon indicating copy to clipboard operation
web-ext copied to clipboard

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

Open rnwst opened this issue 1 year ago • 3 comments
trafficstars

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

rnwst avatar Dec 20 '23 16:12 rnwst

@fregante, this is not a duplicate of #2975. I can run the command causing issues in #2975 (web-ext run --verbose --firefox "deved" --firefox-profile=mc02 --profile-create-if-missing --source-dir=$PWD --devtools --no-config-discovery) without any errors.

It is also unlikely that this is an issue with Firefox 121, as I do not have an installation of Firefox 121 on my computer (I tested with Firefox 120 as per the bug report above, and just tested with Firefox Developer Edition 122 as well, and the issue occurs in both versions).

As you can read in the report above, the issue only occurs when using web-ext's API, but not when running web-ext from the command line. This leads me to belive that this is an issue with web-ext and not with Firefox, since it works fine when using the command line.

rnwst avatar Dec 22 '23 16:12 rnwst

Firefox doesn't accept relative paths. When web-ext run is used from the CLI, it passes an absolute path to the extension: https://github.com/mozilla/web-ext/blob/3063a770638f411a2e77b3ab7dc9eea3e536906a/src/program.js#L433

We would be willing to accept a patch that turns the input (sourceDir) of run into an absolute path if needed: https://github.com/mozilla/web-ext/blob/3063a770638f411a2e77b3ab7dc9eea3e536906a/src/cmd/run.js#L64

Rob--W avatar Jan 04 '24 14:01 Rob--W

Hello, I've opened a PR #3024 to add a patch for this, would really appreciate any feedback and suggestions. Thanks!

sbeesm avatar Jan 22 '24 08:01 sbeesm