Functions and classes available to Web Workers - Web APIs 编辑

In addition to the standard JavaScript set of functions (such as String, Array, Object, JSON, etc), there are a variety of functions available from the DOM to workers. This article provides a list of those.

Worker Contexts & Functions

Workers run in a different global context than the current window! While  Window is not directly available to workers, many of the same methods are defined in a shared mixin (WindowOrWorkerGlobalScope), and made available to workers through their own WorkerGlobalScope-derived contexts: 

Some of the functions that are common to all workers and to the main thread (from WindowOrWorkerGlobalScope) are: atob(), btoa(), clearInterval()clearTimeout(),dump() This API has not been standardized., setInterval(), setTimeout().

The following functions are only available to workers:

Web APIs available in workers

Note that if a listed API is supported by a platform in a particular version, then it can generally be assumed to work in web workers.

The following Web APIs are available to workers: Broadcast Channel API, Cache API,Channel Messaging API,Console API, Crypto, CustomEvent, Data Store (Firefox only), DOMRequest and DOMCursorFetchFileReaderFileReaderSync (only works in workers!), FormDataImageDataIndexedDBNetwork Information APINotificationsPerformancePerformanceEntry, PerformanceMeasure, PerformanceMark, PerformanceObserver, PerformanceResourceTimingPromiseServer-sent eventsServiceWorkerRegistrationTextEncoder and TextDecoderURLWebGL with OffscreenCanvas (enabled behind a feature preference setting gfx.offscreencanvas.enabled), WebSocketXMLHttpRequest.

Workers can also spawn other workers, so these APIs are also available: WorkerWorkerGlobalScopeWorkerLocationWorkerNavigator.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:200 次

字数:8863

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文