Skip to content

fix: strip selection URL fragment to prevent highlights disappearing in Firefox#91

Merged
cuspymd merged 2 commits intomainfrom
fix/firefox-selection-url-highlight
Apr 3, 2026
Merged

fix: strip selection URL fragment to prevent highlights disappearing in Firefox#91
cuspymd merged 2 commits intomainfrom
fix/firefox-selection-url-highlight

Conversation

@cuspymd
Copy link
Copy Markdown
Owner

@cuspymd cuspymd commented Apr 3, 2026

Summary

  • Fixes a Firefox-only bug where highlights appeared to disappear after clicking anywhere on pages that modify the URL on text selection (e.g., archive.is)
  • Strips the #selection-<N>.<N>-<N>.<N> fragment from window.location.href when initializing currentUrl so highlights are always stored under the canonical base URL

Root Cause

Firefox (MV3) re-injects content scripts whenever a page changes its URL via history.pushState. Sites like archive.is append a #selection-2049.0-2049.50 fragment to the URL on text selection. This caused Firefox to re-inject the content script with the selection URL, setting currentUrl to the transient selection URL instead of the base URL. Highlights were then saved under this transient key. When the selection was cleared and the URL reverted, the content script was re-injected again with the base URL and found no highlights — making them appear to vanish (they were still in storage, just under the wrong key).

Chrome is not affected because it does not re-inject content scripts on history.pushState.

Change

// Before
const currentUrl = window.location.href;

// After
const currentUrl = window.location.href.replace(/#selection-[\d.]+-[\d.]+$/, '');

The regex only strips the archive.is-specific #selection-NNN.N-NNN.N pattern, leaving all other hash fragments (e.g., SPA route hashes like #/page) untouched.

Test plan

  • Open Firefox, navigate to https://archive.is/isXfF
  • Select text and create a highlight
  • Click anywhere to clear the selection (URL reverts to base URL)
  • Verify the highlight remains visible on the page
  • Verify the highlight appears under the correct base URL in the Pages List view
  • Confirm Chrome behavior is unchanged

Closes #90

🤖 Generated with Claude Code

…at canonical URL

Firefox (MV3) re-injects content scripts when a page changes the URL via
history.pushState. Sites like archive.is append a #selection-NNN.N-NNN.N
fragment to the URL on text selection, causing Firefox to re-inject the
content script with the selection URL. Highlights were then saved under
this transient URL instead of the canonical base URL, making them appear
to disappear when the selection was cleared and the URL reverted.

Strip the #selection-... fragment from window.location.href before
assigning currentUrl so highlights are always stored and retrieved
under the stable base URL.

Closes #90

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd94ffc770

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…UrlChange

main added a navigation bridge that fires handleUrlChange on history.pushState
events. Without this fix, archive.is selection URL changes would also trigger
handleUrlChange with the #selection-... URL, causing highlights to be cleared
and reloaded from the wrong key.

Apply the same #selection-... normalization inside handleUrlChange so that
selection fragment URL changes are treated as no-op navigation events.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cuspymd
Copy link
Copy Markdown
Owner Author

cuspymd commented Apr 3, 2026

@codex review latest code

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cuspymd cuspymd merged commit ebc0698 into main Apr 3, 2026
2 checks passed
@cuspymd cuspymd deleted the fix/firefox-selection-url-highlight branch April 3, 2026 15:35
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.

Firefox: highlights saved under wrong URL when site modifies URL on text selection

1 participant