[Web API type definition issue] Mark navigator.serviceWorker as an optional property
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- frontend
Research direction
No source file or test is named in the issue. Start by reviewing how the generator represents Navigator and ServiceWorker, then read the linked TypeScript issue and existing discussion before changing the declaration. Done means the generated type reflects the reported optional behavior and the relevant validation passes.
Written by the indexing model from the issue text.
Description
Summary
navigator.serviceWorker may be undefined in some secure contexts, like IABs and Firefox Private Mode
Expected vs. Actual Behavior
navigator.serviceWorker.register()
Expected: throw a TypeScript error; serviceWorker may be undefined
Actual: no TypeScript error
Playground Link
No response
Browser Support
- This API is supported in at least two major browser engines (not two Chromium-based browsers).
Have Tried The Latest Releases
- This issue applies to the latest release of TypeScript.
- This issue applies to the latest release of
@types/web.
Additional Context
I am requesting a reconsideration of marking navigator.serviceWorker as optional.
The previous issue opened in 2023 on the TypeScript repository has been labeled as "Working as Intended" under the explanation by Ryan Cavanaugh: (https://github.com/microsoft/TypeScript/issues/52044#issuecomment-1372844081)
Quoting:
APIs like these are marked non-optional for convenience, since it's extremely plausible that your script runs only in secure contexts as an invariant.
Based on his comment, it appears to me that it had been misunderstood that serviceWorker is undefined in non-secure contexts, while the point is that it may be undefined even in secure contexts.
Examples include but are not limited to:
- Firefox's private mode
- Some in-app browsers, especially those on iOS.
In-app browser usage is not insignificant!
~62% of global web traffic comes from mobile devices, and, according to eMarketer, ~88% of the time people spend in their mobile devices is used on apps. Apps today incorporate IABs for the purposes of authentication, advertisement, and more. IAB usage is at its peak in social media and messaging apps.
Given the high usage of IABs. serviceWorker not being an optional property of navigator is anything but convenient.
- Dominant language
- TypeScript
- Stars
- 740
- Forks
- 474
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 15
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/TypeScript-DOM-lib-generator
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
microsoft/TypeScript-DOM-lib-generator#2554 · 6 comments ·
-
lib.d.ts bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
lib.d.ts bug
Difficulty 1/5 Under an hour Newbie friendliness 68/100
microsoft/TypeScript-DOM-lib-generator#2154 · 1 reaction ·
-
lib.d.ts bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microsoft/TypeScript-DOM-lib-generator#2107 · 5 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microsoft/TypeScript-DOM-lib-generator#1675 · 2 comments · 1 reaction ·
All issues in microsoft/TypeScript-DOM-lib-generator
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fullcalendar/fullcalendar#8106 ·