Skip to content

fix: Prevent TypeError from orphaned content script - #168

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/orphaned-content-script
Open

sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/orphaned-content-script

Conversation

@sentry

@sentry sentry Bot commented Sep 23, 2026

Copy link
Copy Markdown

This PR addresses a TypeError: Cannot read properties of undefined (reading 'local') that occurs in the GitHub file content script (src/content/github/file/main.tsx).

Root Cause:
In Chrome Manifest V3, when the browser extension is reloaded or updated while a content script is already running on a tab, the extension context for that content script becomes invalidated. This causes browser.storage (which is a polyfill for chrome.storage) to become undefined. Subsequent attempts to access browser.storage.local then throw a TypeError.

Solution:
To prevent this, a new helper function isExtensionContextValid() has been introduced. This function checks browser.runtime?.id, which will be undefined if the extension context has been invalidated. The main() function in src/content/github/file/main.tsx now calls this validity check at its entry point. If the context is invalid, main() will return early, preventing any access to browser.storage.local and gracefully handling the orphaned content script scenario. This protects both initial page loads and subsequent soft-nav:end events from triggering the error.

Fixes BROWSER-EXTENSION-SH

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@codecov

codecov Bot commented Sep 23, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 176 bytes (0.03%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
codecov-browser-extension-array-push 660.64kB 176 bytes (0.03%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: codecov-browser-extension-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
background.js 89 bytes 207.75kB 0.04%
githubFile.js 87 bytes 11.55kB 0.76%

Files in githubFile.js:

  • ./src/content/github/file/main.tsx → Total Size: 11.97kB

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants