The port
property of the SharedWorker
interface returns a MessagePort
object used to communicate and control the shared worker.
The port
property of the SharedWorker
interface returns a MessagePort
object used to communicate and control the shared worker.
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:
js
const myWorker = new SharedWorker("worker.js"); myWorker.port.start();
For a full example, see our Basic shared worker example (run shared worker.)
Specification |
---|
HTML Standard # dom-sharedworker-port-dev |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
port |
5 | 79 | 29 | No | 10.6 | 165–7 | No | No | 33 | 11–14 | 165–7 | 4.0–5.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/port