SharedWorkerGlobalScope: close() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The close() method of the SharedWorkerGlobalScope interface discards any tasks queued in the SharedWorkerGlobalScope's event loop, effectively closing this particular scope.

Syntax

js
close()

Parameters

None.

Return value

None (undefined).

Examples

If you want to close your worker instance from inside the worker itself, you can call the following:

js
close();

close() and self.close() are effectively equivalent — both represent close() being called from inside the worker's inner scope.

Note: There is also a way to stop the worker from the main thread: the Worker.terminate method.

Specifications

Specification
HTML
# dom-sharedworkerglobalscope-close-dev

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
close
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 29 (Release date: 2014-04-29)
footnote Full support
Opera – Full support
Opera 10.6 (Release date: 2010-07-01)
footnote Full support
Safari – No support
Safari 5 – 6 (Release date: 2010-06-07)
footnote Removed in 7 and later
Safari – Full support
Safari 16 (Release date: 2022-09-12)
footnote Full support
Chrome Android – Preview support
Chrome Android 148 (Release date: 2026-05-05)
footnote Preview browser support
Firefox for Android – Full support
Firefox for Android 29 (Release date: 2014-04-29)
footnote Full support
Opera Android – Full support
Opera Android 11 (Release date: 2011-03-22)
footnote Full support
Safari on iOS – No support
Safari on iOS 5 – 6 (Release date: 2011-10-12)
footnote Removed in 7 and later
Safari on iOS – Full support
Safari on iOS 16 (Release date: 2022-09-12)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Preview support
WebView Android 148 (Release date: 2026-05-05)
footnote Preview browser support
WebView on iOS – No support
WebView on iOS 5 – 6 (Release date: 2011-10-12)
footnote Removed in 7 and later
WebView on iOS – Full support
WebView on iOS 16 (Release date: 2022-09-12)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
In development. Supported in a pre-release version.
In development. Supported in a pre-release version.
No support
No support
Has more compatibility info.

See also

DedicatedWorkerGlobalScope