SharedWorker.port

The port property of the SharedWorker interface returns a MessagePort object used to communicate and control the shared worker.

Syntax

myWorker.port;

Value

A MessagePort object.

Example

The following code snippet shows creation of a SharedWorker object using the SharedWorker() constructor. Multiple scripts can then access the worker through a MessagePort object accessed using the SharedWorker.port property — the port is started using its start() method:

var myWorker = new SharedWorker('worker.js');
myWorker.port.start();

For a full example, see our Basic shared worker example (run shared worker.)

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'AbstractWorker.onerror' in that specification.
Living Standard

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
portChrome Full support 4Edge Full support 79Firefox Full support 29IE No support NoOpera Full support 10.6Safari No support 5 — 6.1WebView Android No support NoChrome Android No support NoFirefox Android Full support 33Opera Android No support 11 — 14Safari iOS No support 5.1 — 7Samsung Internet Android No support 4.0 — 5.0

Legend

Full support  
Full support
No support  
No support

See also