Fix: Make sure bindings work after page restored from bfcache#3205
Merged
Conversation
#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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
puppeteer_) to allRuntime.addBindingandRuntime.removeBindingcalls, matching upstream Puppeteer's approachaddPageBindingfunction to use the prefix when calling the CDP binding, avoiding name collisions when pages are restored from the back-forward cacheSymbol.toStringTagcheck in favor of checkingglobalThis[name]to detect already-wrapped bindingsExposeFunctionAsyncworks correctly after navigating back to a BFCached pageUpstream PR
puppeteer/puppeteer#12663
Closes #2682
Changes
BindingUtils.csCdpBindingPrefixconstant; updated JSaddPageBindingto acceptprefixparam and useglobalThis[prefix + name]()IsolatedWorld.csCdpBindingPrefixto binding name inRuntime.addBindingcallCdpPage.csCdpBindingPrefixto binding name inRuntime.addBindingandRuntime.removeBindingcallsBFCacheTests.csTest plan
🤖 Generated with Claude Code