[Bug]: second instance send "--allow-file-access-from-files" to master instance on Windows · Issue #32933 · electron/electron · GitHub
Skip to content

[Bug]: second instance send "--allow-file-access-from-files" to master instance on Windows #32933

Closed as not planned

Description

@fxha

Preflight Checklist

Electron Version

15.3.7, 17.0.1

What operating system are you using?

Windows

Operating System Version

Win10 x64

What arch are you using?

x64

Last Known Working Electron version

???

Expected Behavior

$myApp.exe --path C:\tmp\foo.txt --foo=1 --show 1

The command above is converted into argv (below) in the second instance and is received without any changes in the master instance when requestSingleInstanceLock is used.

argv = [
  'myApp.exe',
  '--path',
  'C:\tmp\foo.txt',
  '--foo=1',
  '--show',
  '1'
]

No --allow-file-access-from-files is send to master instance because it was not included in original argv and no sorting is performed.

Optionally if --allow-file-access-from-files is needed by Chromium, it should be appended or inserted after the application path but before the first user argument.

Actual Behavior

The argv is correctly built in the second instance, but Electron inserts a --allow-file-access-from-files flag at an unexpected position that may destroy argument parsing when sending to master. In addition the argv received by the master seem to be "sorted".

The argv received by the master instance via app.on('second-instance'):

argv = [
  'myApp.exe',
  '--path',
  '--foo=1',
  '--show',
  '--allow-file-access-from-files',
  'C:\tmp\foo.txt',
  '1'
]

Happy argument parsing 😄

Testcase Gist URL

No response

Additional Information

Build a dummy Electron app with following code:

app.on('second-instance', (event, argv, workingDirectory) => {
  console.log(argv)
})

const gotSingleInstanceLock = app.requestSingleInstanceLock()
if (!gotSingleInstanceLock) {
  process.stdout.write('Other instance detected: bye\n')
  app.exit()
  return
}

Activity

  1. nornagon commented on Feb 16, 2022

    @nornagon
    Contributor

    Duplicate of #20322

  2. fxha commented on Feb 17, 2022

    @fxha
    Author

    Hey @nornagon, could you please update the documentation that other users know that argv isn't actually the original command line arguments that are passed to the application but a pre-parsed one? According to the linked issue, a user should never use the provided information because they may invalid.

    Since when is additionalData available as requestSingleInstanceLock parameter? v15 doesn't seem to have this option available according TS definitions.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions