Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rnwst opened this issue Dec 20, 2023 · 3 comments · Fixed by #3024
Closed

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

rnwst opened this issue Dec 20, 2023 · 3 comments · Fixed by #3024

Comments

@rnwst
Copy link

rnwst commented Dec 20, 2023

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 added a commit to rnwst/easy-languages-dict that referenced this issue Dec 20, 2023
Add support for Firefox. Update `build.js` to build both a Chromium and
a Firefox version of the extension. Convert manifest to MV2 for the
Firefox build.

Unfortunately, `npm run start-firefox-desktop` doesn't currently work
due to mozilla/web-ext#2993.
rnwst added a commit to rnwst/easy-languages-dict that referenced this issue Dec 20, 2023
Add support for Firefox. Update `build.js` to build both a Chromium and
a Firefox version of the extension. Convert manifest to MV2 for the
Firefox build.

Unfortunately, `npm run start-firefox-desktop` doesn't currently work
due to mozilla/web-ext#2993.
@rnwst
Copy link
Author

rnwst commented Dec 22, 2023

@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.

@Rob--W
Copy link
Member

Rob--W commented Jan 4, 2024

Firefox doesn't accept relative paths. When web-ext run is used from the CLI, it passes an absolute path to the extension:

coerce: (arg) => (arg != null ? path.resolve(arg) : undefined),

We would be willing to accept a patch that turns the input (sourceDir) of run into an absolute path if needed:

log.info(`Running web extension from ${sourceDir}`);

rnwst added a commit to rnwst/easy-languages-dict that referenced this issue Jan 15, 2024
Firefox only accepts absolute paths. As a temporary workaround, supply
only absolute paths to Firefox.

Now that this issue is fixed, use Firefox by default for extension
development (when running `npm start`), as it works much better than
Chromium.

Use Firefox Developer Edition instead of standard Firefox for
extension development.

Also fix bug introduced in 52e4098,
which broke the `npm run lint-web-ext` command.
sbeesm added a commit to sbeesm/web-ext that referenced this issue Jan 22, 2024
@sbeesm
Copy link
Contributor

sbeesm commented Jan 22, 2024

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

sbeesm added a commit to sbeesm/web-ext that referenced this issue Jan 23, 2024
@Rob--W Rob--W closed this as completed in 244aeb3 Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants