Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(dashboard): focus session when page.pickLocator is called (#40236)
Pavel Feldman5907571154d1
diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.mdindex e8099c2999..27ded1efe6 100644--- a/docs/src/api/class-browsercontext.md+++ b/docs/src/api/class-browsercontext.md@@ -68,11 +68,11 @@ await context.CloseAsync();This event is not emitted.-## event: BrowserContext.bringToFront+## event: BrowserContext.pickLocator* since: v1.60- argument: <[Page]>-Emitted when a client calls [`method: Page.bringToFront`] on a page in this context. The event is dispatched to all+Emitted when a client calls [`method: Page.pickLocator`] on a page in this context. The event is dispatched to allclients connected to the context, including the one that initiated the call.## property: BrowserContext.clockdiff --git a/packages/dashboard/src/dashboard.tsx b/packages/dashboard/src/dashboard.tsxindex 164c32af87..618410f784 100644--- a/packages/dashboard/src/dashboard.tsx+++ b/packages/dashboard/src/dashboard.tsx@@ -36,9 +36,20 @@ function tabFavicon(url: string): string {const BUTTONS = ['left', 'middle', 'right'] as const;-export const Dashboard: React.FC<{ browser: string }> = ({ browser }) => {+export const Dashboard: React.FC<{+ browser: string;+ autoInteractive?: boolean;+ onAutoInteractiveConsumed?: () => void;+}> = ({ browser, autoInteractive, onAutoInteractiveConsumed }) => {const client = React.useContext(DashboardClientContext);const [interactive, setInteractive] = React.useState(false);++ React.useEffect(() => {+ if (!autoInteractive)+ return;+ setInteractive(true);+ onAutoInteractiveConsumed?.();+ }, [autoInteractive, onAutoInteractiveConsumed]);const [tabs, setTabs] = React.useState<Tab[] | null>(null);const [url, setUrl] = React.useState('');const [frame, setFrame] = React.useState<DashboardChannelEvents['frame']>();diff --git a/packages/dashboard/src/dashboardChannel.ts b/packages/dashboard/src/dashboardChannel.tsindex 83d83918c1..30023a3169 100644--- a/packages/dashboard/src/dashboardChannel.ts+++ b/packages/dashboard/src/dashboardChannel.ts@@ -36,6 +36,7 @@ export type DashboardChannelEvents = {tabs: { target: ContextTarget; tabs: Tab[] };frame: { target: PageTarget; data: string; viewportWidth: number; viewportHeight: number };elementPicked: { target: PageTarget; selector: string };+ pickLocator: { target: PageTarget };};export type MouseButton = 'left' | 'middle' | 'right';diff --git a/packages/dashboard/src/index.tsx b/packages/dashboard/src/index.tsxindex 22c8cc020a..3b741e322e 100644--- a/packages/dashboard/src/index.tsx+++ b/packages/dashboard/src/index.tsx@@ -24,6 +24,7 @@ import { Grid } from './grid';import { SessionModel } from './sessionModel';import { DashboardClient } from './dashboardClient';+import type { DashboardChannelEvents } from './dashboardChannel';import type { DashboardClientChannel } from './dashboardClient';applyTheme();@@ -54,6 +55,7 @@ if (document.hidden)const App: React.FC = () => {const [, setRevision] = React.useState(0);const [sessionGuid, setSessionGuid] = React.useState<string | undefined>(parseHash);+ const [autoInteractiveBrowser, setAutoInteractiveBrowser] = React.useState<string | undefined>();React.useEffect(() => model.subscribe(() => setRevision(r => r + 1)), []);@@ -63,8 +65,22 @@ const App: React.FC = () => {return () => window.removeEventListener('popstate', onPopState);}, []);+ React.useEffect(() => {+ const onPickLocator = (params: DashboardChannelEvents['pickLocator']) => {+ setAutoInteractiveBrowser(params.target.browser);+ if (parseHash() !== params.target.browser)+ navigate('#session=' + encodeURIComponent(params.target.browser));+ };+ client.on('pickLocator', onPickLocator);+ return () => client.off('pickLocator', onPickLocator);+ }, []);+const content = sessionGuid- ? <Dashboard browser={sessionGuid} />+ ? <Dashboard+ browser={sessionGuid}+ autoInteractive={autoInteractiveBrowser === sessionGuid}+ onAutoInteractiveConsumed={() => setAutoInteractiveBrowser(undefined)}+ />: <Grid model={model} />;return <DashboardClientContext.Provider value={client}>{content}</DashboardClientContext.Provider>;diff --git a/packages/playwright-client/types/types.d.ts b/packages/playwright-client/types/types.d.tsindex e72e4392df..ccd3cd339c 100644--- a/packages/playwright-client/types/types.d.ts+++ b/packages/playwright-client/types/types.d.ts@@ -8225,13 +8225,6 @@ export interface BrowserContext {*/on(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Emitted when a client calls [page.bringToFront()](https://playwright.dev/docs/api/class-page#page-bring-to-front)- * on a page in this context. The event is dispatched to all clients connected to the context, including the one that- * initiated the call.- */- on(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Emitted when Browser context gets closed. This might happen because of one of the following:* - Browser context is closed.@@ -8312,6 +8305,13 @@ export interface BrowserContext {*/on(event: 'page', listener: (page: Page) => any): this;+ /**+ * Emitted when a client calls [page.pickLocator()](https://playwright.dev/docs/api/class-page#page-pick-locator) on a+ * page in this context. The event is dispatched to all clients connected to the context, including the one that+ * initiated the call.+ */+ on(event: 'picklocator', listener: (page: Page) => any): this;+/*** Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To* only listen for requests from a particular page, use@@ -8369,11 +8369,6 @@ export interface BrowserContext {*/once(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.- */- once(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.*/@@ -8394,6 +8389,11 @@ export interface BrowserContext {*/once(event: 'page', listener: (page: Page) => any): this;+ /**+ * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.+ */+ once(event: 'picklocator', listener: (page: Page) => any): this;+/*** Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.*/@@ -8429,13 +8429,6 @@ export interface BrowserContext {*/addListener(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Emitted when a client calls [page.bringToFront()](https://playwright.dev/docs/api/class-page#page-bring-to-front)- * on a page in this context. The event is dispatched to all clients connected to the context, including the one that- * initiated the call.- */- addListener(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Emitted when Browser context gets closed. This might happen because of one of the following:* - Browser context is closed.@@ -8516,6 +8509,13 @@ export interface BrowserContext {*/addListener(event: 'page', listener: (page: Page) => any): this;+ /**+ * Emitted when a client calls [page.pickLocator()](https://playwright.dev/docs/api/class-page#page-pick-locator) on a+ * page in this context. The event is dispatched to all clients connected to the context, including the one that+ * initiated the call.+ */+ addListener(event: 'picklocator', listener: (page: Page) => any): this;+/*** Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To* only listen for requests from a particular page, use@@ -8573,11 +8573,6 @@ export interface BrowserContext {*/removeListener(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Removes an event listener added by `on` or `addListener`.- */- removeListener(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Removes an event listener added by `on` or `addListener`.*/@@ -8598,6 +8593,11 @@ export interface BrowserContext {*/removeListener(event: 'page', listener: (page: Page) => any): this;+ /**+ * Removes an event listener added by `on` or `addListener`.+ */+ removeListener(event: 'picklocator', listener: (page: Page) => any): this;+/*** Removes an event listener added by `on` or `addListener`.*/@@ -8633,11 +8633,6 @@ export interface BrowserContext {*/off(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Removes an event listener added by `on` or `addListener`.- */- off(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Removes an event listener added by `on` or `addListener`.*/@@ -8658,6 +8653,11 @@ export interface BrowserContext {*/off(event: 'page', listener: (page: Page) => any): this;+ /**+ * Removes an event listener added by `on` or `addListener`.+ */+ off(event: 'picklocator', listener: (page: Page) => any): this;+/*** Removes an event listener added by `on` or `addListener`.*/@@ -8693,13 +8693,6 @@ export interface BrowserContext {*/prependListener(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Emitted when a client calls [page.bringToFront()](https://playwright.dev/docs/api/class-page#page-bring-to-front)- * on a page in this context. The event is dispatched to all clients connected to the context, including the one that- * initiated the call.- */- prependListener(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Emitted when Browser context gets closed. This might happen because of one of the following:* - Browser context is closed.@@ -8780,6 +8773,13 @@ export interface BrowserContext {*/prependListener(event: 'page', listener: (page: Page) => any): this;+ /**+ * Emitted when a client calls [page.pickLocator()](https://playwright.dev/docs/api/class-page#page-pick-locator) on a+ * page in this context. The event is dispatched to all clients connected to the context, including the one that+ * initiated the call.+ */+ prependListener(event: 'picklocator', listener: (page: Page) => any): this;+/*** Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To* only listen for requests from a particular page, use@@ -9489,13 +9489,6 @@ export interface BrowserContext {*/waitForEvent(event: 'backgroundpage', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;- /**- * Emitted when a client calls [page.bringToFront()](https://playwright.dev/docs/api/class-page#page-bring-to-front)- * on a page in this context. The event is dispatched to all clients connected to the context, including the one that- * initiated the call.- */- waitForEvent(event: 'bringtofront', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;-/*** Emitted when Browser context gets closed. This might happen because of one of the following:* - Browser context is closed.@@ -9576,6 +9569,13 @@ export interface BrowserContext {*/waitForEvent(event: 'page', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;+ /**+ * Emitted when a client calls [page.pickLocator()](https://playwright.dev/docs/api/class-page#page-pick-locator) on a+ * page in this context. The event is dispatched to all clients connected to the context, including the one that+ * initiated the call.+ */+ waitForEvent(event: 'picklocator', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;+/*** Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To* only listen for requests from a particular page, usediff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.tsindex 4ad2b16926..1f504a0352 100644--- a/packages/playwright-core/src/client/browserContext.ts+++ b/packages/playwright-core/src/client/browserContext.ts@@ -149,7 +149,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>dialog.dismiss().catch(() => {});}});- this._channel.on('bringToFront', ({ page }) => this.emit(Events.BrowserContext.BringToFront, Page.from(page)));+ this._channel.on('pickLocator', ({ page }) => this.emit(Events.BrowserContext.PickLocator, Page.from(page)));this._channel.on('request', ({ request, page }) => this._onRequest(network.Request.from(request), Page.fromNullable(page)));this._channel.on('requestFailed', ({ request, failureText, responseEndTiming, page }) => this._onRequestFailed(network.Request.from(request), responseEndTiming, failureText, Page.fromNullable(page)));this._channel.on('requestFinished', params => this._onRequestFinished(params));diff --git a/packages/playwright-core/src/client/events.ts b/packages/playwright-core/src/client/events.tsindex b5c4279c67..d8f77665c9 100644--- a/packages/playwright-core/src/client/events.ts+++ b/packages/playwright-core/src/client/events.ts@@ -39,7 +39,7 @@ export const Events = {},BrowserContext: {- BringToFront: 'bringtofront',+ PickLocator: 'picklocator',Console: 'console',Close: 'close',Dialog: 'dialog',diff --git a/packages/playwright-core/src/protocol/validator.ts b/packages/playwright-core/src/protocol/validator.tsindex ce574850eb..327276d4e4 100644--- a/packages/playwright-core/src/protocol/validator.ts+++ b/packages/playwright-core/src/protocol/validator.ts@@ -941,7 +941,7 @@ scheme.BrowserContextInitializer = tObject({scheme.BrowserContextBindingCallEvent = tObject({binding: tChannel(['BindingCall']),});-scheme.BrowserContextBringToFrontEvent = tObject({+scheme.BrowserContextPickLocatorEvent = tObject({page: tChannel(['Page']),});scheme.BrowserContextConsoleEvent = tObject({diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.tsindex f4d6d2f7c0..c00ee31fb0 100644--- a/packages/playwright-core/src/server/browserContext.ts+++ b/packages/playwright-core/src/server/browserContext.ts@@ -45,7 +45,7 @@ import type * as types from './types';import type * as channels from '@protocol/channels';const BrowserContextEvent = {- BringToFront: 'bringtofront',+ PickLocator: 'picklocator',Console: 'console',Close: 'close',Page: 'page',@@ -66,7 +66,7 @@ const BrowserContextEvent = {} as const;export type BrowserContextEventMap = {- [BrowserContextEvent.BringToFront]: [page: Page];+ [BrowserContextEvent.PickLocator]: [page: Page];[BrowserContextEvent.Console]: [message: ConsoleMessage];[BrowserContextEvent.Close]: [];[BrowserContextEvent.Page]: [page: Page];diff --git a/packages/playwright-core/src/server/dispatchers/browserContextDispatcher.ts b/packages/playwright-core/src/server/dispatchers/browserContextDispatcher.tsindex bba8e78ccf..23794c7c8a 100644--- a/packages/playwright-core/src/server/dispatchers/browserContextDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/browserContextDispatcher.ts@@ -105,8 +105,8 @@ export class BrowserContextDispatcher extends Dispatcher<BrowserContext, channelthis.addObjectListener(BrowserContext.Events.Page, page => {this._dispatchEvent('page', { page: PageDispatcher.from(this, page) });});- this.addObjectListener(BrowserContext.Events.BringToFront, page => {- this._dispatchEvent('bringToFront', { page: PageDispatcher.from(this, page) });+ this.addObjectListener(BrowserContext.Events.PickLocator, page => {+ this._dispatchEvent('pickLocator', { page: PageDispatcher.from(this, page) });});this.addObjectListener(BrowserContext.Events.Close, () => {this._dispatchEvent('close');diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.tsindex c074b91d50..257b657ba3 100644--- a/packages/playwright-core/src/server/page.ts+++ b/packages/playwright-core/src/server/page.ts@@ -648,7 +648,6 @@ export class Page extends SdkObject<PageEventMap> {async bringToFront(progress: Progress): Promise<void> {await progress.race(this.delegate.bringToFront());- this.emitOnContext(BrowserContext.Events.BringToFront, this);}async addInitScript(progress: Progress, source: string) {diff --git a/packages/playwright-core/src/server/recorder.ts b/packages/playwright-core/src/server/recorder.tsindex c0a8c6dd9c..ec4129ac2a 100644--- a/packages/playwright-core/src/server/recorder.ts+++ b/packages/playwright-core/src/server/recorder.ts@@ -274,6 +274,7 @@ export class Recorder extends EventEmitter<RecorderEventMap> implements Instrume}async pickLocator(progress: Progress, page: Page): Promise<string> {+ page.emitOnContext(BrowserContext.Events.PickLocator, page);if (this._mode !== 'none')await progress.race(this.setMode('none'));diff --git a/packages/playwright-core/src/tools/dashboard/dashboardController.ts b/packages/playwright-core/src/tools/dashboard/dashboardController.tsindex 570fef7a53..9817868ce5 100644--- a/packages/playwright-core/src/tools/dashboard/dashboardController.ts+++ b/packages/playwright-core/src/tools/dashboard/dashboardController.ts@@ -157,6 +157,12 @@ export class DashboardConnection implements Transport {});}+ emitPickLocator(att: AttachedBrowser, pageGuid: string) {+ this.sendEvent?.('pickLocator', {+ target: { browser: att.browserGuid, context: att.contextGuid, page: pageGuid },+ });+ }+private _pushSessions = () => {if (this._pushSessionsScheduled)return;@@ -205,6 +211,11 @@ class AttachedBrowser {if (!this._selectedPage)this._selectPage(page).catch(() => {});}),+ eventsHelper.addEventListener(this._context, 'picklocator', page => {+ this._selectPage(page)+ .then(() => this._owner.emitPickLocator(this, this._pageId(page)))+ .catch(() => {});+ }),);const pages = this._context.pages();if (pages.length > 0)diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.tsindex e72e4392df..ccd3cd339c 100644--- a/packages/playwright-core/types/types.d.ts+++ b/packages/playwright-core/types/types.d.ts@@ -8225,13 +8225,6 @@ export interface BrowserContext {*/on(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Emitted when a client calls [page.bringToFront()](https://playwright.dev/docs/api/class-page#page-bring-to-front)- * on a page in this context. The event is dispatched to all clients connected to the context, including the one that- * initiated the call.- */- on(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Emitted when Browser context gets closed. This might happen because of one of the following:* - Browser context is closed.@@ -8312,6 +8305,13 @@ export interface BrowserContext {*/on(event: 'page', listener: (page: Page) => any): this;+ /**+ * Emitted when a client calls [page.pickLocator()](https://playwright.dev/docs/api/class-page#page-pick-locator) on a+ * page in this context. The event is dispatched to all clients connected to the context, including the one that+ * initiated the call.+ */+ on(event: 'picklocator', listener: (page: Page) => any): this;+/*** Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To* only listen for requests from a particular page, use@@ -8369,11 +8369,6 @@ export interface BrowserContext {*/once(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.- */- once(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.*/@@ -8394,6 +8389,11 @@ export interface BrowserContext {*/once(event: 'page', listener: (page: Page) => any): this;+ /**+ * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.+ */+ once(event: 'picklocator', listener: (page: Page) => any): this;+/*** Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.*/@@ -8429,13 +8429,6 @@ export interface BrowserContext {*/addListener(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Emitted when a client calls [page.bringToFront()](https://playwright.dev/docs/api/class-page#page-bring-to-front)- * on a page in this context. The event is dispatched to all clients connected to the context, including the one that- * initiated the call.- */- addListener(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Emitted when Browser context gets closed. This might happen because of one of the following:* - Browser context is closed.@@ -8516,6 +8509,13 @@ export interface BrowserContext {*/addListener(event: 'page', listener: (page: Page) => any): this;+ /**+ * Emitted when a client calls [page.pickLocator()](https://playwright.dev/docs/api/class-page#page-pick-locator) on a+ * page in this context. The event is dispatched to all clients connected to the context, including the one that+ * initiated the call.+ */+ addListener(event: 'picklocator', listener: (page: Page) => any): this;+/*** Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To* only listen for requests from a particular page, use@@ -8573,11 +8573,6 @@ export interface BrowserContext {*/removeListener(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Removes an event listener added by `on` or `addListener`.- */- removeListener(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Removes an event listener added by `on` or `addListener`.*/@@ -8598,6 +8593,11 @@ export interface BrowserContext {*/removeListener(event: 'page', listener: (page: Page) => any): this;+ /**+ * Removes an event listener added by `on` or `addListener`.+ */+ removeListener(event: 'picklocator', listener: (page: Page) => any): this;+/*** Removes an event listener added by `on` or `addListener`.*/@@ -8633,11 +8633,6 @@ export interface BrowserContext {*/off(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Removes an event listener added by `on` or `addListener`.- */- off(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Removes an event listener added by `on` or `addListener`.*/@@ -8658,6 +8653,11 @@ export interface BrowserContext {*/off(event: 'page', listener: (page: Page) => any): this;+ /**+ * Removes an event listener added by `on` or `addListener`.+ */+ off(event: 'picklocator', listener: (page: Page) => any): this;+/*** Removes an event listener added by `on` or `addListener`.*/@@ -8693,13 +8693,6 @@ export interface BrowserContext {*/prependListener(event: 'backgroundpage', listener: (page: Page) => any): this;- /**- * Emitted when a client calls [page.bringToFront()](https://playwright.dev/docs/api/class-page#page-bring-to-front)- * on a page in this context. The event is dispatched to all clients connected to the context, including the one that- * initiated the call.- */- prependListener(event: 'bringtofront', listener: (page: Page) => any): this;-/*** Emitted when Browser context gets closed. This might happen because of one of the following:* - Browser context is closed.@@ -8780,6 +8773,13 @@ export interface BrowserContext {*/prependListener(event: 'page', listener: (page: Page) => any): this;+ /**+ * Emitted when a client calls [page.pickLocator()](https://playwright.dev/docs/api/class-page#page-pick-locator) on a+ * page in this context. The event is dispatched to all clients connected to the context, including the one that+ * initiated the call.+ */+ prependListener(event: 'picklocator', listener: (page: Page) => any): this;+/*** Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To* only listen for requests from a particular page, use@@ -9489,13 +9489,6 @@ export interface BrowserContext {*/waitForEvent(event: 'backgroundpage', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;- /**- * Emitted when a client calls [page.bringToFront()](https://playwright.dev/docs/api/class-page#page-bring-to-front)- * on a page in this context. The event is dispatched to all clients connected to the context, including the one that- * initiated the call.- */- waitForEvent(event: 'bringtofront', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;-/*** Emitted when Browser context gets closed. This might happen because of one of the following:* - Browser context is closed.@@ -9576,6 +9569,13 @@ export interface BrowserContext {*/waitForEvent(event: 'page', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;+ /**+ * Emitted when a client calls [page.pickLocator()](https://playwright.dev/docs/api/class-page#page-pick-locator) on a+ * page in this context. The event is dispatched to all clients connected to the context, including the one that+ * initiated the call.+ */+ waitForEvent(event: 'picklocator', optionsOrPredicate?: { predicate?: (page: Page) => boolean | Promise<boolean>, timeout?: number } | ((page: Page) => boolean | Promise<boolean>)): Promise<Page>;+/*** Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To* only listen for requests from a particular page, usediff --git a/packages/protocol/src/channels.d.ts b/packages/protocol/src/channels.d.tsindex a7ca57cf27..ca5f4eb0e8 100644--- a/packages/protocol/src/channels.d.ts+++ b/packages/protocol/src/channels.d.ts@@ -1647,7 +1647,7 @@ export type BrowserContextInitializer = {};export interface BrowserContextEventTarget {on(event: 'bindingCall', callback: (params: BrowserContextBindingCallEvent) => void): this;- on(event: 'bringToFront', callback: (params: BrowserContextBringToFrontEvent) => void): this;+ on(event: 'pickLocator', callback: (params: BrowserContextPickLocatorEvent) => void): this;on(event: 'console', callback: (params: BrowserContextConsoleEvent) => void): this;on(event: 'close', callback: (params: BrowserContextCloseEvent) => void): this;on(event: 'dialog', callback: (params: BrowserContextDialogEvent) => void): this;@@ -1701,7 +1701,7 @@ export interface BrowserContextChannel extends BrowserContextEventTarget, EventTexport type BrowserContextBindingCallEvent = {binding: BindingCallChannel,};-export type BrowserContextBringToFrontEvent = {+export type BrowserContextPickLocatorEvent = {page: PageChannel,};export type BrowserContextConsoleEvent = {@@ -2079,7 +2079,7 @@ export type BrowserContextClockSetSystemTimeResult = void;export interface BrowserContextEvents {'bindingCall': BrowserContextBindingCallEvent;- 'bringToFront': BrowserContextBringToFrontEvent;+ 'pickLocator': BrowserContextPickLocatorEvent;'console': BrowserContextConsoleEvent;'close': BrowserContextCloseEvent;'dialog': BrowserContextDialogEvent;diff --git a/packages/protocol/src/protocol.yml b/packages/protocol/src/protocol.ymlindex 2387fdd7cc..f639871f3a 100644--- a/packages/protocol/src/protocol.yml+++ b/packages/protocol/src/protocol.yml@@ -1516,7 +1516,7 @@ BrowserContext:parameters:binding: BindingCall- bringToFront:+ pickLocator:parameters:page: Pagediff --git a/tests/mcp/cli-devtools.spec.ts b/tests/mcp/cli-devtools.spec.tsindex 467b2a8bdc..98af761d8a 100644--- a/tests/mcp/cli-devtools.spec.ts+++ b/tests/mcp/cli-devtools.spec.ts@@ -181,6 +181,32 @@ test('pick', async ({ cdpServer, cli, server }) => {expect(output).toContain(`locator: getByRole('button', { name: 'Submit' })`);});+test('pick activates dashboard session', async ({ cdpServer, cli, server, openDashboard }) => {+ server.setContent('/', `<button>Submit</button>`, 'text/html');+ const browserContext = await cdpServer.start();+ const [page] = browserContext.pages();+ await page.goto(server.PREFIX);++ await cli('attach', `--cdp=${cdpServer.endpoint}`);+ await cli('snapshot');++ const dashboard = await openDashboard();+ await expect(dashboard.locator('.session-chip')).toHaveCount(1);++ const scriptReady = page.waitForEvent('console', msg => msg.text() === 'Recorder script ready for test');+ const pickPromise = cli('pick');+ await scriptReady;++ await expect(dashboard.locator('div.dashboard-view.interactive')).toBeVisible();++ const box = await page.getByRole('button', { name: 'Submit' }).boundingBox();+ await page.mouse.click(box!.x + box!.width / 2, box!.y + box!.height / 2);++ const { output } = await pickPromise;+ expect(output).toContain(`ref: e2`);+ expect(output).toContain(`locator: getByRole('button', { name: 'Submit' })`);+});+test('highlight', async ({ cdpServer, cli, server }) => {server.setContent('/', `<button>Submit</button>`, 'text/html');const browserContext = await cdpServer.start();