Sending messages from parent scripts

Note that any script in the same origin (basically, same origin means that you're accessing it from multiple URLs covered under the same domain; for example, https://www.google.co.in/ accessing google.com/script.js follows the same origin, but facebook.com accessing google.com/script.js does not. There will be more on same origin in a later section named Same origin policy) can access the shared worker in the same way our previous script.js  accesses it, with the worker being in the same state for every file which accesses it.

Here's how you'll send a message from a script to a worker:

// script.jsconst awesomeworker = new SharedWorker('myworker.js');awesomeworker.port.start();awesomeworker.port.postMessage("Hello ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.