Skip to content

fix: Handle missing GitHub raw button gracefully - #162

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/github-raw-button-not-found
Open

fix: Handle missing GitHub raw button gracefully#162
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/github-raw-button-not-found

Conversation

@sentry

@sentry sentry Bot commented Aug 21, 2026

Copy link
Copy Markdown

This PR addresses the "Error: Raw button not found" issue (BROWSER-EXTENSION-SA) which occurred when the extension attempted to locate GitHub's [data-testid="raw-button"] element.

Root Cause:
The error stemmed from the extension querying for the 'Raw' button immediately upon page load or soft-nav:end events. This often happened before GitHub's DOM was fully rendered, or in cases where the button might legitimately be absent (e.g., for certain file types or GitHub UI variations). The previous implementation would throw an error if the element was not found instantly.

Solution:

  1. waitForElement Utility: Introduced a new asynchronous utility function waitForElement in src/content/github/file/utils/waitForElement.ts. This utility uses a MutationObserver to efficiently wait for a specified DOM element to appear within a given timeout, resolving with the element or rejecting with a custom ElementNotFoundError.
  2. Graceful Element Retrieval: Replaced the synchronous document.querySelector calls with await waitForElement in createCoverageButton() (main.tsx) and createDropdown() (dropdown.tsx).
  3. Typed Error Handling: Created a custom ElementNotFoundError class to provide specific error identification.
  4. Error Suppression: Updated the try/catch block in main.tsx and added .catch() handlers to the createDropdown calls. These now specifically check for ElementNotFoundError and, if caught, log a message to the console and return early without reporting to Sentry. This prevents unnecessary error reports for expected scenarios where the 'Raw' button might not be present or takes longer to render.

Fixes BROWSER-EXTENSION-SA

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

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Bundle Report

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

Detailed changes
Bundle name Size Change
codecov-browser-extension-array-push 661.24kB 774 bytes (0.12%) ⬆️

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 685 bytes 12.15kB 5.98% ⚠️

Files in githubFile.js:

  • ./src/content/github/file/utils/dropdown.tsx → Total Size: 1.91kB

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

  • ./src/content/github/file/utils/waitForElement.ts → Total Size: 1.33kB

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