Skip to content

v3.1.1: web workers are broken because importScripts() cannot load socket.io.js #3809

Closed
@ericmandel

Description

@ericmandel

Describe the bug

Using v3.1.1 and calling importScripts() in a worker to load socket.io.js results in a NetworkError, such as the following:

Screen Shot 2021-02-18 at 6 48 15 PM

Use of importScripts() works fine with v2.

To Reproduce

The attached zip file contains 4 files: v2.html, v2.js, along with v3.html, v3.js ... but they are short:

v2.html:

<html>
<body>
<script>
  let v2 = new Worker("v2.js");
</script>
</body>
</html>

v2.js:

importScripts("https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js");

v3.html:

<html>
<body>
<script>
  let v3 = new Worker("v3.js");
</script>
</body>
</html>

v3.js:

importScripts("https://cdn.socket.io/3.1.1/socket.io.js");

These two test cases use CDN files for the sake of simplicity. I am not using CDN files in my project, but get the same result.

To see the correct behavior (no error), load v2.html. To see the error in the JavaScript console, load v3.html.

According to https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts, the Network error is indicates:

Screen Shot 2021-02-18 at 6 54 53 PM

Expected behavior

I expect importScripts() to load socket.io.js successfully.

Platform:

  • Device: Macbook Pro
  • OS: 10.15.7

socketioImportScripts.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions