Open Bug 1724251 Opened 3 years ago Updated 1 year ago

Command line arguments handled in "command-line-startup" have unexpected side effects

Categories

(Toolkit :: Startup and Profile System, defect)

Desktop
macOS
defect

Tracking

()

People

(Reporter: jdescottes, Unassigned)

References

Details

In the RemoteAgent & Marionette components, we are handling command line arguments by observing "command-line-startup" instead of implementing the handle method of the nsICommandLineHandler interface.

This is done because handle is triggered too late in some scenarios for automation (eg safe mode).

The arguments are read using cmdLine.handleFlag. However they still exhibit side effects which seem usually only applied to unhandled arguments.

For instance, if you execute:

> ./mach run --marionette --remote-debugging-port=1234 

the browser will open on https://0.0.4.210/. If you change the value of "remote-debugging-port" this URL will change.

I am not sure what is responsible of this behavior, but what I can say is that this is exactly the same behavior as if we used two random arguments:

> ./mach run --test1 --test2=1234 

Technically, only the first argument needs to be "unhandled" for this behavior to be triggered.

In order to workaround this, implementing handle to simply consume the arguments from the command line seems to work. See the patch at https://phabricator.services.mozilla.com/D121768?id=467856

But it would be great if we didn't have to do that. Again handle happens too late so we can't really use it and we end up just consuming the arguments to avoid the side effect described here, without doing anything meaningful with them.

We are using the same API in the "command-line-startup" observer as in "handle" so it seems strange that it doesn't have the same effect.

Note, this happens for me on macos, haven't checked other operating systems.

See Also: → 1724028
Summary: Command line arguments handled in "command-line-startup" can have unexpected side effects → Command line arguments handled in "command-line-startup" have unexpected side effects

Seems that we re-initialize the command line after that notification on macOS for some reason: https://searchfox.org/mozilla-central/rev/00977c4e37865a92f1c15572ae4aea90e934b25b/toolkit/xre/nsAppRunner.cpp#5169

(In reply to Dave Townsend [:mossop] from comment #1)

Seems that we re-initialize the command line after that notification on macOS for some reason: https://searchfox.org/mozilla-central/rev/00977c4e37865a92f1c15572ae4aea90e934b25b/toolkit/xre/nsAppRunner.cpp#5169

Thanks for the input, just checked on Windows and I don't reproduce the issue. I'll mark this as macos only.

OS: Unspecified → macOS
Hardware: Unspecified → Desktop
Severity: -- → S4
See Also: → 1838158
You need to log in before you can comment on or make changes to this bug.