Skip to content

getForwardedArgs() in main.js drops the first user argument for packaged apps #1072

@skynightz

Description

@skynightz

Summary

  • Version: ElectronNET.Core / ElectronNET.Core.AspNet 0.5.0
  • .NET: .NET 10 (net10.0)
  • Electron: 39.8.9
  • Target: win-x64 also macOS/Linux packaged targets

In a packaged app, the first user argument is dropped before being forwarded
to the backend, because the host main.js uses process.argv.slice(2):

return process.argv.slice(2).filter(arg => { ... });

The first user argument shifts by one between launch modes (offset documented
in #647), so the fixed slice(2) only matches the dev launch:

electronize start (dev):   first user arg at process.argv[2]   ->  slice(2) keeps it    ✓
packaged executable:       first user arg at process.argv[1]   ->  slice(2) drops it    ✗

Steps to Reproduce

  1. Run myapp.exe --foo=bar — backend gets no args.
  2. Run myapp.exe -- --foo=bar--foo=bar arrives, confirming the first argument is swallowed.

Fix

const argsOffset = app.isPackaged ? 1 : 2;
return process.argv.slice(argsOffset).filter(arg => { ... });

Workaround

Insert an empty argument -- before getForwardedArgs() runs, via the custom_main.js hook:

const { app } = require('electron');
exports.onStartup = function () {
    if (app.isPackaged) {
        process.argv.splice(1, 0, '--');
    }
    return true;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions