Svetlin Mladenov Svetlin Mladenov - 4 months ago 6x
Javascript Question

Detecting that a web-worker has been loaded without sending an explicit message

Is there a way to detect that a web-worker has been loaded. I looked at the spec but there is only an

event. There is no
or anything of the sort.

I am looking for an alternative to the script element onload event but for web-workers.

I want to do it without the worker explicitly sending a message after load because it is for a library, and I need it to be as general as possible and don't want to impose this restriction on the worker.


There is not by design. This was planned originally, but got taken out later on. I forgot the rationale, but I suspect it is related to certain implementations allowing the allocation of many workers, but only running a couple at the time.

(There are some plans to improve this, in particular if SharedArrayBuffer happens, which needs that kind of information, but there's no standard way now.)

A workaround might be to fetch the code in advance and then initiate the worker from a blob URL.