Skip to content

Feature detection of module workers is hard #5325

@surma

Description

@surma

Currently, the advised way to feature-detect support for new Worker({type: "module"}) is to create an options object and see if the .type property gets accessed by the constructor with a getter:

let supportsModuleWorker = false;
const options = {
  get type() {
    supportsModuleWorker = true
  }
};
new Worker("data:,", options).terminate();

That seems fairly convoluted. I propose adding type property to module instances:

const w = new Worker("data:,", {type: "module"})
const supportsModuleWorker = "type" in w;
w.terminate();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions