ExperimentalExperimentalHow to obtain the port
Optionaloptions: { addPageHideListener?: boolean }addPageHideListener defaults to true; tests that share one jsdom window pass
false so sockets do not pile listeners onto it
ExperimentalbinaryReadonly ExperimentalbufferedReadonly ExperimentalCLOSEDReadonly ExperimentalCLOSINGReadonly ExperimentalCONNECTINGReadonly ExperimentalextensionsExperimentaloncloseExperimentalonerrorExperimentalonmessageExperimentalonopenReadonly ExperimentalOPENReadonly ExperimentalprotocolExperimentalreadyExperimentalurl
A
WebSocketwhose wire is an ElectronMessagePortto the main process instead of a TCP socket. Chromium closes every TCP client socket when the OS suspends; a MessagePort is a Mojo pipe, which observes no power events, so the connection survives sleep.Isomorphic with the DOM
WebSocketfor everythingRpcClientuses:readyState,url,send,close, and theopen/message/error/closeevents. A port has no close code, so intent travels in a close frame:close(code, reason)posts one before closing the port, a frame from main is reported as main's close, and a port that closes with no frame is 1006 withwasClean: false, the same shape a websocket that died produces.pagehidecloses with 1001 so a reload or window close reads as clean on main.Keeps the first port it is handed and ignores any other: the bridge that hands ports out is reachable from same-origin web views, and a page has exactly one connection.