Skip to content

navigator.serviceWorker may be undefined in some secure contexts #52044

Closed
@TheCymaera

Description

@TheCymaera

lib Update Request

Configuration Check

My compilation target is ESNext and my lib is the default.

Missing / Incorrect Definition

navigator.serviceWorker is undefined in some secure contexts (private mode on Firefox), thus the correct type definition should be:

readonly serviceWorker?: ServiceWorkerContainer;

Sample Code

Bad:

navigator.serviceWorker.register()

Good:

navigator.serviceWorker?.register()

Documentation Link

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/serviceWorker

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions