Skip to content

second-instance event process arguments rip apart "name-value" arguments #20322

@siebertm

Description

@siebertm

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

When I run an electron app with requestSingleInstanceLock() and some command line arguments, in electron 6 (and maybe even 5), it seems that the --allow-file-access-from-files and --original-process-start-time=13213718723637733 arguments are inserted anywhere in the argv array. The original arguments are preserved but when we have applications which expect key-value type arguments, these arguments will be split, resulting in invalid values.

A simple test case is actually contained in the electron repository: https://github.com/electron/electron/blob/6-0-x/spec/fixtures/api/singleton/main.js

const { app } = require('electron')

app.once('ready', () => {
  console.log('started') // ping parent
})

const gotTheLock = app.requestSingleInstanceLock()

app.on('second-instance', (event, args) => {
  setImmediate(() => {
    console.log(JSON.stringify(args))
    app.exit(0)
  })
})

if (!gotTheLock) {
  app.exit(1)
}

When we now start the second instance with 2 arguments: ["--param", "value"], the second-instance event will fire with the following arguments:

[
  "path\to\electron.exe",
  "--param",
  "--allow-file-access-from-files",
  "--original-process-start-time=13213718723637733",
  "value"
]

The expected behaviour would be to keep the arguments together, like:

[
  "path\to\electron.exe",
  "--allow-file-access-from-files",
  "--original-process-start-time=13213718723637733",
  "--param",
  "value"
]

In the spec spec-main/api-app-spec.ts:222, the test successfully validates exactly that behaviour, but that may be wrong. the arguments could be appended or prepended, but should not be inserted somewhere in the middle...

  • Electron Version:

    • v6.0.9
  • Operating System:

    • Windows 10 (insiders, Version 10.0.18975.1000)
  • Last Known Working Electron version:

    • 4.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions