Repository navigation
fix(context): reuse the session of an attached target in attach_target - #668
Merged
Merged
Conversation
attach_target on a target with a session opened another one, which Ferrum handled like an auto-attach: workers were attached again, extensions ran once more per document and target.session_id moved away from the cached page. Return the target when it already has a session, and return the target instead of true. Clear the session id on Target.detachedFromTarget and when a service worker is let go, so detached targets can be attached again.
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.
Context#attach_targeton a target that already had a session opened another one. Chrome reported it throughTarget.attachedToTarget, so Ferrum treated it like an auto-attach: it re-armed auto-attach on the new session, which attached every worker again, registered the extensions again, so they ran once more per document, and overwrotetarget.session_idwhile the cachedPage/Workerstayed on the first session.Fix
attach_targetreturns the target as is when it already has a session, like Puppeteer'starget.page()/target.worker()reuse the session they have.Targetinstead oftrue, sobrowser.attach_target(id).workerworks. A target is truthy, so callers checking the result keep working.Target.detachedFromTarget, so a detached target kept a deadsession_idand the early return would have skipped the attach. The session id is now cleared onTarget.detachedFromTarget, and right away when Ferrum lets go of a service worker, soattach_targetright after the worker shows up doesn't pick the session that is about to be detached.Test
spec/context_spec.rb: attaching twice to a page with an extension returns the target, keeps its session and the extension runs once after a reload. Without the fix the session changes and the extension runs three times.spec/worker_spec.rb: a detached service worker target has no session id.