Skip to content

feat: Support multiple extensions in web-ext run - #3700

Open
Rob--W wants to merge 1 commit into
mozilla:masterfrom
Rob--W:web-ext-run-multiple-source-dirs
Open

Rob--W wants to merge 1 commit into
mozilla:masterfrom
Rob--W:web-ext-run-multiple-source-dirs

Conversation

@Rob--W

@Rob--W Rob--W commented Apr 28, 2026

Copy link
Copy Markdown
Member

Fixes #1107.

Before this patch, web-ext run was equivalent to web-ext run -s . or web-ext run --source-dir . and did not support additional directories. This patch adds support for loading multiple source directories.

Example of loading current directory plus another one:

web-ext run -s . -s path/to/another

This starts Firefox desktop with both extensions loaded. If any of their sources change, the extension will be updated in the browser.

This functionality works for Firefox desktop, Firefox for Android, Chromium (the ChromiumExtensionRunner now supports reloading of individual extensions; previously it just reloaded "all" of them).

The R reload shortcut reloads all extensions at once.

The existing change detection logic automatically added the artifacts directory (web-ext-artifacts) to the ignores for watching purposes. This is not implemented for the additional source directories. Use --ignore-files if you want to ignore them.

Before this patch, `web-ext run` was equivalent to `web-ext run -s .` or
`web-ext run --source-dir .` and did not support additional directories.
This patch adds support for loading multiple source directories.

Example of loading current directory plus another one:
```
web-ext run -s . -s path/to/another
```

This starts Firefox desktop with both extensions loaded. If any of their
sources change, the extension will be updated in the browser.

This functionality works for Firefox desktop, Firefox for Android,
Chromium (the ChromiumExtensionRunner now supports reloading of
individual extensions; previously it just reloaded "all" of them).

The R reload shortcut reloads all extensions at once.

The existing change detection logic automatically added the artifacts
directory (`web-ext-artifacts`) to the ignores for watching purposes.
This is not implemented for the additional source directories. Use
`--ignore-files` if you want to ignore them.
@Rob--W
Rob--W requested a review from rpl April 28, 2026 13:57
@aaronanish-t

Copy link
Copy Markdown

fwiw this also fixes a crash on current master: right now passing -s twice to any command (run or build) crashes with TypeError [ERR_INVALID_ARG_TYPE]: The "paths[0]" argument must be of type string. Received an instance of Array from path.resolve (reproduced on 10.8.0). with this PR, run accepts both and the other commands get the "Multiple --source-dir are not allowed." usage error instead.

@aaronanish-t

Copy link
Copy Markdown

tried this out locally, merged onto current master (merges cleanly). run's unit tests pass, and build -s a -s b now gives the usage error instead of the path.resolve crash 👍

one thing I hit: the check in the source-dir coerce uses program.programArgv.includes('run'), so any argv token that's exactly run gets past it, and those commands still crash with ERR_INVALID_ARG_TYPE:

web-ext build -s run -s other                      # source dir named "run"
web-ext build --ignore-files run -s other -s other

moving the check into execute(), where the command is already parsed as cmd, fixes both. It also covers a sourceDir array from a config file, which coerce never sees:

if (cmd !== 'run' && Array.isArray(adjustedArgv.sourceDir)) {
  throw new UsageError('Multiple --source-dir are not allowed.');
}

it has to go before checkRequiredArguments(), otherwise sign reports the missing --api-key first and the existing "rejects multiple --source-dir in web-ext sign" test fails. With that order, test.program.js and test.run.js pass (84).

small question: should -s . -s . be deduped? from the code it looks like it'd push the same dir into extensions twice (haven't tried it in a browser).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow mutilple sources for "web-ext run --source-dir=..."

2 participants