Skip to content

net.WebSocket #44987

Closed

Description

@jameshfisher

Preflight Checklist

Problem Description

Our application needs to supports web proxies. It also needs to open WebSocket connections from the main process.

The natural choice would be the net module "uses Chromium's native networking library instead of the Node.js implementation, offering better support for web proxies." However, it only supports HTTP(S) requests; not WebSocket.

Proposed Solution

The net module should expose Chromium's WebSocket implementation like this:

const { net } = require('electron')
new net.WebSocket(...)

Alternatives Considered

I have been unable to find any alternative implementation that lets us open WebSocket connections from the main process and support all web proxies. I would also appreciate any advice on alternatives to the Electron net module.

I found https://github.com/jfromaniello/mac-ca and https://github.com/ukoloff/win-ca, but

  • They are OS-specific. I would like to support all platforms supported by Electron.
  • It's unclear to me whether this supports all web proxies. Is the only significant difference between the Node.js and Chromium network stacks their list of root CAs?

Additional Information

I found this previous issue which is very similar. It was closed because "it will take a considerable amount of work since the net layer of chromium doesn't expose it directly as a part of URLRequest." 7.5 years later, perhaps this has changed?

Activity

  1. felixrieseberg commented on Jan 13, 2025

    @felixrieseberg
    Member

    I think this is a pretty reasonable idea - and if it could be done without increasing complexity dramatically, we might be able to take a PR. Would you be interested in writing one?

  2. jameshfisher commented on Jan 19, 2025

    @jameshfisher
    ContributorAuthor

    I don't know the Electron codebase but I've had a look around:

    net.request is implemented in /lib/browser/api/net.ts using ClientRequest
    ClientRequest is implemented in /lib/common/api/net-client-request.ts using createURLLoader from process._linkedBinding('electron_common_net')
    electron_common_net and createURLLoader are defined in /shell/common/api/electron_api_net.cc using SimpleURLLoaderWrapper
    SimpleURLLoaderWrapper is implemented in /shell/common/api/electron_api_url_loader.cc using network::SimpleURLLoader from services/network/public/cpp/simple_url_loader.h
    simple_url_loader.h is from Chromium?

    Not sure where Chromium's WebSocket implementation would be exposed for us to use, but I see files like services/network/websocket_factory.cc

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

Metadata

Metadata

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions