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

Yargs turns values like "--something" passed to web-ext run --args="..." as additional web-ext options #1846

Closed
MatthD opened this issue Feb 27, 2020 · 5 comments · Fixed by #1902

Comments

@MatthD
Copy link

MatthD commented Feb 27, 2020

Is this a feature request or a bug?

Bug

What is the current behavior?

Try to load this command ./node_modules/.bin/web-ext run -t chromium --arg="--no-default-browser-check"
But it always return unknown arguments: default-browser-check, defaultBrowserCheck

I am not able to pass any args to chromium.

What is the expected or desired behavior?

Should be able to pass any chromium args

Version information (for bug reports)

  • Chrome version: 74.0.3729.131 (
  • Your OS and version: Mac OSX Mojave 10.14.5
node v12.16.1
npm 6.13.4
web-ext 4.1.0 (installed locally)
@rpl
Copy link
Member

rpl commented Feb 27, 2020

eh, that's really annoying :-|

I took a quick look and yargs seems to be parsing the argument twice internally and the second time seems to be turning the --args/--arg value into its own separate CLI arguments, which is then triggering the yargs validation error internally.

Besides that, --arg is the web-ext argument to use to pass more command line options to Chrome (e.g. web-ext run -t chromium --arg="https://mozilla.org" is opening chrome with a tab navigated to the expected url).

Ironically, it looks that adding one space character at the start of the --arg value is workaround the issue:

  • web-ext run -t chromium --arg=" --no-default-browser-check" seems to be able to bypass the yargs validation error and get the option to chrome (e.g. I tried to run web-ext run -t chromium --arg=" --disable-extensions" locally and none of the extension was running, as expected).

@rpl rpl added the type: bug label Feb 27, 2020
@rpl
Copy link
Member

rpl commented Feb 27, 2020

Some additional detail from the logs I collected locally while reproducing this issue.

The first time yargs _parseArgs is being called --no-default-browser-check is still the value of the --args argument:

Trace: yargs _parseArgs { args:
   [ 'run',
     '-s',
     '/.../webextensions-examples/borderify',
     '-t',
     'chromium',
     '--args=--no-default-browser-check' ],
  parsed:
   { argv:
      { _: [Array],
        ...
        args: '--no-default-browser-check',
        ... },
     ...
    at Object.parseArgs [as _parseArgs] (/.../work/projects/web-ext-cli/web-ext/node_modules/yargs/yargs.js:1060:13)
    at Object.argv (/.../work/projects/web-ext-cli/web-ext/node_modules/yargs/yargs.js:1041:21)
    at Program.getArguments (/.../work/projects/web-ext-cli/web-ext/dist/webpack:/src/program.js:157:29)
    at Program.execute (/.../work/projects/web-ext-cli/web-ext/dist/webpack:/src/program.js:225:23)
    at Object.main (/.../work/projects/web-ext-cli/web-ext/dist/webpack:/src/program.js:680:18)
    at Object.<anonymous> (/.../work/projects/web-ext-cli/web-ext/bin/web-ext:7:8)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)

The second time yargs _parseArgs is being called (from inside runCommand) the --no-default-browser-check has been turned into an argument (which is then unknown and triggers yargs validation error):

Trace: yargs _parseArgs { args:
   [ 'run',
     '-s',
     '/home/rpl/work/projects/extensions/webextensions-examples/borderify',
     '-t',
     'chromium',
     '--args=--no-default-browser-check' ],
  parsed:
   { argv:
      { _: [Array],
        ...
        args: [],
        arg: [],
        'default-browser-check': false,
        defaultBrowserCheck: false,
     ...
     aliases:
      { ...
        args: [Array],
        arg: [Array],
        ...
        'default-browser-check': [Array],
        defaultBrowserCheck: [Array] },
     newAliases:
      { ...
        defaultBrowserCheck: true,
        'default-browser-check': true },
     ...
    at Object.parseArgs [as _parseArgs] (/.../work/projects/web-ext-cli/web-ext/node_modules/yargs/yargs.js:1060:13)
    at Object.runCommand (/.../work/projects/web-ext-cli/web-ext/node_modules/yargs/lib/command.js:198:30)
    at Object.parseArgs [as _parseArgs] (/.../work/projects/web-ext-cli/web-ext/node_modules/yargs/yargs.js:1109:41)
    at Object.argv (/.../work/projects/web-ext-cli/web-ext/node_modules/yargs/yargs.js:1041:21)
    at Program.getArguments (/.../work/projects/web-ext-cli/web-ext/dist/webpack:/src/program.js:157:29)
    at Program.execute (/.../work/projects/web-ext-cli/web-ext/dist/webpack:/src/program.js:225:23)
    at Object.main (/.../work/projects/web-ext-cli/web-ext/dist/webpack:/src/program.js:680:18)
    at Object.<anonymous> (/.../work/projects/web-ext-cli/web-ext/bin/web-ext:7:8)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)

@rpl rpl changed the title How to pass args to chromium ? Yargs turns values like "--something" passed to web-ext run --args="..." as additional web-ext options Mar 12, 2020
@rpl
Copy link
Member

rpl commented Mar 26, 2020

yargs seems to support a new unknown-options-as-args parser configuration option, which is set to false by default. Setting this yargs parser option to true seems to prevent yargs from parsing the --* value set as a command option value as a separate option.

e.g. by logging the parsed option from the yargs _parseArgs method above:

With unknown-options-as-args set to false (current behavior):

Trace: _parseArgs { _: [ 'run' ],
  t: 'chromium',
  arg: '--no-default-browser-check',
  ...
    at Object.parseArgs [as _parseArgs] (/.../web-ext/node_modules/yargs/yargs.js:1060:13)
    at Object.argv (/.../web-ext/node_modules/yargs/yargs.js:1041:21)
    at Program.getArguments (/.../web-ext/dist/webpack:/src/program.js:157:29)
    at Program.execute (/.../web-ext/dist/webpack:/src/program.js:224:23)
    ...

Trace: _parseArgs { _: [ 'run' ],
  t: [ 'chromium' ],
  target: [ 'chromium' ],
  arg: [],
  args: [],
  'default-browser-check': false,
  defaultBrowserCheck: false,
  ...
    at Object.parseArgs [as _parseArgs] (/.../web-ext/node_modules/yargs/yargs.js:1060:13)
    at Object.runCommand (/.../web-ext/node_modules/yargs/lib/command.js:198:30)
    at Object.parseArgs [as _parseArgs] (/.../web-ext/node_modules/yargs/yargs.js:1108:41)
    at Object.argv (/.../web-ext/node_modules/yargs/yargs.js:1041:21)
    ...
web-ext run

Run the extension

Options:
...
Unknown arguments: default-browser-check, defaultBrowserCheck

With unknown-options-as-args set to true:

Trace: _parseArgs { _:
   [ 'run', '-t', 'chromium', '--arg=--no-default-browser-check' ],
  s: '/.../extensions/whimsicalify',
  'source-dir': '/.../whimsicalify',
  ... }
    at Object.parseArgs [as _parseArgs] (/.../web-ext/node_modules/yargs/yargs.js:1060:13)
    at Object.argv (/.../web-ext/node_modules/yargs/yargs.js:1041:21)
    at Program.getArguments (/.../web-ext/dist/webpack:/src/program.js:157:29)
    at Program.execute (/.../web-ext/dist/webpack:/src/program.js:224:23)
    ...
Trace: _parseArgs { _: [ 'run' ],
  t: [ 'chromium' ],
  target: [ 'chromium' ],
  arg: [ '--no-default-browser-check' ],
  ... }
    at Object.parseArgs [as _parseArgs] (/.../web-ext/node_modules/yargs/yargs.js:1060:13)
    at Object.runCommand (/.../web-ext/node_modules/yargs/lib/command.js:198:30)
    at Object.parseArgs [as _parseArgs] (/.../web-ext/node_modules/yargs/yargs.js:1108:41)
    at Object.argv (/.../web-ext/node_modules/yargs/yargs.js:1041:21)
    ...
...
[extension-runners/chromium.js][debug] Starting Chromium instance...

@Rob--W
Copy link
Member

Rob--W commented Mar 26, 2020

Using unknown-options-as-args would also result in --unknown (not just --arg=--unknown).

Another hacky work-around is to map process.argv's values, by replacing ^-- with SOMEDUMMY before processing, and then post-processing by replacing SOMEDUMMY with --.

@rpl
Copy link
Member

rpl commented May 6, 2020

This looks to have been fixed upstream in yargs v15.3.1 (which is now used on master, updated in
ee98f1c).

I'm not closing this issue yet because it would be good to look into adding an explicit test case, to be able to catch any new regression in that behavior when we will update yargs again in the future.

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