Experiment 01 · Worker instantiation · Module script
Uses a module script, that simply acknowledges messages it receives, logging them on the console. Module script instantiated with:
const worker = new Worker( "worker.js", { type: "module" }); // Note the type: "module"` option
worker.postMessage( { op: "sip", args: [ "☕️" ] });
worker.postMessage( { op: "crunch", args: [ "🍐", "🍪" ] });
worker.postMessage( { op: "listen", args: [ "Shut up and play yer guitar / Ship Ahoy" ] });
worker.postMessage( { op: undefined });
Open the Console (
Supported by Safari 12 and Firefox 64 out-of-the box, however not by Chrome 71, which displays following message:
Uncaught TypeError: Failed to construct 'Worker': Module scripts are not supported
on DedicatedWorker yet.
You can try the feature with
'--enable-experimental-web-platform-features' flag (see https://crbug.com/680046)
Starting Chrome with the experimental-web-platform-features
flag
provides support for instantiating web workers with module scripts.
$ open -a "Google Chrome" --args --enable-experimental-web-platform-features