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

牧云@^-^@ 提交于 2019-11-28 07:34:17

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.

Take a look here

http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#workerglobalscope

I think it is confirming that once the browser goes away, any workers must stop.

Whenever a Document object is discarded, it must be removed from the list of the worker's Documents of each worker whose list contains that Document.

In the case where you have one window using web workers, and you close that window (or tab), the worker goes away.

If you have a case where you have a window, that opens other windows or tabs, the workers can continue. But if you close everything, they all go away.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!