Intent to Ship: ES modules for Shared Workers ('module' type option)

156 views
Skip to first unread message

Eriko Kurimoto

unread,
Jan 28, 2020, 12:10:40 PM1/28/20
to blink-dev
Contact emails
Support module scripts loading in shared workers. When the ‘module’ type is set on the constructor’s type attribute, worker scripts are loaded as ES modules and the import statement is available on worker contexts. 

Explainer
‘module’ type in WorkerOptions enables you to load module scripts as Shared Workers.

        const worker = new SharedWorker(‘worker.js’, { name: ‘worker-name’, type: ‘module’ });

We continue to support DOMString name as the second argument of SharedWorker constructor and the default value of type attribute is ‘classic’, so the behavior of the traditional way of constructing SharedWorker (as below) still works as is.

        const worker = new SharedWorker(‘worker.js’, ‘worker-name’);
        // new SharedWorker(‘worker.js’, { name: ‘worker-name’, type: ‘classic’ });

A shared worker constructed with this option can use static import, dynamic import(), and export statements.

        // worker-library.js
        export function doSomething() { … };
        export const answer = 42;

        // worker.js
        import * as module from “./worker-library.js”
        module.doSomething();
        console.log(module.answer); // 42

In WorkerOptions, credentials mode can be specified using a value from {‘include’, ‘same-origin’, ‘omit’}. Credentials mode is used for fetching the module graph, and used only when type attribute is set to ‘module’.

        const worker = new SharedWorker(‘worker.js’, { name: ‘worker-name’, type: ‘module’, credentials: ‘same-origin’});

Module script loading is available for any worker type (dedicated worker, shared worker, service worker) in terms of the specification, but currently it is only shipped for Dedicated Workers. For the next step, this Intent-to-Ship targets Shared Workers.

Design docs/spec
Specification:
SharedWorker interface

Module script loading for workers

TAG review was already filled and resolved for modules on workers.
Interoperability and Compatibility
This feature is not supported by any other browser yet. 
Edge: Positive (showed an interest in the initial spec PR)
Firefox: Positive (have been involved in discussion since the initial spec PR. impl issue)
Safari: No public signals (impl issue for dedicated workers)
Web developers: Positive (Starred by 15 users as of January 27, 2020)

Note: the browser signals for Edge and Firefox are from the initial design of the feature in 2016. We believe that nothing has changed that would decrease their support for the specification, but have pinged on the Firefox implementation issue to try to confirm, and welcome any corrections or updates.

Will this feature be supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?
Shared Workers on Chrome on Android is not enabled yet.
This feature will be supported on Windows, Mac, Linux, Chrome OS.

Is this feature fully tested by web-platform-tests?
Mostly tested. Web platform tests for module script loading in shared workers can be found in wpt/workers/modules directory. You can see the test result from wpt.fyi. We need to add tests for csp, credentials and referrer which are WIP.
Also we will add web-platform-tests here as well: content-security-policy, referrer-policymixed-content, upgrade-insecure-request.
SharedWorker cannot be nested nor called from Dedicated Workers, so there are no tests for constructing SharedWorker from workers.

Tracking bug
https://bugs.chromium.org/p/chromium/issues/detail?id=824646

Link to entry on the Chrome Platform Status

Chris Harrelson

unread,
Jan 30, 2020, 3:38:08 PM1/30/20
to Eriko Kurimoto, blink-dev
Hi, one question:

Is there any additional concern or special condition about shared workers that make this intent different than the one for dedicated workers? Or is the reason it was omitted previously just that implementation was not complete?

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/1e47122c-0550-4b97-961a-4d30d032f8aa%40chromium.org.

Eriko Kurimoto

unread,
Jan 31, 2020, 12:01:49 AM1/31/20
to Chris Harrelson, blink-dev
Hi. Thanks for reviewing.

About your question, ES module for Shared Workers was omitted in that for Dedicated Workers because of the implementation reason.

Eriko

Chris Harrelson

unread,
Jan 31, 2020, 12:32:10 AM1/31/20
to Eriko Kurimoto, blink-dev

Yoav Weiss

unread,
Jan 31, 2020, 4:32:33 AM1/31/20
to Chris Harrelson, Eriko Kurimoto, blink-dev

Daniel Bratell

unread,
Feb 6, 2020, 2:23:06 PM2/6/20
to Yoav Weiss, Chris Harrelson, Eriko Kurimoto, blink-dev

Eriko Kurimoto

unread,
Feb 18, 2020, 1:33:25 AM2/18/20
to blink-dev, Daniel Bratell, Eriko Kurimoto, blink-dev, Yoav Weiss, Chris Harrelson
Thank you all! This feature is enabled by default in M82.  I updated the chrome platform status.

LGTM2

Ok then. LGTM1!

To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.
Reply all
Reply to author
Forward
0 new messages