-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: prevent service worker registration errors in VSCode webview #7234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,16 @@ import "../node_modules/@vscode/codicons/dist/codicon.css" | |||||
|
|
||||||
| import { getHighlighter } from "./utils/highlighter" | ||||||
|
|
||||||
| // Prevent service worker registration in VSCode webview context | ||||||
| // VSCode webviews don't support service workers and attempting to register them causes errors | ||||||
| if ("serviceWorker" in navigator) { | ||||||
| // Override the register method to prevent any service worker registration attempts | ||||||
| navigator.serviceWorker.register = () => { | ||||||
| console.warn("Service worker registration is disabled in VSCode webview context") | ||||||
| return Promise.reject(new Error("Service worker registration is disabled in VSCode webview")) | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better compatibility, could we return a DOMException instead of a generic Error? This would match the original error type:
Suggested change
|
||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Initialize Shiki early to hide initialization latency (async) | ||||||
| getHighlighter().catch((error: Error) => console.error("Failed to initialize Shiki highlighter:", error)) | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,12 @@ class TelemetryClient { | |||||||||||||||
| capture_pageview: false, | ||||||||||||||||
| capture_pageleave: false, | ||||||||||||||||
| autocapture: false, | ||||||||||||||||
| // Disable service worker to prevent registration errors in VSCode webview | ||||||||||||||||
| disable_persistence: false, | ||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional? The
Suggested change
|
||||||||||||||||
| disable_session_recording: true, | ||||||||||||||||
| opt_out_capturing_by_default: false, | ||||||||||||||||
| // Explicitly disable web vitals and other features that might use service workers | ||||||||||||||||
| capture_performance: false, | ||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be helpful to add more detailed comments explaining why each option is disabled? This could help future maintainers understand the VSCode webview limitations:
Suggested change
|
||||||||||||||||
| }) | ||||||||||||||||
| } else { | ||||||||||||||||
| TelemetryClient.telemetryEnabled = false | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could there be a race condition here? The service worker override happens after imports but before the app renders. If PostHog or other libraries attempt to register service workers during their import/initialization phase, this override would be too late. Consider moving this block to the very top of the file, before any imports.