--- title: SharedWorker.port slug: Web/API/SharedWorker/port translation_of: Web/API/SharedWorker/port ---
A propriedade port
do {{domxref ("SharedWorker")}} retorna um objeto {{domxref ("MessagePort")}} usado para comunicar e controlar o shared worker.
myWorker.port;
Um objeto {{domxref("MessagePort")}}.
O snippet de código a seguir mostra a criação de um objeto SharedWorker usando o construtor {{domxref ("SharedWorker.SharedWorker", "SharedWorker ()")}} . Vários scripts podem acessar o worker através de um objeto do tipo {{domxref ("MessagePort")}} , usando a propriedade SharedWorker.port — A porta é iniciada usando o método start()
.
var myWorker = new SharedWorker('worker.js'); myWorker.port.start();
Veja um exemplo completo Basic shared worker example (run shared worker.)
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "#dom-sharedworker-port", "AbstractWorker.onerror")}} | {{Spec2('HTML WHATWG')}} | No change from {{SpecName("Web Workers")}}. |
{{SpecName('Web Workers', "#dom-sharedworker-port", "AbstractWorker.onerror")}} | {{Spec2('Web Workers')}} | Initial definition |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Support | {{CompatChrome(4)}} | {{CompatGeckoDesktop(29.0)}} | {{CompatNo}} | {{CompatOpera(10.60)}} | 5 {{CompatNo}} 6.1 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | Firefox OS (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Support | {{CompatNo}} | {{CompatNo}} | {{CompatGeckoMobile("33.0")}} | 2.1 | {{CompatNo}} | 11.5 | 5.1 {{CompatNo}} 7.1 |