The port
property of the SharedWorker
interface returns a MessagePort
object used to communicate and control the shared worker.
myWorker.port;
A MessagePort
object.
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.)
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'AbstractWorker.onerror' in that specification. | Living Standard |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 4 | ? | 29 | 10 | 10.6 | 5 — 6.1 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | ? | 33 | 11.5 | 5.1 — 7.1 | Yes |
SharedWorker
interface it belongs to.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/port