Skip to content

fix: stop prompting for bitcoin: protocol handler on every load#2369

Merged
im-adithya merged 3 commits into
masterfrom
fix/bitcoin-protocol-handler-prompt
May 25, 2026
Merged

fix: stop prompting for bitcoin: protocol handler on every load#2369
im-adithya merged 3 commits into
masterfrom
fix/bitcoin-protocol-handler-prompt

Conversation

@reneaaron
Copy link
Copy Markdown
Member

@reneaaron reneaaron commented May 21, 2026

Summary

  • The browser-native `registerProtocolHandler` prompt was reappearing on every page load, because browsers re-prompt every time `navigator.registerProtocolHandler` is called if the user dismissed (X'd) the previous prompt without explicitly accepting or denying.
  • Gate the call with `sessionStorage` so we ask at most once per browser session. Users who dismiss still get re-asked next session, and an explicit accept persists permanently in the browser as before.

Test plan

  • Load Hub in a fresh tab → see the bitcoin protocol handler bar once.
  • Dismiss it with X, reload the same tab → bar does NOT reappear.
  • Open Hub in a new tab → bar appears again.
  • Accept the prompt → bar never reappears (browser remembers permanently).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Prevented repeated browser protocol-registration prompts by ensuring the handler is registered only once per session, avoiding redundant dialogs on subsequent page loads.

Review Change Stack

Browsers re-show the registerProtocolHandler prompt every time it is
called if the user dismissed (X'd) the previous one without explicitly
accepting or denying. Gate the call with sessionStorage so we ask at
most once per browser session.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 190516eb-79b7-4f5a-a883-0b87817d1591

📥 Commits

Reviewing files that changed from the base of the PR and between 13f944a and 3bbfc33.

📒 Files selected for processing (1)
  • frontend/src/hooks/useRegisterProtocolHandler.ts

📝 Walkthrough

Walkthrough

The hook computes a handler URL and uses a module-level STORAGE_KEY to check sessionStorage before calling navigator.registerProtocolHandler("bitcoin", ...); if registration proceeds, it stores "true" in sessionStorage to avoid repeated prompts during the same session.

Changes

Session-aware protocol handler registration

Layer / File(s) Summary
Session storage guard for protocol handler registration
frontend/src/hooks/useRegisterProtocolHandler.ts
Adds a STORAGE_KEY constant and updates the useEffect to compute a normalized handler URL, early-return when sessionStorage.getItem(STORAGE_KEY) is present, call navigator.registerProtocolHandler inside the existing try/catch, and persist "true" to sessionStorage after successful registration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • getAlby/hub#2131: Introduces the protocol handler registration logic that this PR builds upon with session-aware deduplication.

Suggested reviewers

  • im-adithya

Poem

🐰 I stitched a tiny session key,

so browsers ask once, not endlessly.
A handler set, a single cheer—
quiet reloads throughout the year. 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: preventing repeated prompts for bitcoin protocol handler registration across page loads within a session.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bitcoin-protocol-handler-prompt

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@reneaaron reneaaron marked this pull request as ready for review May 21, 2026 20:25
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/hooks/useRegisterProtocolHandler.ts`:
- Around line 20-22: The hook useRegisterProtocolHandler currently calls
sessionStorage.getItem(STORAGE_KEY) outside the existing try/catch, which can
throw in restricted/private browsing; wrap the getItem access in the same
defensive logic as setItem (either pre-check window.sessionStorage existence or
move both getItem and setItem inside the try/catch) so both reads and writes are
protected, referencing STORAGE_KEY and the sessionStorage getItem/setItem calls
in useRegisterProtocolHandler.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6b4c2e7a-0195-4eb1-8388-576c2ee7057c

📥 Commits

Reviewing files that changed from the base of the PR and between 3a2f935 and 13f944a.

📒 Files selected for processing (1)
  • frontend/src/hooks/useRegisterProtocolHandler.ts

Comment thread frontend/src/hooks/useRegisterProtocolHandler.ts Outdated
reneaaron and others added 2 commits May 21, 2026 22:32
sessionStorage.getItem and setItem can throw in private browsing or
restricted storage modes. Move both inside the existing try/catch so an
exception doesn't break the hook.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
sessionStorage is tab-scoped and ephemeral, so comparing the stored
handler URL gains nothing over a plain truthy check.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@rolznz rolznz requested a review from im-adithya May 22, 2026 08:25
Copy link
Copy Markdown
Member

@im-adithya im-adithya left a comment

Choose a reason for hiding this comment

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

tACK

@im-adithya im-adithya merged commit e29fe81 into master May 25, 2026
12 checks passed
@im-adithya im-adithya deleted the fix/bitcoin-protocol-handler-prompt branch May 25, 2026 15:08
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.

2 participants