Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens to an HTML5 web worker thread when the tab is closed while it's running?

I'm wondering what happens when a user closes the tab which spawned the worker thread, while the thread is still working. Does it halt everything? If so, is there a way to run the thread in the background even when the tab is closed?

like image 689
Vlad Avatar asked Jan 16 '12 02:01

Vlad


1 Answers

Yes it halts everything, a (dedicated) worker can't outlive its owner. If you use a shared worker, which can have multiple owners, the worker will only stay alive as long as at least one owner is alive. This is the case even if you pass on the entangled MessagePort to another window (i.e. owner of the message port is not the owner of the worker).

So, with shared workers you can "transfer" the ownership by opening a new window that establishes its own connection with the worker (with new SharedWorker(...)) and then close the old window. But one window must always remain open.

like image 123
bennedich Avatar answered Oct 04 '22 05:10

bennedich