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

feat: Adds binaryArgs to pass additional flags to Firefox binary #1563

Merged
merged 10 commits into from
Mar 29, 2019

Conversation

denar90
Copy link
Contributor

@denar90 denar90 commented Mar 15, 2019

Hi,
Can we add one more option to run method?

Motivation: puppeteer/puppeteer#4162
Partly solves #1122

Example of usage

    const CDPPort = 6006
    await webExt.cmd.run({
      sourceDir: extPath,
      firefox: puppeteerFirefox.executablePath(),
      binaryArgs: [
        `-juggler=${CDPPort}`
      ]
    }, {
      shouldExitProgram: false,
    })

    const browserWSEndpoint = `ws://127.0.0.1:${CDPPort}`
    browser = await puppeteerFirefox.connect({
      browserWSEndpoint,
    })

Thanks.

@coveralls
Copy link

coveralls commented Mar 15, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 22753b7 on denar90:binaryArgs into 7311faa on mozilla:master.

Copy link
Member

@rpl rpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @denar90, thanks for opening this PR, the new feature propose sounds reasonable to me, but it looks that this PR needs some additional changes to be complete, e.g.:

Feel free to mention me in a comment if you need help (or if you have any doubts that I can help you with).

.gitignore Outdated
@@ -1,5 +1,6 @@
# OSX
.DS_Store
.idea
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unrelated.

@denar90
Copy link
Contributor Author

denar90 commented Mar 19, 2019

@rpl thank you so much for the review 👍
I've update PR. Only thing I'm not sure about tests needed. Please, take a look and specify if more cases need to be covered :)

Thanks :)

@@ -290,6 +291,12 @@ export class FirefoxAndroidExtensionRunner {
'Firefox for Android target does not support --start-url option.'
);
}

if (this.params.binaryArgs) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpl I was thinking about smth like

const ignoredParams = {
  profilePath: '--profile-path',
  keepProfileChanges: '--keep-profile-changes',
  browserConsole: '--browser-console',
  preInstall: '--pre-install',
  startUrl: '--start-url',
  binaryArgs: '--binary-args',
};

const getIgnoredParamsWarningsMessage = (optionName) => {
  return `Firefox for Android target does not support ${optionName} option`;
};

so function printIgnoredParamsWarnings can be a bit cleaner

printIgnoredParamsWarnings() {
  Object.entries(ignoredParams).forEach((ignoredParam) => {
      if (this.params[ignoredParam]) {
        log.warn(
          getIgnoredParamsWarningsMessage(ignoredParams[ignoredParam])
        );
      }
    });
}

