Skip to main content
Worker object

A worker is a script that runs in a background process and does not block other code processes attached to the page.



DOM Information

Inheritance Hierarchy

The Worker does not inherit from any class or interface.


The Worker object has these types of members:


The Worker object has these events.


Returns an error if a worker throws an unhandled exception.


Returns a message from the parent thread to the worker thread, or between two MessagePort objects.



The Worker object has these methods.


Sends a message from the worker to the parent thread.


Terminates a worker thread immediately.



The Worker object has these properties.

PropertyAccess typeDescription



Allows access to the Indexed Database API, as implemented by Internet Explorer 10.



In the past, if you had to do a task on a webpage that might take a long time, you forced the user to wait until the task was finished. Workers can solve that problem by packaging and running code that runs separately from the main webpage. These packages are called threads and run in the background. You can have more than one worker running at once, each with its own thread and JavaScript code file.

Workers run in a "sandbox" and have limited scope. They cannot access most of the object model of the webpage but do have access to the global core JavaScript objects. You can use the WorkerGlobalScope object inside the worker to access objects in the worker's scope.

To terminate a worker thread from the main document, use the terminate method. To terminate the worker thread from inside its own code, use the close method.

You can send messages to a worker from the main document using postMessage. The message will be cloned. You can receive messages from the worker by listening for message events using the onmessage event.

If a worker throws an exception and doesn't handle the exception itself, the exception will create an event you can listen for with the onerror event.

You can determine the location of a worker from inside the worker by using the WorkerLocation object.

You can determine which navigator objects are available to the worker by using the WorkerNavigator object.

Shared workers are not supported in this release.