connectToSharedWorker creates a two new MessagePort which are entangled with each other. One of the two ports is returned, and the other is sent to the Worker with the given name. If such a Worker does not yet exist, one is created.

The Worker receives the other MessagePort through an onconnectEvent fired on the WorkerGlobalScope object.

There is no way to get a reference to the shared Worker object itself.

Communication for shared workers is different from communication for non-shared ones.