remove activate tab
This commit is contained in:
@@ -275,26 +275,6 @@ export class RelayConnection {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (message.method === 'activateTab') {
|
||||
const { targetId } = message.params;
|
||||
debugLog('Activating tab with targetId:', targetId);
|
||||
|
||||
for (const [tabId, tab] of this._attachedTabs) {
|
||||
if (tab.targetId === targetId) {
|
||||
debugLog('Found tab to activate:', tabId);
|
||||
await chrome.tabs.update(tabId, { active: true });
|
||||
// const chromeTab = await chrome.tabs.get(tabId);
|
||||
// if (chromeTab.windowId) {
|
||||
// await chrome.windows.update(chromeTab.windowId, { focused: true });
|
||||
// }
|
||||
return { success: true };
|
||||
}
|
||||
}
|
||||
|
||||
debugLog('Target not found:', targetId);
|
||||
throw new Error(`Target not found: ${targetId}`);
|
||||
}
|
||||
|
||||
if (message.method === 'forwardCDPCommand') {
|
||||
const { sessionId, method, params } = message.params;
|
||||
|
||||
|
||||
@@ -219,13 +219,6 @@ export async function startPlayWriterCDPRelayServer({ port = 19988, host = '127.
|
||||
params: { method, params }
|
||||
})
|
||||
}
|
||||
|
||||
case 'Playwriter.activateTab': {
|
||||
return await sendToExtension({
|
||||
method: 'activateTab',
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return await sendToExtension({
|
||||
|
||||
@@ -15,13 +15,6 @@ export type ExtensionCommandMessage =
|
||||
params?: any
|
||||
}
|
||||
}
|
||||
| {
|
||||
id: number
|
||||
method: 'activateTab'
|
||||
params: {
|
||||
targetId: string
|
||||
}
|
||||
}
|
||||
|
||||
export type ExtensionResponseMessage = {
|
||||
id: number
|
||||
|
||||
@@ -30,7 +30,6 @@ interface VMContext {
|
||||
debug: (...args: any[]) => void
|
||||
}
|
||||
accessibilitySnapshot: (page: Page) => Promise<string>
|
||||
activateTab: (page: Page) => Promise<void>
|
||||
resetPlaywright: () => Promise<{ page: Page; context: BrowserContext }>
|
||||
}
|
||||
|
||||
@@ -214,21 +213,12 @@ server.tool(
|
||||
throw new Error('accessibilitySnapshot is not available on this page')
|
||||
}
|
||||
|
||||
const activateTab = async (targetPage: Page) => {
|
||||
const cdp = await context.newCDPSession(targetPage)
|
||||
const { targetInfo } = await cdp.send('Target.getTargetInfo')
|
||||
const targetId = targetInfo.targetId
|
||||
await cdp.send('Playwriter.activateTab' as any, { targetId })
|
||||
await cdp.detach()
|
||||
}
|
||||
|
||||
let vmContextObj: VMContext = {
|
||||
page,
|
||||
context,
|
||||
state,
|
||||
console: customConsole,
|
||||
accessibilitySnapshot,
|
||||
activateTab,
|
||||
resetPlaywright: async () => {
|
||||
const { page: newPage, context: newContext } = await resetConnection()
|
||||
|
||||
@@ -240,7 +230,6 @@ server.tool(
|
||||
state,
|
||||
console: customConsole,
|
||||
accessibilitySnapshot,
|
||||
activateTab,
|
||||
resetPlaywright: vmContextObj.resetPlaywright
|
||||
}
|
||||
Object.keys(vmContextObj).forEach(key => delete (vmContextObj as any)[key])
|
||||
|
||||
@@ -29,9 +29,10 @@ always detach event listener you create at the end of a message using `page.remo
|
||||
you have access to some functions in addition to playwright methods:
|
||||
|
||||
- `async accessibilitySnapshot(page)`: gets a human readable snapshot of clickable elements on the page. useful to see the overall structure of the page and what elements you can interact with
|
||||
- `async activateTab(page)`: activates (brings to front and focuses) the browser tab for the given page
|
||||
- `async resetPlaywright()`: recreates the CDP connection and resets the browser/page/context. Use this when the MCP stops responding, you get connection errors, assertion failures, or timeout issues. After calling this, the page and context variables are automatically updated in the execution environment. IMPORTANT: this completely resets the execution context, removing any custom properties you may have added to the global scope AND clearing all keys from the `state` object. Only `page`, `context`, `state` (empty), `console`, and utility functions will remain
|
||||
|
||||
To bring a tab to front and focus it, use the standard Playwright method `await page.bringToFront()`
|
||||
|
||||
example:
|
||||
|
||||
```md
|
||||
|
||||
Reference in New Issue
Block a user