Skip to content

Commit 6b96b7f

Browse files
DavertMikclaude
andcommitted
fix: use WithinContext.endCurrent() in switchTo to properly clear context
Addresses review feedback from DenysKuchma. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 072200c commit 6b96b7f

3 files changed

Lines changed: 6 additions & 9 deletions

File tree

lib/helper/Playwright.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import MultipleElementsFound from './errors/MultipleElementsFound.js'
3535
import RemoteBrowserConnectionRefused from './errors/RemoteBrowserConnectionRefused.js'
3636
import Popup from './extras/Popup.js'
3737
import Console from './extras/Console.js'
38+
import { WithinContext } from '../step/within.js'
3839
import { findReact, findVue, findByPlaywrightLocator } from './extras/PlaywrightReactVueLocator.js'
3940
import { dropFile } from './scripts/dropFile.js'
4041
import WebElement from '../element/WebElement.js'
@@ -3609,9 +3610,7 @@ class Playwright extends Helper {
36093610
* {{> switchTo }}
36103611
*/
36113612
async switchTo(locator) {
3612-
if (this.withinLocator) {
3613-
await this._withinEnd()
3614-
}
3613+
WithinContext.endCurrent()
36153614

36163615
if (Number.isInteger(locator)) {
36173616
// Select by frame index of current context

lib/helper/Puppeteer.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { isColorProperty, convertColorToRGBA } from '../colorUtils.js'
3535
import ElementNotFound from './errors/ElementNotFound.js'
3636
import MultipleElementsFound from './errors/MultipleElementsFound.js'
3737
import RemoteBrowserConnectionRefused from './errors/RemoteBrowserConnectionRefused.js'
38+
import { WithinContext } from '../step/within.js'
3839
import Popup from './extras/Popup.js'
3940
import Console from './extras/Console.js'
4041
import { highlightElement } from './scripts/highlightElement.js'
@@ -2674,9 +2675,7 @@ class Puppeteer extends Helper {
26742675
* {{> switchTo }}
26752676
*/
26762677
async switchTo(locator) {
2677-
if (this.withinLocator) {
2678-
await this._withinEnd()
2679-
}
2678+
WithinContext.endCurrent()
26802679

26812680
if (Number.isInteger(locator)) {
26822681
// Select by frame index of current context

lib/helper/WebDriver.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { isColorProperty, convertColorToRGBA } from '../colorUtils.js'
3232
import ElementNotFound from './errors/ElementNotFound.js'
3333
import MultipleElementsFound from './errors/MultipleElementsFound.js'
3434
import ConnectionRefused from './errors/ConnectionRefused.js'
35+
import { WithinContext } from '../step/within.js'
3536
import Locator from '../locator.js'
3637
import { highlightElement } from './scripts/highlightElement.js'
3738
import { focusElement } from './scripts/focusElement.js'
@@ -2799,9 +2800,7 @@ class WebDriver extends Helper {
27992800
* {{> switchTo }}
28002801
*/
28012802
async switchTo(locator) {
2802-
if (this.withinLocator) {
2803-
await this._withinEnd()
2804-
}
2803+
WithinContext.endCurrent()
28052804

28062805
this.browser.isInsideFrame = true
28072806
if (!locator) {

0 commit comments

Comments
 (0)