A shared worker is accessible by multiple scripts — even if they are being access by different windows, iframes or even workers — as long as they are on the same origin.
Questions tagged [shared-worker]
53 questions
11
votes
1 answer
Why does the SharedWorker onConnect event have a Ports array?
In all examples I've seen, they're similar to this
onconnect = function(e) {
var port = e.ports[0];
port.onmessage = function(e) {
var workerResult = 'Result: ' + (e.data[0] * e.data[1]);
port.postMessage(workerResult);
…

No_name
- 2,732
- 3
- 32
- 48
10
votes
1 answer
Best/proper way to share a single WebSocket connection across multiple tabs
How does one share a single WebSocket connection across multiple browser tabs?
I'm aware of multiple questions/posts suggesting SharedWorker. However, it is not a viable solution due to the poor adoption of SharedWorker (only 35% globally according…

Alexander Qiu
- 117
- 1
- 8
6
votes
2 answers
How to configure Angular-CLI-generated project to include a SharedWorker
What are the specific steps to add a SharedWorker to an @angular/cli >1.2-generated project. I would like the SharedWorker to be defined in TypeScript (with full/correct type-definitions editor support), to share interfaces with the main project,…

CalvinDale
- 9,005
- 5
- 29
- 38
6
votes
1 answer
How to start a Server-Sent Event "only once" inside a SharedWorker to push message for any open script?
I have a server-sent event (SSE) implementation that is working with almost no issues. The only issue that I am having is "one user can have many connections to the server". Basically, If a user opens more than one web browser's tab, each tab will…

Junior
- 11,602
- 27
- 106
- 212
5
votes
0 answers
file upload using shared web worker with page navigation
I want to do background upload of files which does not impact the primary usage of the page once the upload of files has started being processed.
In addition to this we want to be able to navigate away from the page performing the upload to other…

Manpreet Singh
- 91
- 5
4
votes
2 answers
How to call shared worker from the web worker?
Is it possible to call a Shared Worker from the Web Worker?
Could you please give me an example.
In my case I have a few web workers and I need to share a singleton service between them.

Warlock
- 7,321
- 10
- 55
- 75
3
votes
2 answers
Is there a way for SharedWorker to tell if it is about to get closed?
Is there a way to tell that the SharedWorker is about to get closed, something like the beforeunload event that window has?
I need this information inside of the worker to signal server of closing of web socket etc.

Akxe
- 9,694
- 3
- 36
- 71
3
votes
1 answer
How to share data with SharedWorker
There has been a lot of discussions and tutorials on SharedWorker on the Internet and StackOverflow, but none has really achieved the most basic goal -- passing data directly between two shared workers.
To me, the strength of SharedWorker over a…

Chong Lip Phang
- 8,755
- 5
- 65
- 100
3
votes
0 answers
Is it possible to run socketIO connections from a service worker file
I tried running it using shared workers. It works as expected with the exception for a single tab connection a single refresh still creates a new socket connection. I decided to try out service workers since it has a longer life span in contrast.…

Arausi Daniel
- 191
- 2
- 9
3
votes
0 answers
How to share WebAssemly module between UI thread and service worker?
My web app is using a web assembly module for some non trivial operations. It has a service worker set up to handle push notifications. Both the main thread and the push notification handler need access to the web assembly module.
Is there a…

Justin D.
- 4,946
- 5
- 36
- 69
3
votes
1 answer
Firefox Quantum SharedWorker not work
In Chrome and Firefox <57 it works, but in Firefox Quantum doesn't work.
The goal is to send a message to another tab in the browser.
When filling in the text input and clicking the send button, the other tab in the browser should write the message…

David
- 156
- 8
3
votes
1 answer
Are Shared WebWorkers supported in IE 11?
I tried to implement this code, here is the link. It works in Chrome, whereas in IE 11 it gives an error 'SharedWorker' is undefined. But according to caniuse, WebWorkers are supported in IE 11.
Does anyone know who is right?

SoftTimur
- 5,630
- 38
- 140
- 292
3
votes
0 answers
How to run EventSource inside Shared Worker?
I implemented server-sent events to receive messages from the server. I describe how I implemented it on another question
Now I am trying to run it inside a shared worker to prevent the user from opening multiple connections to the servers via…

Jaylen
- 39,043
- 40
- 128
- 221
2
votes
1 answer
It has a way to use shared-workers with NuxtJS v.2.14.12?
I've a NuxtJS application and I'm trying to share a websocket connection throught the open tabs. Researching for this, I have found a way using shared-workers but I dont found this at Nuxt / Nuxt PWA documentation. I only found way to create custom…

Bruno Cardoso
- 126
- 7
2
votes
0 answers
Can a service worker postMessage() directly to a shared worker client?
In a service worker, the client interface has postMessage() for talking to clients, which can be of type "window", "worker", or "sharedworker".
In "window" clients, the message event is sent to navigator.serviceWorker.controller. Example service…

Ben Dean
- 21
- 3