Skip to content

Instantly share code, notes, and snippets.

@developit
Last active June 11, 2020 03:37
Show Gist options
  • Save developit/5b09dc86c644d76f8fbd8abe294440f2 to your computer and use it in GitHub Desktop.
Save developit/5b09dc86c644d76f8fbd8abe294440f2 to your computer and use it in GitHub Desktop.
var s;
function supportsModuleWorkers() {
if (s==null) {
s = false;
try {
new Worker('data:,', Object.defineProperty({}, 'type', {
get() { s = true; }
})).terminate();
} catch (e) {}
}
return s;
}
@dasa
Copy link

dasa commented Feb 24, 2020

Nice, but Firefox shows this console warning: Attempting to create a Worker from an empty source. This is probably unintentional.

Is it possible to avoid this?

@dasa
Copy link

dasa commented Feb 24, 2020

Changing line 8 to this seems to do the trick: })).terminate();

@developit
Copy link
Author

Good suggestion @dasa! I've added it.

@gangsthub
Copy link

gangsthub commented Mar 2, 2020

As a pure func?

function supportsModuleWorkers() {
  let s = false;
    try {
      new Worker('data:,', Object.defineProperty({}, 'type', {
        get() { s = true; }
      })).terminate();
    } catch (e) {}
  return s;
}

@RReverser
Copy link

Typo in teminate.

@gangsthub
Copy link

Typo in teminate.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment