Skip to content

[Bug]: 'login' event is not emitted when the HTTP request is sent from the 'main' process using 'net.fetch()' on Windows and MacOS #44249

Closed as not planned

Description

@thomas-jakemeyn

Preflight Checklist

Electron Version

32.1.2

What operating system(s) are you using?

Other (specify below)

Operating System Version

MacOS Sonoma, Windows 11, Debian (Docker)

What arch are you using?

Other (specify below)

Last Known Working Electron version

No response

Expected Behavior

I have developed some tests to validate the behaviour of net.fetch() / fetch() on Windows, MacOS and Linux when sending HTTP(S) requests from the main process, from a renderer process and from a utility process. More specifically, I wanted to check the integration with the OS network settings and trust store when dealing with web proxies and self-signed certificates. See @hackolade/fetch for more details about my approach.

I expected net.fetch() / fetch() to behave consistently whatever the process and the operating system.

Actual Behavior

When sending HTTP requests through a web proxy that requires basic authentication, I observed the following:

  • On Linux, the 'login' event is properly emitted for all processes: main, renderer and utility. As a consequence, the request reaches the server in all cases.
  • On MacOS and Windows, the 'login' event is only emitted for a renderer process and a utility process. It is not emitted when sending the request using net.fetch() from the main process. As a consequence, that request fails with HTTP 407 Proxy Authentication Required.

So how am I supposed to deal with that case?

Image

Note that I created a separate issue for the problem with setCertificateVerifyProc(): see #44264.

Testcase Gist URL

https://gist.github.com/thomas-jakemeyn/035c6494d80b3250b992d70584f4c13c

https://github.com/hackolade/fetch/tree/develop

Additional Information

No response

Activity

  1. moved this to 👀 Unsorted Items in 32-x-yon Oct 15, 2024
  2. codebytere commented on Oct 16, 2024

    @codebytere
    Member

    @thomas-jakemeyn could you please create a standalone sample for this issue specifically? Linking your full fetch repo still requires we make assumptions and introduces extra margin for error in triage.

  3. added
    blocked/need-info ❌
    on Oct 16, 2024
  4. thomas-jakemeyn commented on Oct 16, 2024

    @thomas-jakemeyn
    Author

    Hello @codebytere,
    For reproducing this problem, you need more than just a Electron application. You also need to:

    • start some infrastructure: a proxy with basic auth and a server to reach through that proxy
    • apply some network settings in Windows / MacOS (optional)

    That's exactly what my repository contains. It provides a containerised environment where you can easily reproduce the problem...

  5. removed
    blocked/need-info ❌
    on Oct 16, 2024
  6. mckravchyk commented on Oct 30, 2024

    @mckravchyk
    Contributor

    I'm not getting the login event for Basic Auth in the main process on Linux either, v33.0.2 Please also consider Session.fetch.

  7. added
    blocked/need-repro
    on Nov 16, 2024
  8. electron-issue-triage commented on Nov 16, 2024

    @electron-issue-triage

    Hello @thomas-jakemeyn. Thanks for reporting this and helping to make Electron better!

    Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.

    Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

    Now adding the blocked/need-repro Needs a test case to reproduce the bug label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.

  9. xiaoma13 commented on Nov 17, 2024

    @xiaoma13

    @thomas-jakemeyn Have you solved your problem? I encountered the same difficulty.

  10. removed
    blocked/need-repro
    on Nov 17, 2024
  11. 9 remaining items

  12. DCzajkowski commented on Apr 17, 2025

    @DCzajkowski

    To be fair, the docs state that it will be fired only for renderer and utility processes:

    Emitted when webContents or Utility process wants to do basic auth.

    I think the go-to solution used to be attaching the login event on net.request:

    const request = net.request({ url: '<url>' })
    request.on('login', (authInfo, callback) => {
      callback('<username>', '<password>')
    })
    // ...
    request.end()

    However, that is not possible with the fetch implementation from net.

    Current solutions to work around this issue until its UX improves:

    1. Create a phantom window, make a request so the login callback is invoked, use the app as usual.
    2. Instead of using net.fetch, use net.request with .on('login', callback) handler.
    3. Patch electron (yarn patch or similar) by modifying fetch implementation to use the .on('login', callback) handler:
      export function fetchWithSession (input: RequestInfo, init: (RequestInit & {bypassCustomProtocolHandlers?: boolean}) | undefined, session: SessionT | undefined,
  13. datenreisender commented on May 16, 2025

    @datenreisender

    I do a variant of 2: Before using net.fetch for the first time, I call net.request once with a known URL. If a login is required, I handle it there. It is thus stored in the session and available in all subsequent uses of net.fetch.

    More effort than it should be, but to me better than the other solutions.

  14. thomas-jakemeyn commented on Jun 26, 2025

    @thomas-jakemeyn
    Author

    This issue still happens with electron 37.1.0.

  15. electron-issue-triage commented on Sep 25, 2025

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  16. thomas-jakemeyn commented on Sep 25, 2025

    @thomas-jakemeyn
    Author

    bump

  17. electron-issue-triage commented on Dec 25, 2025

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  18. yaoweiprc commented on Jan 15, 2026

    @yaoweiprc

    bump

  19. electron-issue-triage commented on Apr 16, 2026

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  20. electron-issue-triage commented on May 16, 2026

    @electron-issue-triage

    This issue has been closed due to inactivity, and will not be monitored. If this is a bug and you can reproduce this issue on a supported version of Electron please open a new issue and include instructions for reproducing the issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    32-x-ybug 🪲component/netcomponent/utilityProcesshas-repro-giststale

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions