Skip to content

Fix: Make sure bindings work after page restored from bfcache#3205

Merged
kblok merged 1 commit into
masterfrom
implement-upstream-change-12663
Feb 23, 2026
Merged

Fix: Make sure bindings work after page restored from bfcache#3205
kblok merged 1 commit into
masterfrom
implement-upstream-change-12663

Conversation

@kblok

@kblok kblok commented Feb 23, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds a CDP binding prefix (puppeteer_) to all Runtime.addBinding and Runtime.removeBinding calls, matching upstream Puppeteer's approach
  • Updates the JavaScript addPageBinding function to use the prefix when calling the CDP binding, avoiding name collisions when pages are restored from the back-forward cache
  • Removes the Symbol.toStringTag check in favor of checking globalThis[name] to detect already-wrapped bindings
  • Adds a test verifying that ExposeFunctionAsync works correctly after navigating back to a BFCached page

Upstream PR

puppeteer/puppeteer#12663

Closes #2682

Changes

File Change
BindingUtils.cs Added CdpBindingPrefix constant; updated JS addPageBinding to accept prefix param and use globalThis[prefix + name]()
IsolatedWorld.cs Prepend CdpBindingPrefix to binding name in Runtime.addBinding call
CdpPage.cs Prepend CdpBindingPrefix to binding name in Runtime.addBinding and Runtime.removeBinding calls
BFCacheTests.cs Added test for calling exposed functions after bfcache restoration

Test plan

  • BFCache tests pass (3/3)
  • ExposeFunctionTests pass (13/13)
  • PageEvaluateTests pass
  • ARIA selector tests pass (10/10)

🤖 Generated with Claude Code

#2682)

Add a CDP binding prefix ("puppeteer_") to avoid conflicts when pages
are restored from the back-forward cache. The prefix ensures that the
CDP binding name differs from the user-visible function name, preventing
the browser from clobbering the Puppeteer wrapper when restoring pages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kblok kblok changed the title Fix: Make sure bindings work after page restored from bfcache (#12663) (#2682) Fix: Make sure bindings work after page restored from bfcache Feb 23, 2026
@kblok kblok merged commit 9ab07c0 into master Feb 23, 2026
14 checks passed
@kblok kblok deleted the implement-upstream-change-12663 branch February 23, 2026 22:43
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.

fix: make sure bindings are working after a page is restored from bfcache

1 participant