Only thing I stuck is flow with some errors, but I can dig in if you approve this approach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I like the idea

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(let me know if you get stuck on issues with flow errors, I'll be happy to help you to figure out how to properly handle those)

@denar90
Copy link
Contributor Author

denar90 commented Mar 19, 2019

btw, should I exclude package-lock.json changes from the PR?

@rpl
Copy link
Member

rpl commented Mar 21, 2019

btw, should I exclude package-lock.json changes from the PR?

yes please (I briefly looked to the diff and it seems that it is changing the exact versions into non exact versions, and so let's omit it from this PR, thanks for pointing it out!)

@rpl rpl changed the title Adds binaryArgs to pass additional flags to Firefox binary feature: Adds binaryArgs to pass additional flags to Firefox binary Mar 21, 2019
@@ -261,6 +261,7 @@ export class FirefoxAndroidExtensionRunner {
}

printIgnoredParamsWarnings() {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, let's remove this empty line.

} = this.params;

const binaryArgs = [];

if (browserConsole) {
binaryArgs.push('-jsconsole');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhm... I'm thinking that it may be better to append the additional arguments that the user may be passing to a web-ext run command (instead of prepending them before the ones added internally by web-ext itself).

@Rob--W what do you think about it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appending rather than prepending sounds good to me.

src/program.js Outdated
@@ -503,6 +503,12 @@ Example: $0 --help run.
demandOption: false,
type: 'boolean',
},
'binary-args': {
describe: 'Browser binary options. More at - ' +
'https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, let's indent this line as the other "multi-line" describe values in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt about adding eslint ignore for this line? URL is too long and linter doesn't like it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@denar90 How about omitting the link and give it a more generic description? e.g. something like the following:

'binary-args': {
  describe: "Additional command line options passed to the Browser binary',
  ...  
}

In my opinion, it may be a reasonable choice, e.g. as part of #1392 we may use the --binary-args also to pass additional CLI options to Chromium browsers.

Otherwise we may opt to include a shortened link instead (e.g. you can use https://mzl.la/2CEvSV5 which point to the above link).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about omitting the link and give it a more generic description?

SGTM 👍

@@ -202,6 +202,14 @@ describe('util/extension-runners/firefox-desktop', () => {
]);
});

it('passes binaryArgs tp Firefox', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, typo: tp -> to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops 😊

@rpl rpl changed the title feature: Adds binaryArgs to pass additional flags to Firefox binary feat: Adds binaryArgs to pass additional flags to Firefox binary Mar 21, 2019
@denar90
Copy link
Contributor Author

denar90 commented Mar 21, 2019

yes please (I briefly looked to the diff and it seems that it is changing the exact versions into non exact versions, and so let's omit it from this PR, thanks for pointing it out!)

had to do force-push, hope it isn't a problem :)

src/program.js Outdated
@@ -503,6 +503,11 @@ Example: $0 --help run.
demandOption: false,
type: 'boolean',
},
'binary-args': {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using binary-args here implies that the command line becomes --binary-args. That is a bit too long to my taste. Could you rename this to args
and add an alias: ['arg'],

I would also have liked the 'a' shorthand, but unfortunately the letter is already taken by the --artifacts-dir command.

} = this.params;

const binaryArgs = [];

if (browserConsole) {
binaryArgs.push('-jsconsole');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appending rather than prepending sounds good to me.

};

const getIgnoredParamsWarningsMessage = (optionName) => {
return `Firefox for Android target does not support ${optionName} option`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're at it, let's improve the English:

The Firefox for Android target does not support the ${optionName} option
or
The Firefox for Android target does not support ${optionName}.

} = this.params;

const binaryArgs = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this version of the PR the arguments are still prepended instead of appended. Restore the binaryArgs variable and use binaryArgs.push(...args); before passing it to firefoxApp.run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, looks like I misunderstood you. Does it look fine now - 28cb262?

@@ -88,7 +88,7 @@ export type FirefoxRunnerParams = {|
'no-remote'?: boolean,
'foreground'?: boolean,
'listen': number,
'binary-args'?: Array<string> | string,
'args'?: Array<string> | string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot simply rename binary-args to args here, because this is the API to an external library: https://github.com/mozilla-jetpack/node-fx-runner/blob/71e3848b6adac1054829391c826fd88cfb28f621/lib/run.js#L42-L48

Revert all changes in this file (and use binaryArgs instead of args: binaryArgs in the other file).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so just keep args only for cli? all other code will remain as is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The external interface of web-ext run will use args, and binary-args is only used internally, imposed by the contract of the fx-runner interface.

@@ -172,36 +172,44 @@ describe('util/extension-runners/firefox-desktop', () => {
params.firefoxApp.run,
sinon.match.any,
sinon.match.has(
'binaryArgs',
sinon.match.array.deepEquals(expectedBinaryArgs)
'args',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should also be binaryArgs.

Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Thanks for taking the efforts to minimize the diff.

@rpl
Copy link
Member

rpl commented Mar 29, 2019

@denar90 Thanks! Looks great to me too, Let's merge it!

@rpl rpl merged commit 44114ee into mozilla:master Mar 29, 2019
@rpl rpl added this to In progress in 3.1.0 via automation Mar 29, 2019
@caitmuenster
Copy link

Thanks, @denar90! Your contribution has been added to our contribution wiki.

Would you be interested in creating an account on mozillians.org? I'd be happy to vouch for you!

@denar90
Copy link
Contributor Author

denar90 commented Mar 30, 2019

@rpl @Rob--W thank you for the review and your comments. Really aprriciate your effort 👍

Thanks, @denar90! Your contribution has been added to our contribution wiki.

@caitmuenster thanks 😄

Would you be interested in creating an account on mozillians.org? I'd be happy to vouch for you!

Wow, I'll be more than happy to become part of the community 🙌
Here's my profile - https://mozillians.org/en-US/u/denar90/

@denar90
Copy link
Contributor Author

denar90 commented Mar 31, 2019

btw, about documentation for the new option, do you need some help with it to make release v3.1 faster?

@denar90 denar90 deleted the binaryArgs branch March 31, 2019 20:02
@Rob--W
Copy link
Member

Rob--W commented Mar 31, 2019

@denar90 The documentation that you added at --help should be sufficient.

The list of open tasks for 3.1.0 is at https://github.com/mozilla/web-ext/projects/3

@caitmuenster
Copy link

Thanks, @denar90! You're vouched.

Welcome onboard! 🎉

@denar90
Copy link
Contributor Author

denar90 commented Apr 1, 2019

The list of open tasks for 3.1.0 is at https://github.com/mozilla/web-ext/projects/3

@Rob--W thank you for the info 👍

@caitmuenster thank you for vouching. I'm really honored 😊

@zhl463
Copy link

zhl463 commented Apr 3, 2019

@denar90 I use this to launch firefox with extension, but shows
Error
connect ECONNREFUSED 127.0.0.1:6006
I can launch firefox, and load extension.

@denar90
Copy link
Contributor Author

denar90 commented Apr 3, 2019

@zhl463 thanks for trying this one :)
Can you follow a guide for puppeteer I've made and give feedback if it works for you?

@Rob--W
Copy link
Member

Rob--W commented Apr 3, 2019

@zhl463 That is likely this bug: #1509

@zhl463
Copy link

zhl463 commented Apr 8, 2019

@zhl463 thanks for trying this one :)
Can you follow a guide for puppeteer I've made and give feedback if it works for you?

Yes, I had followed this guide for puppeteer-firefox . but having this error

@zhl463
Copy link

zhl463 commented Apr 8, 2019

@zhl463 That is likely this bug: #1509

Thanks for replying. I will try it.

@rpl rpl moved this from In progress to Done in 3.1.0 Jul 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
3.1.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants