@midscene/web 0.16.5 → 0.16.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/agent.js +78 -14
- package/dist/es/agent.js.map +1 -1
- package/dist/es/bridge-mode-browser.js +3 -3
- package/dist/es/bridge-mode-browser.js.map +1 -1
- package/dist/es/bridge-mode.js +100 -21
- package/dist/es/bridge-mode.js.map +1 -1
- package/dist/es/chrome-extension.js +79 -15
- package/dist/es/chrome-extension.js.map +1 -1
- package/dist/es/index.js +110 -14
- package/dist/es/index.js.map +1 -1
- package/dist/es/midscene-playground.js +78 -14
- package/dist/es/midscene-playground.js.map +1 -1
- package/dist/es/playground.js +78 -14
- package/dist/es/playground.js.map +1 -1
- package/dist/es/playwright.js +110 -14
- package/dist/es/playwright.js.map +1 -1
- package/dist/es/puppeteer-agent-launcher.js +78 -14
- package/dist/es/puppeteer-agent-launcher.js.map +1 -1
- package/dist/es/puppeteer.js +78 -14
- package/dist/es/puppeteer.js.map +1 -1
- package/dist/es/ui-utils.js.map +1 -1
- package/dist/lib/agent.js +77 -10
- package/dist/lib/agent.js.map +1 -1
- package/dist/lib/bridge-mode-browser.js +3 -3
- package/dist/lib/bridge-mode-browser.js.map +1 -1
- package/dist/lib/bridge-mode.js +99 -18
- package/dist/lib/bridge-mode.js.map +1 -1
- package/dist/lib/chrome-extension.js +78 -11
- package/dist/lib/chrome-extension.js.map +1 -1
- package/dist/lib/index.js +109 -10
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene-playground.js +77 -10
- package/dist/lib/midscene-playground.js.map +1 -1
- package/dist/lib/playground.js +77 -10
- package/dist/lib/playground.js.map +1 -1
- package/dist/lib/playwright.js +109 -10
- package/dist/lib/playwright.js.map +1 -1
- package/dist/lib/puppeteer-agent-launcher.js +77 -10
- package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
- package/dist/lib/puppeteer.js +77 -10
- package/dist/lib/puppeteer.js.map +1 -1
- package/dist/lib/ui-utils.js.map +1 -1
- package/dist/types/agent.d.ts +8 -0
- package/dist/types/bridge-mode-browser.d.ts +1 -1
- package/dist/types/bridge-mode.d.ts +1 -2
- package/dist/types/{browser-0beaa7a7.d.ts → browser-a8afbca5.d.ts} +1 -2
- package/dist/types/playwright.d.ts +16 -0
- package/dist/types/ui-utils.d.ts +1 -1
- package/package.json +4 -3
|
@@ -291,7 +291,7 @@ function sleep(ms) {
|
|
|
291
291
|
var ChromeExtensionProxyPage = class {
|
|
292
292
|
constructor(forceSameTabNavigation) {
|
|
293
293
|
this.pageType = "chrome-extension-proxy";
|
|
294
|
-
this.version = "0.16.
|
|
294
|
+
this.version = "0.16.6";
|
|
295
295
|
this.activeTabId = null;
|
|
296
296
|
this.tabIdOfDebuggerAttached = null;
|
|
297
297
|
this.attachingDebugger = null;
|
|
@@ -737,7 +737,7 @@ var BridgeClient = class {
|
|
|
737
737
|
this.socket = (0, import_socket.io)(this.endpoint, {
|
|
738
738
|
reconnection: false,
|
|
739
739
|
query: {
|
|
740
|
-
version: "0.16.
|
|
740
|
+
version: "0.16.6"
|
|
741
741
|
}
|
|
742
742
|
});
|
|
743
743
|
const timeout = setTimeout(() => {
|
|
@@ -878,7 +878,7 @@ var ExtensionBridgePageBrowserSide = class extends ChromeExtensionProxyPage {
|
|
|
878
878
|
);
|
|
879
879
|
await this.bridgeClient.connect();
|
|
880
880
|
this.onLogMessage(
|
|
881
|
-
`Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v${"0.16.
|
|
881
|
+
`Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v${"0.16.6"}`,
|
|
882
882
|
"log"
|
|
883
883
|
);
|
|
884
884
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAAA,gBAAuB;;;ACqHh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AAS,GAAG;AACvE,WAAK,aAAa,+CAA+C,KAAK;AACtE,iBAAW,SAAS,KAAK,oBAAoB;AAC3C,cAAM,OAAO,KAAK,OAAO,KAAK;AAAA,MAChC;AACA,WAAK,qBAAqB,CAAC;AAAA,IAC7B;AAEA,UAAM,MAAM,QAAQ;AAEpB,QAAI,KAAK,cAAc;AACrB,WAAK,aAAa,WAAW;AAC7B,WAAK,eAAe;AACpB,WAAK,aAAa;AAAA,IACpB;AAAA,EACF;AACF","names":["import_utils","fs","error","ClientIO","e"],"ignoreList":[],"sources":["../../src/bridge-mode/browser.ts","../../src/bridge-mode/page-browser-side.ts","../../src/common/ui-utils.ts","../../src/chrome-extension/page.ts","../../src/chrome-extension/cdpInput.ts","../../src/chrome-extension/dynamic-scripts.ts","../../src/bridge-mode/common.ts","../../src/bridge-mode/io-client.ts"],"sourcesContent":["import { ExtensionBridgePageBrowserSide } from '../bridge-mode/page-browser-side';\n\nexport { ExtensionBridgePageBrowserSide };\n","import type {\n ChromePageDestroyOptions,\n KeyboardAction,\n MouseAction,\n} from '@/page';\nimport { assert } from '@midscene/shared/utils';\nimport ChromeExtensionProxyPage from '../chrome-extension/page';\nimport {\n type BridgeConnectTabOptions,\n BridgeEvent,\n DefaultBridgeServerPort,\n KeyboardEvent,\n MouseEvent,\n} from './common';\nimport { BridgeClient } from './io-client';\n\ndeclare const __VERSION__: string;\n\nexport class ExtensionBridgePageBrowserSide extends ChromeExtensionProxyPage {\n public bridgeClient: BridgeClient | null = null;\n\n private destroyOptions?: ChromePageDestroyOptions;\n\n private newlyCreatedTabIds: number[] = [];\n\n constructor(\n public onDisconnect: () => void = () => {},\n public onLogMessage: (\n message: string,\n type: 'log' | 'status',\n ) => void = () => {},\n forceSameTabNavigation = true,\n ) {\n super(forceSameTabNavigation);\n }\n\n private async setupBridgeClient() {\n this.bridgeClient = new BridgeClient(\n `ws://localhost:${DefaultBridgeServerPort}`,\n async (method, args: any[]) => {\n console.log('bridge call from cli side', method, args);\n if (method === BridgeEvent.ConnectNewTabWithUrl) {\n return this.connectNewTabWithUrl.apply(\n this,\n args as unknown as [string],\n );\n }\n\n if (method === BridgeEvent.GetBrowserTabList) {\n return this.getBrowserTabList.apply(this, args as any);\n }\n\n if (method === BridgeEvent.SetActiveTabId) {\n return this.setActiveTabId.apply(this, args as any);\n }\n\n if (method === BridgeEvent.ConnectCurrentTab) {\n return this.connectCurrentTab.apply(this, args as any);\n }\n\n if (method === BridgeEvent.UpdateAgentStatus) {\n return this.onLogMessage(args[0] as string, 'status');\n }\n\n const tabId = await this.getActiveTabId();\n if (!tabId || tabId === 0) {\n throw new Error('no tab is connected');\n }\n\n // this.onLogMessage(`calling method: ${method}`);\n\n if (method.startsWith(MouseEvent.PREFIX)) {\n const actionName = method.split('.')[1] as keyof MouseAction;\n if (actionName === 'drag') {\n return this.mouse[actionName].apply(this.mouse, args as any);\n }\n return this.mouse[actionName].apply(this.mouse, args as any);\n }\n\n if (method.startsWith(KeyboardEvent.PREFIX)) {\n const actionName = method.split('.')[1] as keyof KeyboardAction;\n if (actionName === 'press') {\n return this.keyboard[actionName].apply(this.keyboard, args as any);\n }\n return this.keyboard[actionName].apply(this.keyboard, args as any);\n }\n\n try {\n // @ts-expect-error\n const result = await this[method as keyof ChromeExtensionProxyPage](\n ...args,\n );\n return result;\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : 'Unknown error';\n console.error('error calling method', method, args, e);\n this.onLogMessage(\n `Error calling method: ${method}, ${errorMessage}`,\n 'log',\n );\n throw new Error(errorMessage, { cause: e });\n }\n },\n // on disconnect\n () => {\n return this.destroy();\n },\n );\n await this.bridgeClient.connect();\n this.onLogMessage(\n `Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v${__VERSION__}`,\n 'log',\n );\n }\n\n public async connect() {\n return await this.setupBridgeClient();\n }\n\n public async connectNewTabWithUrl(\n url: string,\n options: BridgeConnectTabOptions = {\n forceSameTabNavigation: true,\n },\n ) {\n const tab = await chrome.tabs.create({ url });\n const tabId = tab.id;\n assert(tabId, 'failed to get tabId after creating a new tab');\n\n // new tab\n this.onLogMessage(`Creating new tab: ${url}`, 'log');\n this.newlyCreatedTabIds.push(tabId);\n\n if (options?.forceSameTabNavigation) {\n this.forceSameTabNavigation = true;\n }\n\n await this.setActiveTabId(tabId);\n }\n\n public async connectCurrentTab(\n options: BridgeConnectTabOptions = {\n forceSameTabNavigation: true,\n },\n ) {\n const tabs = await chrome.tabs.query({ active: true, currentWindow: true });\n console.log('current tab', tabs);\n const tabId = tabs[0]?.id;\n assert(tabId, 'failed to get tabId');\n\n this.onLogMessage(`Connected to current tab: ${tabs[0]?.url}`, 'log');\n\n if (options?.forceSameTabNavigation) {\n this.forceSameTabNavigation = true;\n }\n\n await this.setActiveTabId(tabId);\n }\n\n public async setDestroyOptions(options: ChromePageDestroyOptions) {\n this.destroyOptions = options;\n }\n\n async destroy() {\n if (this.destroyOptions?.closeTab && this.newlyCreatedTabIds.length > 0) {\n this.onLogMessage('Closing all newly created tabs by bridge...', 'log');\n for (const tabId of this.newlyCreatedTabIds) {\n await chrome.tabs.remove(tabId);\n }\n this.newlyCreatedTabIds = [];\n }\n\n await super.destroy();\n\n if (this.bridgeClient) {\n this.bridgeClient.disconnect();\n this.bridgeClient = null;\n this.onDisconnect();\n }\n }\n}\n","import type {\n DetailedLocateParam,\n ExecutionTask,\n ExecutionTaskAction,\n ExecutionTaskInsightAssertion,\n ExecutionTaskInsightLocate,\n ExecutionTaskInsightQuery,\n ExecutionTaskPlanning,\n PlanningActionParamScroll,\n} from '@midscene/core';\n\nexport function typeStr(task: ExecutionTask) {\n return task.subType ? `${task.type} / ${task.subType || ''}` : task.type;\n}\n\nexport function getKeyCommands(\n value: string | string[],\n): Array<{ key: string; command?: string }> {\n // Ensure value is an array of keys\n const keys = Array.isArray(value) ? value : [value];\n\n // Process each key to attach a corresponding command if needed, based on the presence of 'Meta' or 'Control' in the keys array.\n // ref: https://github.com/puppeteer/puppeteer/pull/9357/files#diff-32cf475237b000f980eb214a0a823e45a902bddb7d2426d677cae96397aa0ae4R94\n return keys.reduce((acc: Array<{ key: string; command?: string }>, k) => {\n const includeMeta = keys.includes('Meta') || keys.includes('Control');\n if (includeMeta && (k === 'a' || k === 'A')) {\n return acc.concat([{ key: k, command: 'SelectAll' }]);\n }\n if (includeMeta && (k === 'c' || k === 'C')) {\n return acc.concat([{ key: k, command: 'Copy' }]);\n }\n if (includeMeta && (k === 'v' || k === 'V')) {\n return acc.concat([{ key: k, command: 'Paste' }]);\n }\n return acc.concat([{ key: k }]);\n }, []);\n}\n\nexport function locateParamStr(locate?: DetailedLocateParam) {\n if (!locate) {\n return '';\n }\n\n if (typeof locate === 'string') {\n return locate;\n }\n\n return locate.prompt;\n}\n\nexport function scrollParamStr(scrollParam?: PlanningActionParamScroll) {\n if (!scrollParam) {\n return '';\n }\n return `${scrollParam.direction || 'down'}, ${scrollParam.scrollType || 'once'}, ${scrollParam.distance || 'distance-not-set'}`;\n}\n\nexport function taskTitleStr(\n type:\n | 'Tap'\n | 'Hover'\n | 'Input'\n | 'KeyboardPress'\n | 'Scroll'\n | 'Action'\n | 'Query'\n | 'Assert'\n | 'WaitFor',\n prompt: string,\n) {\n if (prompt) {\n return `${type} - ${prompt}`;\n }\n return type;\n}\n\nexport function paramStr(task: ExecutionTask) {\n let value: string | undefined | object;\n if (task.type === 'Planning') {\n value = (task as ExecutionTaskPlanning)?.param?.userInstruction;\n }\n\n if (task.type === 'Insight') {\n value =\n (task as ExecutionTaskInsightLocate)?.param?.prompt ||\n (task as ExecutionTaskInsightLocate)?.param?.id ||\n (task as ExecutionTaskInsightQuery)?.param?.dataDemand ||\n (task as ExecutionTaskInsightAssertion)?.param?.assertion;\n }\n\n if (task.type === 'Action') {\n const locate = (task as ExecutionTaskAction)?.locate;\n const locateStr = locate ? locateParamStr(locate) : '';\n\n value = task.thought || '';\n if (typeof (task as ExecutionTaskAction)?.param?.timeMs === 'number') {\n value = `${(task as ExecutionTaskAction)?.param?.timeMs}ms`;\n } else if (\n typeof (task as ExecutionTaskAction)?.param?.scrollType === 'string'\n ) {\n value = scrollParamStr((task as ExecutionTaskAction)?.param);\n } else if (\n typeof (task as ExecutionTaskAction)?.param?.value !== 'undefined'\n ) {\n value = (task as ExecutionTaskAction)?.param?.value;\n }\n\n if (locateStr) {\n if (value) {\n value = `${locateStr} - ${value}`;\n } else {\n value = locateStr;\n }\n }\n }\n\n if (typeof value === 'undefined') return '';\n return typeof value === 'string'\n ? value\n : JSON.stringify(value, undefined, 2);\n}\n\nexport const limitOpenNewTabScript = `\nif (!window.__MIDSCENE_NEW_TAB_INTERCEPTOR_INITIALIZED__) {\n window.__MIDSCENE_NEW_TAB_INTERCEPTOR_INITIALIZED__ = true;\n\n // Intercept the window.open method (only once)\n window.open = function(url) {\n console.log('Blocked window.open:', url);\n window.location.href = url;\n return null;\n };\n\n // Block all a tag clicks with target=\"_blank\" (only once)\n document.addEventListener('click', function(e) {\n const target = e.target.closest('a');\n if (target && target.target === '_blank') {\n e.preventDefault();\n console.log('Blocked new tab:', target.href);\n window.location.href = target.href;\n target.removeAttribute('target');\n }\n }, true);\n}\n`;\n","/// <reference types=\"chrome\" />\n\n/*\n It is used to interact with the page tab from the chrome extension.\n The page must be active when interacting with it.\n*/\n\nimport type { WebKeyInput } from '@/common/page';\nimport { limitOpenNewTabScript } from '@/common/ui-utils';\nimport type { AbstractPage, ChromePageDestroyOptions } from '@/page';\nimport type { ElementTreeNode, Point, Size } from '@midscene/core';\nimport type { ElementInfo } from '@midscene/shared/extractor';\nimport { treeToList } from '@midscene/shared/extractor';\nimport { assert } from '@midscene/shared/utils';\nimport type { Protocol as CDPTypes } from 'devtools-protocol';\nimport { CdpKeyboard } from './cdpInput';\nimport {\n getHtmlElementScript,\n injectStopWaterFlowAnimation,\n injectWaterFlowAnimation,\n} from './dynamic-scripts';\n\nfunction sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\ndeclare const __VERSION__: string;\n\nexport default class ChromeExtensionProxyPage implements AbstractPage {\n pageType = 'chrome-extension-proxy';\n\n public forceSameTabNavigation: boolean;\n private version: string = __VERSION__;\n\n private viewportSize?: Size;\n\n private activeTabId: number | null = null;\n\n private tabIdOfDebuggerAttached: number | null = null;\n\n private attachingDebugger: Promise<void> | null = null;\n\n private destroyed = false;\n\n constructor(forceSameTabNavigation: boolean) {\n this.forceSameTabNavigation = forceSameTabNavigation;\n }\n\n public async setActiveTabId(tabId: number) {\n if (this.activeTabId) {\n throw new Error(\n `Active tab id is already set, which is ${this.activeTabId}, cannot set it to ${tabId}`,\n );\n }\n await chrome.tabs.update(tabId, { active: true });\n this.activeTabId = tabId;\n }\n\n public async getActiveTabId() {\n return this.activeTabId;\n }\n\n /**\n * Get a list of current tabs\n * @returns {Promise<Array<{id: number, title: string, url: string}>>}\n */\n public async getBrowserTabList(): Promise<\n { id: string; title: string; url: string; currentActiveTab: boolean }[]\n > {\n const tabs = await chrome.tabs.query({ currentWindow: true });\n return tabs\n .map((tab) => ({\n id: `${tab.id}`,\n title: tab.title,\n url: tab.url,\n currentActiveTab: tab.active,\n }))\n .filter((tab) => tab.id && tab.title && tab.url) as {\n id: string;\n title: string;\n url: string;\n currentActiveTab: boolean;\n }[];\n }\n\n public async getTabIdOrConnectToCurrentTab() {\n if (this.activeTabId) {\n // alway keep on the connected tab\n return this.activeTabId;\n }\n const tabId = await chrome.tabs\n .query({ active: true, currentWindow: true })\n .then((tabs) => tabs[0]?.id);\n this.activeTabId = tabId || 0;\n return this.activeTabId;\n }\n\n private async attachDebugger() {\n assert(!this.destroyed, 'Page is destroyed');\n\n // If already attaching, wait for it to complete\n if (this.attachingDebugger) {\n await this.attachingDebugger;\n return;\n }\n\n // Create new attaching promise\n this.attachingDebugger = (async () => {\n const url = await this.url();\n let error: Error | null = null;\n if (url.startsWith('chrome://')) {\n throw new Error(\n 'Cannot attach debugger to chrome:// pages, please use Midscene in a normal page with http://, https:// or file://',\n );\n }\n\n try {\n const currentTabId = await this.getTabIdOrConnectToCurrentTab();\n\n if (this.tabIdOfDebuggerAttached === currentTabId) {\n // already attached\n return;\n }\n if (\n this.tabIdOfDebuggerAttached &&\n this.tabIdOfDebuggerAttached !== currentTabId\n ) {\n // detach the previous tab\n console.log(\n 'detach the previous tab',\n this.tabIdOfDebuggerAttached,\n '->',\n currentTabId,\n );\n try {\n await this.detachDebugger(this.tabIdOfDebuggerAttached);\n } catch (error) {\n console.error('Failed to detach debugger', error);\n }\n }\n\n // detach any debugger attached to the tab\n console.log('attaching debugger', currentTabId);\n await chrome.debugger.attach({ tabId: currentTabId }, '1.3');\n // wait util the debugger banner in Chrome appears\n await sleep(500);\n\n this.tabIdOfDebuggerAttached = currentTabId;\n\n await this.enableWaterFlowAnimation();\n } catch (e) {\n console.error('Failed to attach debugger', e);\n error = e as Error;\n } finally {\n this.attachingDebugger = null;\n }\n if (error) {\n throw error;\n }\n })();\n\n await this.attachingDebugger;\n }\n\n private async showMousePointer(x: number, y: number) {\n // update mouse pointer while redirecting\n const pointerScript = `(() => {\n if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {\n window.midsceneWaterFlowAnimation.enable();\n window.midsceneWaterFlowAnimation.showMousePointer(${x}, ${y});\n } else {\n console.log('midsceneWaterFlowAnimation is not defined');\n }\n })()`;\n\n await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `${pointerScript}`,\n });\n }\n\n private async hideMousePointer() {\n await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `(() => {\n if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {\n window.midsceneWaterFlowAnimation.hideMousePointer();\n }\n })()`,\n });\n }\n\n private async detachDebugger(tabId?: number) {\n const tabIdToDetach = tabId || this.tabIdOfDebuggerAttached;\n console.log('detaching debugger', tabIdToDetach);\n if (!tabIdToDetach) {\n console.warn('No tab id to detach');\n return;\n }\n\n try {\n await this.disableWaterFlowAnimation(tabIdToDetach);\n await sleep(200); // wait for the animation to stop\n } catch (error) {\n console.warn('Failed to disable water flow animation', error);\n }\n\n try {\n await chrome.debugger.detach({ tabId: tabIdToDetach });\n } catch (error) {\n // maybe tab is closed ?\n console.warn('Failed to detach debugger', error);\n }\n this.tabIdOfDebuggerAttached = null;\n }\n\n private async enableWaterFlowAnimation() {\n // limit open page in new tab\n if (this.forceSameTabNavigation) {\n await chrome.debugger.sendCommand(\n { tabId: this.tabIdOfDebuggerAttached! },\n 'Runtime.evaluate',\n {\n expression: limitOpenNewTabScript,\n },\n );\n }\n\n const script = await injectWaterFlowAnimation();\n // we will call this function in sendCommandToDebugger, so we have to use the chrome.debugger.sendCommand\n await chrome.debugger.sendCommand(\n { tabId: this.tabIdOfDebuggerAttached! },\n 'Runtime.evaluate',\n {\n expression: script,\n },\n );\n }\n\n private async disableWaterFlowAnimation(tabId: number) {\n const script = await injectStopWaterFlowAnimation();\n\n await chrome.debugger.sendCommand({ tabId }, 'Runtime.evaluate', {\n expression: script,\n });\n }\n\n private async sendCommandToDebugger<ResponseType = any, RequestType = any>(\n command: string,\n params: RequestType,\n ): Promise<ResponseType> {\n await this.attachDebugger();\n\n assert(this.tabIdOfDebuggerAttached, 'Debugger is not attached');\n\n // wo don't have to await it\n this.enableWaterFlowAnimation();\n return (await chrome.debugger.sendCommand(\n { tabId: this.tabIdOfDebuggerAttached! },\n command,\n params as any,\n )) as ResponseType;\n }\n\n private async getPageContentByCDP() {\n const script = await getHtmlElementScript();\n\n // check tab url\n await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: script,\n });\n\n const expression = () => {\n return {\n tree: (window as any).midscene_element_inspector.webExtractNodeTree(),\n size: {\n width: document.documentElement.clientWidth,\n height: document.documentElement.clientHeight,\n dpr: window.devicePixelRatio,\n },\n };\n };\n const returnValue = await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: `(${expression.toString()})()`,\n returnByValue: true,\n });\n\n if (!returnValue.result.value) {\n const errorDescription =\n returnValue.exceptionDetails?.exception?.description || '';\n if (!errorDescription) {\n console.error('returnValue from cdp', returnValue);\n }\n throw new Error(\n `Failed to get page content from page, error: ${errorDescription}`,\n );\n }\n // console.log('returnValue', returnValue.result.value);\n return returnValue.result.value as {\n tree: ElementTreeNode<ElementInfo>;\n size: Size;\n };\n }\n\n public async evaluateJavaScript(script: string) {\n return this.sendCommandToDebugger('Runtime.evaluate', {\n expression: script,\n });\n }\n\n // current implementation is wait until domReadyState is complete\n public async waitUntilNetworkIdle() {\n const timeout = 10000;\n const startTime = Date.now();\n let lastReadyState = '';\n while (Date.now() - startTime < timeout) {\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: 'document.readyState',\n });\n lastReadyState = result.result.value;\n if (lastReadyState === 'complete') {\n await new Promise((resolve) => setTimeout(resolve, 300));\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, 300));\n }\n throw new Error(\n `Failed to wait until network idle, last readyState: ${lastReadyState}`,\n );\n }\n\n async getElementsInfo() {\n const tree = await this.getElementsNodeTree();\n return treeToList(tree);\n }\n\n async getElementsNodeTree() {\n await this.hideMousePointer();\n const content = await this.getPageContentByCDP();\n if (content?.size) {\n this.viewportSize = content.size;\n }\n\n return content?.tree || { node: null, children: [] };\n }\n\n async size() {\n if (this.viewportSize) return this.viewportSize;\n const content = await this.getPageContentByCDP();\n return content.size;\n }\n\n async screenshotBase64() {\n // screenshot by cdp\n await this.hideMousePointer();\n const base64 = await this.sendCommandToDebugger('Page.captureScreenshot', {\n format: 'jpeg',\n quality: 90,\n });\n return `data:image/jpeg;base64,${base64.data}`;\n }\n\n async url() {\n const tabId = await this.getTabIdOrConnectToCurrentTab();\n const url = await chrome.tabs.get(tabId).then((tab) => tab.url);\n return url || '';\n }\n\n async scrollUntilTop(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(0, -9999999);\n }\n\n async scrollUntilBottom(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(0, 9999999);\n }\n\n async scrollUntilLeft(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(-9999999, 0);\n }\n\n async scrollUntilRight(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(9999999, 0);\n }\n\n async scrollUp(distance?: number, startingPoint?: Point) {\n const { height } = await this.size();\n const scrollDistance = distance || height * 0.7;\n return this.mouse.wheel(\n 0,\n -scrollDistance,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollDown(distance?: number, startingPoint?: Point) {\n const { height } = await this.size();\n const scrollDistance = distance || height * 0.7;\n return this.mouse.wheel(\n 0,\n scrollDistance,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollLeft(distance?: number, startingPoint?: Point) {\n const { width } = await this.size();\n const scrollDistance = distance || width * 0.7;\n return this.mouse.wheel(\n -scrollDistance,\n 0,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollRight(distance?: number, startingPoint?: Point) {\n const { width } = await this.size();\n const scrollDistance = distance || width * 0.7;\n return this.mouse.wheel(\n scrollDistance,\n 0,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async clearInput(element: ElementInfo) {\n if (!element) {\n console.warn('No element to clear input');\n return;\n }\n\n await this.mouse.click(element.center[0], element.center[1]);\n\n await this.sendCommandToDebugger('Input.dispatchKeyEvent', {\n type: 'keyDown',\n commands: ['selectAll'],\n });\n\n await this.sendCommandToDebugger('Input.dispatchKeyEvent', {\n type: 'keyUp',\n commands: ['selectAll'],\n });\n\n await sleep(100);\n\n await this.keyboard.press({\n key: 'Backspace',\n });\n }\n\n private latestMouseX = 100;\n private latestMouseY = 100;\n\n mouse = {\n click: async (x: number, y: number) => {\n await this.mouse.move(x, y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x,\n y,\n button: 'left',\n clickCount: 1,\n });\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x,\n y,\n button: 'left',\n clickCount: 1,\n });\n },\n wheel: async (\n deltaX: number,\n deltaY: number,\n startX?: number,\n startY?: number,\n ) => {\n const finalX = startX || this.latestMouseX;\n const finalY = startY || this.latestMouseY;\n await this.showMousePointer(finalX, finalY);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseWheel',\n x: finalX,\n y: finalY,\n deltaX,\n deltaY,\n });\n this.latestMouseX = finalX;\n this.latestMouseY = finalY;\n },\n move: async (x: number, y: number) => {\n await this.showMousePointer(x, y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseMoved',\n x,\n y,\n });\n this.latestMouseX = x;\n this.latestMouseY = y;\n },\n drag: async (\n from: { x: number; y: number },\n to: { x: number; y: number },\n ) => {\n await this.mouse.move(from.x, from.y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x: from.x,\n y: from.y,\n button: 'left',\n clickCount: 1,\n });\n await this.mouse.move(to.x, to.y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x: to.x,\n y: to.y,\n button: 'left',\n clickCount: 1,\n });\n },\n };\n\n keyboard = {\n type: async (text: string) => {\n const cdpKeyboard = new CdpKeyboard({\n send: this.sendCommandToDebugger.bind(this),\n });\n await cdpKeyboard.type(text, { delay: 0 });\n },\n press: async (\n action:\n | { key: WebKeyInput; command?: string }\n | { key: WebKeyInput; command?: string }[],\n ) => {\n const cdpKeyboard = new CdpKeyboard({\n send: this.sendCommandToDebugger.bind(this),\n });\n const keys = Array.isArray(action) ? action : [action];\n for (const k of keys) {\n const commands = k.command ? [k.command] : [];\n await cdpKeyboard.down(k.key, { commands });\n }\n for (const k of [...keys].reverse()) {\n await cdpKeyboard.up(k.key);\n }\n },\n };\n\n async destroy(): Promise<void> {\n this.activeTabId = null;\n await this.detachDebugger();\n this.destroyed = true;\n }\n}\n","// From https://github.com/puppeteer/puppeteer/blob/15abcc390862fd08cc3475532f2d9a11284aee6b/packages/puppeteer-core/src/cdp/Input.ts#L55\n// with some modifications to fit the session type\n/**\n * @license\n * Copyright 2017 Google Inc.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type KeyDefinition,\n type KeyInput,\n _keyDefinitions,\n} from '@midscene/shared/keyboard-layout';\nimport { assert } from '@midscene/shared/utils';\n\ntype KeyDescription = Required<\n Pick<KeyDefinition, 'keyCode' | 'key' | 'text' | 'code' | 'location'>\n>;\n\n/**\n * @public\n */\nexport interface KeyDownOptions {\n /**\n * @deprecated Do not use. This is automatically handled.\n */\n text?: string;\n /**\n * @deprecated Do not use. This is automatically handled.\n */\n commands?: string[];\n}\n\n/**\n * @public\n */\nexport interface KeyboardTypeOptions {\n delay?: number;\n}\n\n/**\n * @public\n */\nexport type KeyPressOptions = KeyDownOptions & KeyboardTypeOptions;\n\ntype InternalCDPSession = {\n send: (command: string, params: any) => Promise<void>;\n};\n\n/**\n * @internal\n */\nexport class CdpKeyboard {\n #pressedKeys = new Set<string>();\n\n #client: InternalCDPSession;\n\n _modifiers = 0;\n\n constructor(client: InternalCDPSession) {\n this.#client = client;\n }\n\n updateClient(client: InternalCDPSession): void {\n this.#client = client;\n }\n\n async down(\n key: KeyInput,\n options: Readonly<KeyDownOptions> = {\n text: undefined,\n commands: [],\n },\n ): Promise<void> {\n const description = this.#keyDescriptionForString(key);\n\n const autoRepeat = this.#pressedKeys.has(description.code);\n this.#pressedKeys.add(description.code);\n this._modifiers |= this.#modifierBit(description.key);\n\n const text = options.text === undefined ? description.text : options.text;\n await this.#client.send('Input.dispatchKeyEvent', {\n type: text ? 'keyDown' : 'rawKeyDown',\n modifiers: this._modifiers,\n windowsVirtualKeyCode: description.keyCode,\n code: description.code,\n key: description.key,\n text: text,\n unmodifiedText: text,\n autoRepeat,\n location: description.location,\n isKeypad: description.location === 3,\n commands: options.commands,\n });\n }\n\n #modifierBit(key: string): number {\n if (key === 'Alt') {\n return 1;\n }\n if (key === 'Control') {\n return 2;\n }\n if (key === 'Meta') {\n return 4;\n }\n if (key === 'Shift') {\n return 8;\n }\n return 0;\n }\n\n #keyDescriptionForString(keyString: KeyInput): KeyDescription {\n const shift = this._modifiers & 8;\n const description = {\n key: '',\n keyCode: 0,\n code: '',\n text: '',\n location: 0,\n };\n\n const definition = _keyDefinitions[keyString];\n\n assert(definition, `Unknown key: \"${keyString}\"`);\n\n if (definition.key) {\n description.key = definition.key;\n }\n if (shift && definition.shiftKey) {\n description.key = definition.shiftKey;\n }\n\n if (definition.keyCode) {\n description.keyCode = definition.keyCode;\n }\n if (shift && definition.shiftKeyCode) {\n description.keyCode = definition.shiftKeyCode;\n }\n\n if (definition.code) {\n description.code = definition.code;\n }\n\n if (definition.location) {\n description.location = definition.location;\n }\n\n if (description.key.length === 1) {\n description.text = description.key;\n }\n\n if (definition.text) {\n description.text = definition.text;\n }\n if (shift && definition.shiftText) {\n description.text = definition.shiftText;\n }\n\n // if any modifiers besides shift are pressed, no text should be sent\n if (this._modifiers & ~8) {\n description.text = '';\n }\n\n return description;\n }\n\n async up(key: KeyInput): Promise<void> {\n const description = this.#keyDescriptionForString(key);\n\n this._modifiers &= ~this.#modifierBit(description.key);\n this.#pressedKeys.delete(description.code);\n await this.#client.send('Input.dispatchKeyEvent', {\n type: 'keyUp',\n modifiers: this._modifiers,\n key: description.key,\n windowsVirtualKeyCode: description.keyCode,\n code: description.code,\n location: description.location,\n });\n }\n\n async sendCharacter(char: string): Promise<void> {\n await this.#client.send('Input.insertText', { text: char });\n }\n\n private charIsKey(char: string): char is KeyInput {\n return !!_keyDefinitions[char as KeyInput];\n }\n\n async type(\n text: string,\n options: Readonly<KeyboardTypeOptions> = {},\n ): Promise<void> {\n const delay = options.delay || undefined;\n for (const char of text) {\n if (this.charIsKey(char)) {\n await this.press(char, { delay });\n } else {\n if (delay) {\n await new Promise((f) => {\n return setTimeout(f, delay);\n });\n }\n await this.sendCharacter(char);\n }\n }\n }\n\n async press(\n key: KeyInput | KeyInput[],\n options: Readonly<KeyPressOptions> = {},\n ): Promise<void> {\n const { delay = null } = options;\n const keys = Array.isArray(key) ? key : [key];\n\n for (const k of keys) {\n await this.down(k, options);\n }\n\n if (delay) {\n await new Promise((f) => {\n return setTimeout(f, options.delay);\n });\n }\n\n for (const k of [...keys].reverse()) {\n await this.up(k);\n }\n }\n}\n","import fs from 'node:fs';\nimport { ifInBrowser } from '@midscene/shared/utils';\n\n// remember to include this file into extension's package\n// extract html element from page\nlet scriptFileContentCache: string | null = null;\nexport const getHtmlElementScript = async () => {\n const scriptFileToRetrieve = chrome.runtime.getURL('scripts/htmlElement.js');\n if (scriptFileContentCache) return scriptFileContentCache;\n if (ifInBrowser) {\n const script = await fetch(scriptFileToRetrieve);\n scriptFileContentCache = await script.text();\n return scriptFileContentCache;\n }\n return fs.readFileSync(scriptFileToRetrieve, 'utf8');\n};\n\n// inject water flow animation\nlet waterFlowScriptFileContentCache: string | null = null;\nexport const injectWaterFlowAnimation = async () => {\n const waterFlowScriptFileToRetrieve = chrome.runtime.getURL(\n 'scripts/water-flow.js',\n );\n if (waterFlowScriptFileContentCache) return waterFlowScriptFileContentCache;\n if (ifInBrowser) {\n const script = await fetch(waterFlowScriptFileToRetrieve);\n waterFlowScriptFileContentCache = await script.text();\n return waterFlowScriptFileContentCache;\n }\n return fs.readFileSync(waterFlowScriptFileToRetrieve, 'utf8');\n};\n\n// inject stop water flow animation\nlet stopWaterFlowScriptFileContentCache: string | null = null;\nexport const injectStopWaterFlowAnimation = async () => {\n const stopWaterFlowScriptFileToRetrieve = chrome.runtime.getURL(\n 'scripts/stop-water-flow.js',\n );\n if (stopWaterFlowScriptFileContentCache)\n return stopWaterFlowScriptFileContentCache;\n if (ifInBrowser) {\n const script = await fetch(stopWaterFlowScriptFileToRetrieve);\n stopWaterFlowScriptFileContentCache = await script.text();\n return stopWaterFlowScriptFileContentCache;\n }\n return fs.readFileSync(stopWaterFlowScriptFileToRetrieve, 'utf8');\n};\n","export const DefaultBridgeServerPort = 3766;\nexport const DefaultLocalEndpoint = `http://127.0.0.1:${DefaultBridgeServerPort}`;\nexport const BridgeCallTimeout = 30000;\n\nexport enum BridgeEvent {\n Call = 'bridge-call',\n CallResponse = 'bridge-call-response',\n UpdateAgentStatus = 'bridge-update-agent-status',\n Message = 'bridge-message',\n Connected = 'bridge-connected',\n Refused = 'bridge-refused',\n ConnectNewTabWithUrl = 'connectNewTabWithUrl',\n ConnectCurrentTab = 'connectCurrentTab',\n GetBrowserTabList = 'getBrowserTabList',\n SetDestroyOptions = 'setDestroyOptions',\n SetActiveTabId = 'setActiveTabId',\n}\n\nexport interface BridgeConnectTabOptions {\n /**\n * If true, the page will always track the active tab.\n * @default true\n */\n forceSameTabNavigation?: boolean;\n}\n\nexport enum MouseEvent {\n PREFIX = 'mouse.',\n Click = 'mouse.click',\n Wheel = 'mouse.wheel',\n Move = 'mouse.move',\n Drag = 'mouse.drag',\n}\n\nexport enum KeyboardEvent {\n PREFIX = 'keyboard.',\n Type = 'keyboard.type',\n Press = 'keyboard.press',\n}\n\nexport const BridgePageType = 'page-over-chrome-extension-bridge';\n\nexport const BridgeErrorCodeNoClientConnected = 'no-client-connected';\n\nexport interface BridgeCall {\n method: string;\n args: any[];\n response: any;\n callTime: number;\n responseTime: number;\n callback: (error: Error | undefined, response: any) => void;\n error?: Error;\n}\n\nexport interface BridgeCallRequest {\n id: string;\n method: string;\n args: any[];\n}\n\nexport interface BridgeCallResponse {\n id: string;\n response: any;\n error?: any;\n}\n\nexport interface BridgeConnectedEventPayload {\n version: string;\n}\n","import { assert } from '@midscene/shared/utils';\nimport { io as ClientIO, type Socket as ClientSocket } from 'socket.io-client';\nimport {\n type BridgeCallRequest,\n type BridgeCallResponse,\n type BridgeConnectedEventPayload,\n BridgeEvent,\n} from './common';\n\ndeclare const __VERSION__: string;\n\n// ws client, this is where the request is processed\nexport class BridgeClient {\n private socket: ClientSocket | null = null;\n public serverVersion: string | null = null;\n constructor(\n public endpoint: string,\n public onBridgeCall: (method: string, args: any[]) => Promise<any>,\n public onDisconnect?: () => void,\n ) {}\n\n async connect() {\n return new Promise((resolve, reject) => {\n this.socket = ClientIO(this.endpoint, {\n reconnection: false,\n query: {\n version: __VERSION__,\n },\n });\n\n const timeout = setTimeout(() => {\n try {\n this.socket?.offAny();\n this.socket?.close();\n } catch (e) {\n console.warn('got error when offing socket', e);\n }\n this.socket = null;\n reject(new Error('failed to connect to bridge server after timeout'));\n }, 1 * 1000);\n\n // on disconnect\n this.socket.on('disconnect', (reason: string) => {\n // console.log('bridge-disconnected, reason:', reason);\n this.socket = null;\n this.onDisconnect?.();\n });\n\n this.socket.on('connect_error', (e: any) => {\n console.error('bridge-connect-error', e);\n reject(new Error(e || 'bridge connect error'));\n });\n\n this.socket.on(\n BridgeEvent.Connected,\n (payload: BridgeConnectedEventPayload) => {\n clearTimeout(timeout);\n this.serverVersion = payload?.version || 'unknown';\n resolve(this.socket);\n },\n );\n this.socket.on(BridgeEvent.Refused, (e: any) => {\n console.error('bridge-refused', e);\n try {\n this.socket?.disconnect();\n } catch (e) {\n // console.warn('got error when disconnecting socket', e);\n }\n reject(new Error(e || 'bridge refused'));\n });\n this.socket.on(BridgeEvent.Call, (call: BridgeCallRequest) => {\n const id = call.id;\n assert(typeof id !== 'undefined', 'call id is required');\n (async () => {\n let response: any;\n try {\n response = await this.onBridgeCall(call.method, call.args);\n } catch (e: any) {\n const errorContent = `Error from bridge client when calling, method: ${call.method}, args: ${call.args}, error: ${e?.message || e}\\n${e?.stack || ''}`;\n console.error(errorContent);\n return this.socket?.emit(BridgeEvent.CallResponse, {\n id,\n error: errorContent,\n } as BridgeCallResponse);\n }\n this.socket?.emit(BridgeEvent.CallResponse, {\n id,\n response,\n } as BridgeCallResponse);\n })();\n });\n });\n }\n\n disconnect() {\n this.socket?.disconnect();\n this.socket = null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAAA,gBAAuB;;;ACyHhB,IAAM,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AClHrC,uBAA2B;AAC3B,IAAAA,gBAAuB;;;ACLvB,6BAIO;AACP,mBAAuB;AAbvB;AAoDO,IAAM,cAAN,MAAkB;AAAA,EAOvB,YAAY,QAA4B;AAqCxC;AAgBA;AA3DA,qCAAe,oBAAI,IAAY;AAE/B;AAEA,sBAAa;AAGX,uBAAK,SAAU;AAAA,EACjB;AAAA,EAEA,aAAa,QAAkC;AAC7C,uBAAK,SAAU;AAAA,EACjB;AAAA,EAEA,MAAM,KACJ,KACA,UAAoC;AAAA,IAClC,MAAM;AAAA,IACN,UAAU,CAAC;AAAA,EACb,GACe;AACf,UAAM,cAAc,sBAAK,sDAAL,WAA8B;AAElD,UAAM,aAAa,mBAAK,cAAa,IAAI,YAAY,IAAI;AACzD,uBAAK,cAAa,IAAI,YAAY,IAAI;AACtC,SAAK,cAAc,sBAAK,8BAAL,WAAkB,YAAY;AAEjD,UAAM,OAAO,QAAQ,SAAS,SAAY,YAAY,OAAO,QAAQ;AACrE,UAAM,mBAAK,SAAQ,KAAK,0BAA0B;AAAA,MAChD,MAAM,OAAO,YAAY;AAAA,MACzB,WAAW,KAAK;AAAA,MAChB,uBAAuB,YAAY;AAAA,MACnC,MAAM,YAAY;AAAA,MAClB,KAAK,YAAY;AAAA,MACjB;AAAA,MACA,gBAAgB;AAAA,MAChB;AAAA,MACA,UAAU,YAAY;AA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AEpE,QAAI,SAAS,wBAAwB;AACnC,WAAK,yBAAyB;AAAA,IAChC;AAEA,UAAM,KAAK,eAAe,KAAK;AAAA,EACjC;AAAA,EAEA,MAAa,kBAAkB,SAAmC;AAChE,SAAK,iBAAiB;AAAA,EACxB;AAAA,EAEA,MAAM,UAAU;AACd,QAAI,KAAK,gBAAgB,YAAY,KAAK,mBAAmB,SAAS,GAAG;AACvE,WAAK,aAAa,+CAA+C,KAAK;AACtE,iBAAW,SAAS,KAAK,oBAAoB;AAC3C,cAAM,OAAO,KAAK,OAAO,KAAK;AAAA,MAChC;AACA,WAAK,qBAAqB,CAAC;AAAA,IAC7B;AAEA,UAAM,MAAM,QAAQ;AAEpB,QAAI,KAAK,cAAc;AACrB,WAAK,aAAa,WAAW;AAC7B,WAAK,eAAe;AACpB,WAAK,aAAa;AAAA,IACpB;AAAA,EACF;AACF","names":["import_utils","fs","error","ClientIO","e"],"ignoreList":[],"sources":["../../src/bridge-mode/browser.ts","../../src/bridge-mode/page-browser-side.ts","../../src/common/ui-utils.ts","../../src/chrome-extension/page.ts","../../src/chrome-extension/cdpInput.ts","../../src/chrome-extension/dynamic-scripts.ts","../../src/bridge-mode/common.ts","../../src/bridge-mode/io-client.ts"],"sourcesContent":["import { ExtensionBridgePageBrowserSide } from '../bridge-mode/page-browser-side';\n\nexport { ExtensionBridgePageBrowserSide };\n","import type {\n ChromePageDestroyOptions,\n KeyboardAction,\n MouseAction,\n} from '@/page';\nimport { assert } from '@midscene/shared/utils';\nimport ChromeExtensionProxyPage from '../chrome-extension/page';\nimport {\n type BridgeConnectTabOptions,\n BridgeEvent,\n DefaultBridgeServerPort,\n KeyboardEvent,\n MouseEvent,\n} from './common';\nimport { BridgeClient } from './io-client';\n\ndeclare const __VERSION__: string;\n\nexport class ExtensionBridgePageBrowserSide extends ChromeExtensionProxyPage {\n public bridgeClient: BridgeClient | null = null;\n\n private destroyOptions?: ChromePageDestroyOptions;\n\n private newlyCreatedTabIds: number[] = [];\n\n constructor(\n public onDisconnect: () => void = () => {},\n public onLogMessage: (\n message: string,\n type: 'log' | 'status',\n ) => void = () => {},\n forceSameTabNavigation = true,\n ) {\n super(forceSameTabNavigation);\n }\n\n private async setupBridgeClient() {\n this.bridgeClient = new BridgeClient(\n `ws://localhost:${DefaultBridgeServerPort}`,\n async (method, args: any[]) => {\n console.log('bridge call from cli side', method, args);\n if (method === BridgeEvent.ConnectNewTabWithUrl) {\n return this.connectNewTabWithUrl.apply(\n this,\n args as unknown as [string],\n );\n }\n\n if (method === BridgeEvent.GetBrowserTabList) {\n return this.getBrowserTabList.apply(this, args as any);\n }\n\n if (method === BridgeEvent.SetActiveTabId) {\n return this.setActiveTabId.apply(this, args as any);\n }\n\n if (method === BridgeEvent.ConnectCurrentTab) {\n return this.connectCurrentTab.apply(this, args as any);\n }\n\n if (method === BridgeEvent.UpdateAgentStatus) {\n return this.onLogMessage(args[0] as string, 'status');\n }\n\n const tabId = await this.getActiveTabId();\n if (!tabId || tabId === 0) {\n throw new Error('no tab is connected');\n }\n\n // this.onLogMessage(`calling method: ${method}`);\n\n if (method.startsWith(MouseEvent.PREFIX)) {\n const actionName = method.split('.')[1] as keyof MouseAction;\n if (actionName === 'drag') {\n return this.mouse[actionName].apply(this.mouse, args as any);\n }\n return this.mouse[actionName].apply(this.mouse, args as any);\n }\n\n if (method.startsWith(KeyboardEvent.PREFIX)) {\n const actionName = method.split('.')[1] as keyof KeyboardAction;\n if (actionName === 'press') {\n return this.keyboard[actionName].apply(this.keyboard, args as any);\n }\n return this.keyboard[actionName].apply(this.keyboard, args as any);\n }\n\n try {\n // @ts-expect-error\n const result = await this[method as keyof ChromeExtensionProxyPage](\n ...args,\n );\n return result;\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : 'Unknown error';\n console.error('error calling method', method, args, e);\n this.onLogMessage(\n `Error calling method: ${method}, ${errorMessage}`,\n 'log',\n );\n throw new Error(errorMessage, { cause: e });\n }\n },\n // on disconnect\n () => {\n return this.destroy();\n },\n );\n await this.bridgeClient.connect();\n this.onLogMessage(\n `Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v${__VERSION__}`,\n 'log',\n );\n }\n\n public async connect() {\n return await this.setupBridgeClient();\n }\n\n public async connectNewTabWithUrl(\n url: string,\n options: BridgeConnectTabOptions = {\n forceSameTabNavigation: true,\n },\n ) {\n const tab = await chrome.tabs.create({ url });\n const tabId = tab.id;\n assert(tabId, 'failed to get tabId after creating a new tab');\n\n // new tab\n this.onLogMessage(`Creating new tab: ${url}`, 'log');\n this.newlyCreatedTabIds.push(tabId);\n\n if (options?.forceSameTabNavigation) {\n this.forceSameTabNavigation = true;\n }\n\n await this.setActiveTabId(tabId);\n }\n\n public async connectCurrentTab(\n options: BridgeConnectTabOptions = {\n forceSameTabNavigation: true,\n },\n ) {\n const tabs = await chrome.tabs.query({ active: true, currentWindow: true });\n console.log('current tab', tabs);\n const tabId = tabs[0]?.id;\n assert(tabId, 'failed to get tabId');\n\n this.onLogMessage(`Connected to current tab: ${tabs[0]?.url}`, 'log');\n\n if (options?.forceSameTabNavigation) {\n this.forceSameTabNavigation = true;\n }\n\n await this.setActiveTabId(tabId);\n }\n\n public async setDestroyOptions(options: ChromePageDestroyOptions) {\n this.destroyOptions = options;\n }\n\n async destroy() {\n if (this.destroyOptions?.closeTab && this.newlyCreatedTabIds.length > 0) {\n this.onLogMessage('Closing all newly created tabs by bridge...', 'log');\n for (const tabId of this.newlyCreatedTabIds) {\n await chrome.tabs.remove(tabId);\n }\n this.newlyCreatedTabIds = [];\n }\n\n await super.destroy();\n\n if (this.bridgeClient) {\n this.bridgeClient.disconnect();\n this.bridgeClient = null;\n this.onDisconnect();\n }\n }\n}\n","import type {\n DetailedLocateParam,\n ExecutionTask,\n ExecutionTaskAction,\n ExecutionTaskInsightAssertion,\n ExecutionTaskInsightLocate,\n ExecutionTaskInsightQuery,\n ExecutionTaskPlanning,\n PlanningActionParamScroll,\n} from '@midscene/core';\n\nexport function typeStr(task: ExecutionTask) {\n return task.subType ? `${task.type} / ${task.subType || ''}` : task.type;\n}\n\nexport function getKeyCommands(\n value: string | string[],\n): Array<{ key: string; command?: string }> {\n // Ensure value is an array of keys\n const keys = Array.isArray(value) ? value : [value];\n\n // Process each key to attach a corresponding command if needed, based on the presence of 'Meta' or 'Control' in the keys array.\n // ref: https://github.com/puppeteer/puppeteer/pull/9357/files#diff-32cf475237b000f980eb214a0a823e45a902bddb7d2426d677cae96397aa0ae4R94\n return keys.reduce((acc: Array<{ key: string; command?: string }>, k) => {\n const includeMeta = keys.includes('Meta') || keys.includes('Control');\n if (includeMeta && (k === 'a' || k === 'A')) {\n return acc.concat([{ key: k, command: 'SelectAll' }]);\n }\n if (includeMeta && (k === 'c' || k === 'C')) {\n return acc.concat([{ key: k, command: 'Copy' }]);\n }\n if (includeMeta && (k === 'v' || k === 'V')) {\n return acc.concat([{ key: k, command: 'Paste' }]);\n }\n return acc.concat([{ key: k }]);\n }, []);\n}\n\nexport function locateParamStr(locate?: DetailedLocateParam) {\n if (!locate) {\n return '';\n }\n\n if (typeof locate === 'string') {\n return locate;\n }\n\n return locate.prompt;\n}\n\nexport function scrollParamStr(scrollParam?: PlanningActionParamScroll) {\n if (!scrollParam) {\n return '';\n }\n return `${scrollParam.direction || 'down'}, ${scrollParam.scrollType || 'once'}, ${scrollParam.distance || 'distance-not-set'}`;\n}\n\nexport function taskTitleStr(\n type:\n | 'Tap'\n | 'Hover'\n | 'Input'\n | 'KeyboardPress'\n | 'Scroll'\n | 'Action'\n | 'Query'\n | 'Assert'\n | 'WaitFor'\n | 'Locate'\n | 'Boolean'\n | 'Number'\n | 'String',\n prompt: string,\n) {\n if (prompt) {\n return `${type} - ${prompt}`;\n }\n return type;\n}\n\nexport function paramStr(task: ExecutionTask) {\n let value: string | undefined | object;\n if (task.type === 'Planning') {\n value = (task as ExecutionTaskPlanning)?.param?.userInstruction;\n }\n\n if (task.type === 'Insight') {\n value =\n (task as ExecutionTaskInsightLocate)?.param?.prompt ||\n (task as ExecutionTaskInsightLocate)?.param?.id ||\n (task as ExecutionTaskInsightQuery)?.param?.dataDemand ||\n (task as ExecutionTaskInsightAssertion)?.param?.assertion;\n }\n\n if (task.type === 'Action') {\n const locate = (task as ExecutionTaskAction)?.locate;\n const locateStr = locate ? locateParamStr(locate) : '';\n\n value = task.thought || '';\n if (typeof (task as ExecutionTaskAction)?.param?.timeMs === 'number') {\n value = `${(task as ExecutionTaskAction)?.param?.timeMs}ms`;\n } else if (\n typeof (task as ExecutionTaskAction)?.param?.scrollType === 'string'\n ) {\n value = scrollParamStr((task as ExecutionTaskAction)?.param);\n } else if (\n typeof (task as ExecutionTaskAction)?.param?.value !== 'undefined'\n ) {\n value = (task as ExecutionTaskAction)?.param?.value;\n }\n\n if (locateStr) {\n if (value) {\n value = `${locateStr} - ${value}`;\n } else {\n value = locateStr;\n }\n }\n }\n\n if (typeof value === 'undefined') return '';\n return typeof value === 'string'\n ? value\n : JSON.stringify(value, undefined, 2);\n}\n\nexport const limitOpenNewTabScript = `\nif (!window.__MIDSCENE_NEW_TAB_INTERCEPTOR_INITIALIZED__) {\n window.__MIDSCENE_NEW_TAB_INTERCEPTOR_INITIALIZED__ = true;\n\n // Intercept the window.open method (only once)\n window.open = function(url) {\n console.log('Blocked window.open:', url);\n window.location.href = url;\n return null;\n };\n\n // Block all a tag clicks with target=\"_blank\" (only once)\n document.addEventListener('click', function(e) {\n const target = e.target.closest('a');\n if (target && target.target === '_blank') {\n e.preventDefault();\n console.log('Blocked new tab:', target.href);\n window.location.href = target.href;\n target.removeAttribute('target');\n }\n }, true);\n}\n`;\n","/// <reference types=\"chrome\" />\n\n/*\n It is used to interact with the page tab from the chrome extension.\n The page must be active when interacting with it.\n*/\n\nimport type { WebKeyInput } from '@/common/page';\nimport { limitOpenNewTabScript } from '@/common/ui-utils';\nimport type { AbstractPage, ChromePageDestroyOptions } from '@/page';\nimport type { ElementTreeNode, Point, Size } from '@midscene/core';\nimport type { ElementInfo } from '@midscene/shared/extractor';\nimport { treeToList } from '@midscene/shared/extractor';\nimport { assert } from '@midscene/shared/utils';\nimport type { Protocol as CDPTypes } from 'devtools-protocol';\nimport { CdpKeyboard } from './cdpInput';\nimport {\n getHtmlElementScript,\n injectStopWaterFlowAnimation,\n injectWaterFlowAnimation,\n} from './dynamic-scripts';\n\nfunction sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\ndeclare const __VERSION__: string;\n\nexport default class ChromeExtensionProxyPage implements AbstractPage {\n pageType = 'chrome-extension-proxy';\n\n public forceSameTabNavigation: boolean;\n private version: string = __VERSION__;\n\n private viewportSize?: Size;\n\n private activeTabId: number | null = null;\n\n private tabIdOfDebuggerAttached: number | null = null;\n\n private attachingDebugger: Promise<void> | null = null;\n\n private destroyed = false;\n\n constructor(forceSameTabNavigation: boolean) {\n this.forceSameTabNavigation = forceSameTabNavigation;\n }\n\n public async setActiveTabId(tabId: number) {\n if (this.activeTabId) {\n throw new Error(\n `Active tab id is already set, which is ${this.activeTabId}, cannot set it to ${tabId}`,\n );\n }\n await chrome.tabs.update(tabId, { active: true });\n this.activeTabId = tabId;\n }\n\n public async getActiveTabId() {\n return this.activeTabId;\n }\n\n /**\n * Get a list of current tabs\n * @returns {Promise<Array<{id: number, title: string, url: string}>>}\n */\n public async getBrowserTabList(): Promise<\n { id: string; title: string; url: string; currentActiveTab: boolean }[]\n > {\n const tabs = await chrome.tabs.query({ currentWindow: true });\n return tabs\n .map((tab) => ({\n id: `${tab.id}`,\n title: tab.title,\n url: tab.url,\n currentActiveTab: tab.active,\n }))\n .filter((tab) => tab.id && tab.title && tab.url) as {\n id: string;\n title: string;\n url: string;\n currentActiveTab: boolean;\n }[];\n }\n\n public async getTabIdOrConnectToCurrentTab() {\n if (this.activeTabId) {\n // alway keep on the connected tab\n return this.activeTabId;\n }\n const tabId = await chrome.tabs\n .query({ active: true, currentWindow: true })\n .then((tabs) => tabs[0]?.id);\n this.activeTabId = tabId || 0;\n return this.activeTabId;\n }\n\n private async attachDebugger() {\n assert(!this.destroyed, 'Page is destroyed');\n\n // If already attaching, wait for it to complete\n if (this.attachingDebugger) {\n await this.attachingDebugger;\n return;\n }\n\n // Create new attaching promise\n this.attachingDebugger = (async () => {\n const url = await this.url();\n let error: Error | null = null;\n if (url.startsWith('chrome://')) {\n throw new Error(\n 'Cannot attach debugger to chrome:// pages, please use Midscene in a normal page with http://, https:// or file://',\n );\n }\n\n try {\n const currentTabId = await this.getTabIdOrConnectToCurrentTab();\n\n if (this.tabIdOfDebuggerAttached === currentTabId) {\n // already attached\n return;\n }\n if (\n this.tabIdOfDebuggerAttached &&\n this.tabIdOfDebuggerAttached !== currentTabId\n ) {\n // detach the previous tab\n console.log(\n 'detach the previous tab',\n this.tabIdOfDebuggerAttached,\n '->',\n currentTabId,\n );\n try {\n await this.detachDebugger(this.tabIdOfDebuggerAttached);\n } catch (error) {\n console.error('Failed to detach debugger', error);\n }\n }\n\n // detach any debugger attached to the tab\n console.log('attaching debugger', currentTabId);\n await chrome.debugger.attach({ tabId: currentTabId }, '1.3');\n // wait util the debugger banner in Chrome appears\n await sleep(500);\n\n this.tabIdOfDebuggerAttached = currentTabId;\n\n await this.enableWaterFlowAnimation();\n } catch (e) {\n console.error('Failed to attach debugger', e);\n error = e as Error;\n } finally {\n this.attachingDebugger = null;\n }\n if (error) {\n throw error;\n }\n })();\n\n await this.attachingDebugger;\n }\n\n private async showMousePointer(x: number, y: number) {\n // update mouse pointer while redirecting\n const pointerScript = `(() => {\n if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {\n window.midsceneWaterFlowAnimation.enable();\n window.midsceneWaterFlowAnimation.showMousePointer(${x}, ${y});\n } else {\n console.log('midsceneWaterFlowAnimation is not defined');\n }\n })()`;\n\n await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `${pointerScript}`,\n });\n }\n\n private async hideMousePointer() {\n await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `(() => {\n if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {\n window.midsceneWaterFlowAnimation.hideMousePointer();\n }\n })()`,\n });\n }\n\n private async detachDebugger(tabId?: number) {\n const tabIdToDetach = tabId || this.tabIdOfDebuggerAttached;\n console.log('detaching debugger', tabIdToDetach);\n if (!tabIdToDetach) {\n console.warn('No tab id to detach');\n return;\n }\n\n try {\n await this.disableWaterFlowAnimation(tabIdToDetach);\n await sleep(200); // wait for the animation to stop\n } catch (error) {\n console.warn('Failed to disable water flow animation', error);\n }\n\n try {\n await chrome.debugger.detach({ tabId: tabIdToDetach });\n } catch (error) {\n // maybe tab is closed ?\n console.warn('Failed to detach debugger', error);\n }\n this.tabIdOfDebuggerAttached = null;\n }\n\n private async enableWaterFlowAnimation() {\n // limit open page in new tab\n if (this.forceSameTabNavigation) {\n await chrome.debugger.sendCommand(\n { tabId: this.tabIdOfDebuggerAttached! },\n 'Runtime.evaluate',\n {\n expression: limitOpenNewTabScript,\n },\n );\n }\n\n const script = await injectWaterFlowAnimation();\n // we will call this function in sendCommandToDebugger, so we have to use the chrome.debugger.sendCommand\n await chrome.debugger.sendCommand(\n { tabId: this.tabIdOfDebuggerAttached! },\n 'Runtime.evaluate',\n {\n expression: script,\n },\n );\n }\n\n private async disableWaterFlowAnimation(tabId: number) {\n const script = await injectStopWaterFlowAnimation();\n\n await chrome.debugger.sendCommand({ tabId }, 'Runtime.evaluate', {\n expression: script,\n });\n }\n\n private async sendCommandToDebugger<ResponseType = any, RequestType = any>(\n command: string,\n params: RequestType,\n ): Promise<ResponseType> {\n await this.attachDebugger();\n\n assert(this.tabIdOfDebuggerAttached, 'Debugger is not attached');\n\n // wo don't have to await it\n this.enableWaterFlowAnimation();\n return (await chrome.debugger.sendCommand(\n { tabId: this.tabIdOfDebuggerAttached! },\n command,\n params as any,\n )) as ResponseType;\n }\n\n private async getPageContentByCDP() {\n const script = await getHtmlElementScript();\n\n // check tab url\n await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: script,\n });\n\n const expression = () => {\n return {\n tree: (window as any).midscene_element_inspector.webExtractNodeTree(),\n size: {\n width: document.documentElement.clientWidth,\n height: document.documentElement.clientHeight,\n dpr: window.devicePixelRatio,\n },\n };\n };\n const returnValue = await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: `(${expression.toString()})()`,\n returnByValue: true,\n });\n\n if (!returnValue.result.value) {\n const errorDescription =\n returnValue.exceptionDetails?.exception?.description || '';\n if (!errorDescription) {\n console.error('returnValue from cdp', returnValue);\n }\n throw new Error(\n `Failed to get page content from page, error: ${errorDescription}`,\n );\n }\n // console.log('returnValue', returnValue.result.value);\n return returnValue.result.value as {\n tree: ElementTreeNode<ElementInfo>;\n size: Size;\n };\n }\n\n public async evaluateJavaScript(script: string) {\n return this.sendCommandToDebugger('Runtime.evaluate', {\n expression: script,\n });\n }\n\n // current implementation is wait until domReadyState is complete\n public async waitUntilNetworkIdle() {\n const timeout = 10000;\n const startTime = Date.now();\n let lastReadyState = '';\n while (Date.now() - startTime < timeout) {\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: 'document.readyState',\n });\n lastReadyState = result.result.value;\n if (lastReadyState === 'complete') {\n await new Promise((resolve) => setTimeout(resolve, 300));\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, 300));\n }\n throw new Error(\n `Failed to wait until network idle, last readyState: ${lastReadyState}`,\n );\n }\n\n async getElementsInfo() {\n const tree = await this.getElementsNodeTree();\n return treeToList(tree);\n }\n\n async getElementsNodeTree() {\n await this.hideMousePointer();\n const content = await this.getPageContentByCDP();\n if (content?.size) {\n this.viewportSize = content.size;\n }\n\n return content?.tree || { node: null, children: [] };\n }\n\n async size() {\n if (this.viewportSize) return this.viewportSize;\n const content = await this.getPageContentByCDP();\n return content.size;\n }\n\n async screenshotBase64() {\n // screenshot by cdp\n await this.hideMousePointer();\n const base64 = await this.sendCommandToDebugger('Page.captureScreenshot', {\n format: 'jpeg',\n quality: 90,\n });\n return `data:image/jpeg;base64,${base64.data}`;\n }\n\n async url() {\n const tabId = await this.getTabIdOrConnectToCurrentTab();\n const url = await chrome.tabs.get(tabId).then((tab) => tab.url);\n return url || '';\n }\n\n async scrollUntilTop(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(0, -9999999);\n }\n\n async scrollUntilBottom(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(0, 9999999);\n }\n\n async scrollUntilLeft(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(-9999999, 0);\n }\n\n async scrollUntilRight(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(9999999, 0);\n }\n\n async scrollUp(distance?: number, startingPoint?: Point) {\n const { height } = await this.size();\n const scrollDistance = distance || height * 0.7;\n return this.mouse.wheel(\n 0,\n -scrollDistance,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollDown(distance?: number, startingPoint?: Point) {\n const { height } = await this.size();\n const scrollDistance = distance || height * 0.7;\n return this.mouse.wheel(\n 0,\n scrollDistance,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollLeft(distance?: number, startingPoint?: Point) {\n const { width } = await this.size();\n const scrollDistance = distance || width * 0.7;\n return this.mouse.wheel(\n -scrollDistance,\n 0,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollRight(distance?: number, startingPoint?: Point) {\n const { width } = await this.size();\n const scrollDistance = distance || width * 0.7;\n return this.mouse.wheel(\n scrollDistance,\n 0,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async clearInput(element: ElementInfo) {\n if (!element) {\n console.warn('No element to clear input');\n return;\n }\n\n await this.mouse.click(element.center[0], element.center[1]);\n\n await this.sendCommandToDebugger('Input.dispatchKeyEvent', {\n type: 'keyDown',\n commands: ['selectAll'],\n });\n\n await this.sendCommandToDebugger('Input.dispatchKeyEvent', {\n type: 'keyUp',\n commands: ['selectAll'],\n });\n\n await sleep(100);\n\n await this.keyboard.press({\n key: 'Backspace',\n });\n }\n\n private latestMouseX = 100;\n private latestMouseY = 100;\n\n mouse = {\n click: async (x: number, y: number) => {\n await this.mouse.move(x, y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x,\n y,\n button: 'left',\n clickCount: 1,\n });\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x,\n y,\n button: 'left',\n clickCount: 1,\n });\n },\n wheel: async (\n deltaX: number,\n deltaY: number,\n startX?: number,\n startY?: number,\n ) => {\n const finalX = startX || this.latestMouseX;\n const finalY = startY || this.latestMouseY;\n await this.showMousePointer(finalX, finalY);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseWheel',\n x: finalX,\n y: finalY,\n deltaX,\n deltaY,\n });\n this.latestMouseX = finalX;\n this.latestMouseY = finalY;\n },\n move: async (x: number, y: number) => {\n await this.showMousePointer(x, y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseMoved',\n x,\n y,\n });\n this.latestMouseX = x;\n this.latestMouseY = y;\n },\n drag: async (\n from: { x: number; y: number },\n to: { x: number; y: number },\n ) => {\n await this.mouse.move(from.x, from.y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x: from.x,\n y: from.y,\n button: 'left',\n clickCount: 1,\n });\n await this.mouse.move(to.x, to.y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x: to.x,\n y: to.y,\n button: 'left',\n clickCount: 1,\n });\n },\n };\n\n keyboard = {\n type: async (text: string) => {\n const cdpKeyboard = new CdpKeyboard({\n send: this.sendCommandToDebugger.bind(this),\n });\n await cdpKeyboard.type(text, { delay: 0 });\n },\n press: async (\n action:\n | { key: WebKeyInput; command?: string }\n | { key: WebKeyInput; command?: string }[],\n ) => {\n const cdpKeyboard = new CdpKeyboard({\n send: this.sendCommandToDebugger.bind(this),\n });\n const keys = Array.isArray(action) ? action : [action];\n for (const k of keys) {\n const commands = k.command ? [k.command] : [];\n await cdpKeyboard.down(k.key, { commands });\n }\n for (const k of [...keys].reverse()) {\n await cdpKeyboard.up(k.key);\n }\n },\n };\n\n async destroy(): Promise<void> {\n this.activeTabId = null;\n await this.detachDebugger();\n this.destroyed = true;\n }\n}\n","// From https://github.com/puppeteer/puppeteer/blob/15abcc390862fd08cc3475532f2d9a11284aee6b/packages/puppeteer-core/src/cdp/Input.ts#L55\n// with some modifications to fit the session type\n/**\n * @license\n * Copyright 2017 Google Inc.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type KeyDefinition,\n type KeyInput,\n _keyDefinitions,\n} from '@midscene/shared/keyboard-layout';\nimport { assert } from '@midscene/shared/utils';\n\ntype KeyDescription = Required<\n Pick<KeyDefinition, 'keyCode' | 'key' | 'text' | 'code' | 'location'>\n>;\n\n/**\n * @public\n */\nexport interface KeyDownOptions {\n /**\n * @deprecated Do not use. This is automatically handled.\n */\n text?: string;\n /**\n * @deprecated Do not use. This is automatically handled.\n */\n commands?: string[];\n}\n\n/**\n * @public\n */\nexport interface KeyboardTypeOptions {\n delay?: number;\n}\n\n/**\n * @public\n */\nexport type KeyPressOptions = KeyDownOptions & KeyboardTypeOptions;\n\ntype InternalCDPSession = {\n send: (command: string, params: any) => Promise<void>;\n};\n\n/**\n * @internal\n */\nexport class CdpKeyboard {\n #pressedKeys = new Set<string>();\n\n #client: InternalCDPSession;\n\n _modifiers = 0;\n\n constructor(client: InternalCDPSession) {\n this.#client = client;\n }\n\n updateClient(client: InternalCDPSession): void {\n this.#client = client;\n }\n\n async down(\n key: KeyInput,\n options: Readonly<KeyDownOptions> = {\n text: undefined,\n commands: [],\n },\n ): Promise<void> {\n const description = this.#keyDescriptionForString(key);\n\n const autoRepeat = this.#pressedKeys.has(description.code);\n this.#pressedKeys.add(description.code);\n this._modifiers |= this.#modifierBit(description.key);\n\n const text = options.text === undefined ? description.text : options.text;\n await this.#client.send('Input.dispatchKeyEvent', {\n type: text ? 'keyDown' : 'rawKeyDown',\n modifiers: this._modifiers,\n windowsVirtualKeyCode: description.keyCode,\n code: description.code,\n key: description.key,\n text: text,\n unmodifiedText: text,\n autoRepeat,\n location: description.location,\n isKeypad: description.location === 3,\n commands: options.commands,\n });\n }\n\n #modifierBit(key: string): number {\n if (key === 'Alt') {\n return 1;\n }\n if (key === 'Control') {\n return 2;\n }\n if (key === 'Meta') {\n return 4;\n }\n if (key === 'Shift') {\n return 8;\n }\n return 0;\n }\n\n #keyDescriptionForString(keyString: KeyInput): KeyDescription {\n const shift = this._modifiers & 8;\n const description = {\n key: '',\n keyCode: 0,\n code: '',\n text: '',\n location: 0,\n };\n\n const definition = _keyDefinitions[keyString];\n\n assert(definition, `Unknown key: \"${keyString}\"`);\n\n if (definition.key) {\n description.key = definition.key;\n }\n if (shift && definition.shiftKey) {\n description.key = definition.shiftKey;\n }\n\n if (definition.keyCode) {\n description.keyCode = definition.keyCode;\n }\n if (shift && definition.shiftKeyCode) {\n description.keyCode = definition.shiftKeyCode;\n }\n\n if (definition.code) {\n description.code = definition.code;\n }\n\n if (definition.location) {\n description.location = definition.location;\n }\n\n if (description.key.length === 1) {\n description.text = description.key;\n }\n\n if (definition.text) {\n description.text = definition.text;\n }\n if (shift && definition.shiftText) {\n description.text = definition.shiftText;\n }\n\n // if any modifiers besides shift are pressed, no text should be sent\n if (this._modifiers & ~8) {\n description.text = '';\n }\n\n return description;\n }\n\n async up(key: KeyInput): Promise<void> {\n const description = this.#keyDescriptionForString(key);\n\n this._modifiers &= ~this.#modifierBit(description.key);\n this.#pressedKeys.delete(description.code);\n await this.#client.send('Input.dispatchKeyEvent', {\n type: 'keyUp',\n modifiers: this._modifiers,\n key: description.key,\n windowsVirtualKeyCode: description.keyCode,\n code: description.code,\n location: description.location,\n });\n }\n\n async sendCharacter(char: string): Promise<void> {\n await this.#client.send('Input.insertText', { text: char });\n }\n\n private charIsKey(char: string): char is KeyInput {\n return !!_keyDefinitions[char as KeyInput];\n }\n\n async type(\n text: string,\n options: Readonly<KeyboardTypeOptions> = {},\n ): Promise<void> {\n const delay = options.delay || undefined;\n for (const char of text) {\n if (this.charIsKey(char)) {\n await this.press(char, { delay });\n } else {\n if (delay) {\n await new Promise((f) => {\n return setTimeout(f, delay);\n });\n }\n await this.sendCharacter(char);\n }\n }\n }\n\n async press(\n key: KeyInput | KeyInput[],\n options: Readonly<KeyPressOptions> = {},\n ): Promise<void> {\n const { delay = null } = options;\n const keys = Array.isArray(key) ? key : [key];\n\n for (const k of keys) {\n await this.down(k, options);\n }\n\n if (delay) {\n await new Promise((f) => {\n return setTimeout(f, options.delay);\n });\n }\n\n for (const k of [...keys].reverse()) {\n await this.up(k);\n }\n }\n}\n","import fs from 'node:fs';\nimport { ifInBrowser } from '@midscene/shared/utils';\n\n// remember to include this file into extension's package\n// extract html element from page\nlet scriptFileContentCache: string | null = null;\nexport const getHtmlElementScript = async () => {\n const scriptFileToRetrieve = chrome.runtime.getURL('scripts/htmlElement.js');\n if (scriptFileContentCache) return scriptFileContentCache;\n if (ifInBrowser) {\n const script = await fetch(scriptFileToRetrieve);\n scriptFileContentCache = await script.text();\n return scriptFileContentCache;\n }\n return fs.readFileSync(scriptFileToRetrieve, 'utf8');\n};\n\n// inject water flow animation\nlet waterFlowScriptFileContentCache: string | null = null;\nexport const injectWaterFlowAnimation = async () => {\n const waterFlowScriptFileToRetrieve = chrome.runtime.getURL(\n 'scripts/water-flow.js',\n );\n if (waterFlowScriptFileContentCache) return waterFlowScriptFileContentCache;\n if (ifInBrowser) {\n const script = await fetch(waterFlowScriptFileToRetrieve);\n waterFlowScriptFileContentCache = await script.text();\n return waterFlowScriptFileContentCache;\n }\n return fs.readFileSync(waterFlowScriptFileToRetrieve, 'utf8');\n};\n\n// inject stop water flow animation\nlet stopWaterFlowScriptFileContentCache: string | null = null;\nexport const injectStopWaterFlowAnimation = async () => {\n const stopWaterFlowScriptFileToRetrieve = chrome.runtime.getURL(\n 'scripts/stop-water-flow.js',\n );\n if (stopWaterFlowScriptFileContentCache)\n return stopWaterFlowScriptFileContentCache;\n if (ifInBrowser) {\n const script = await fetch(stopWaterFlowScriptFileToRetrieve);\n stopWaterFlowScriptFileContentCache = await script.text();\n return stopWaterFlowScriptFileContentCache;\n }\n return fs.readFileSync(stopWaterFlowScriptFileToRetrieve, 'utf8');\n};\n","export const DefaultBridgeServerPort = 3766;\nexport const DefaultLocalEndpoint = `http://127.0.0.1:${DefaultBridgeServerPort}`;\nexport const BridgeCallTimeout = 30000;\n\nexport enum BridgeEvent {\n Call = 'bridge-call',\n CallResponse = 'bridge-call-response',\n UpdateAgentStatus = 'bridge-update-agent-status',\n Message = 'bridge-message',\n Connected = 'bridge-connected',\n Refused = 'bridge-refused',\n ConnectNewTabWithUrl = 'connectNewTabWithUrl',\n ConnectCurrentTab = 'connectCurrentTab',\n GetBrowserTabList = 'getBrowserTabList',\n SetDestroyOptions = 'setDestroyOptions',\n SetActiveTabId = 'setActiveTabId',\n}\n\nexport interface BridgeConnectTabOptions {\n /**\n * If true, the page will always track the active tab.\n * @default true\n */\n forceSameTabNavigation?: boolean;\n}\n\nexport enum MouseEvent {\n PREFIX = 'mouse.',\n Click = 'mouse.click',\n Wheel = 'mouse.wheel',\n Move = 'mouse.move',\n Drag = 'mouse.drag',\n}\n\nexport enum KeyboardEvent {\n PREFIX = 'keyboard.',\n Type = 'keyboard.type',\n Press = 'keyboard.press',\n}\n\nexport const BridgePageType = 'page-over-chrome-extension-bridge';\n\nexport const BridgeErrorCodeNoClientConnected = 'no-client-connected';\n\nexport interface BridgeCall {\n method: string;\n args: any[];\n response: any;\n callTime: number;\n responseTime: number;\n callback: (error: Error | undefined, response: any) => void;\n error?: Error;\n}\n\nexport interface BridgeCallRequest {\n id: string;\n method: string;\n args: any[];\n}\n\nexport interface BridgeCallResponse {\n id: string;\n response: any;\n error?: any;\n}\n\nexport interface BridgeConnectedEventPayload {\n version: string;\n}\n","import { assert } from '@midscene/shared/utils';\nimport { io as ClientIO, type Socket as ClientSocket } from 'socket.io-client';\nimport {\n type BridgeCallRequest,\n type BridgeCallResponse,\n type BridgeConnectedEventPayload,\n BridgeEvent,\n} from './common';\n\ndeclare const __VERSION__: string;\n\n// ws client, this is where the request is processed\nexport class BridgeClient {\n private socket: ClientSocket | null = null;\n public serverVersion: string | null = null;\n constructor(\n public endpoint: string,\n public onBridgeCall: (method: string, args: any[]) => Promise<any>,\n public onDisconnect?: () => void,\n ) {}\n\n async connect() {\n return new Promise((resolve, reject) => {\n this.socket = ClientIO(this.endpoint, {\n reconnection: false,\n query: {\n version: __VERSION__,\n },\n });\n\n const timeout = setTimeout(() => {\n try {\n this.socket?.offAny();\n this.socket?.close();\n } catch (e) {\n console.warn('got error when offing socket', e);\n }\n this.socket = null;\n reject(new Error('failed to connect to bridge server after timeout'));\n }, 1 * 1000);\n\n // on disconnect\n this.socket.on('disconnect', (reason: string) => {\n // console.log('bridge-disconnected, reason:', reason);\n this.socket = null;\n this.onDisconnect?.();\n });\n\n this.socket.on('connect_error', (e: any) => {\n console.error('bridge-connect-error', e);\n reject(new Error(e || 'bridge connect error'));\n });\n\n this.socket.on(\n BridgeEvent.Connected,\n (payload: BridgeConnectedEventPayload) => {\n clearTimeout(timeout);\n this.serverVersion = payload?.version || 'unknown';\n resolve(this.socket);\n },\n );\n this.socket.on(BridgeEvent.Refused, (e: any) => {\n console.error('bridge-refused', e);\n try {\n this.socket?.disconnect();\n } catch (e) {\n // console.warn('got error when disconnecting socket', e);\n }\n reject(new Error(e || 'bridge refused'));\n });\n this.socket.on(BridgeEvent.Call, (call: BridgeCallRequest) => {\n const id = call.id;\n assert(typeof id !== 'undefined', 'call id is required');\n (async () => {\n let response: any;\n try {\n response = await this.onBridgeCall(call.method, call.args);\n } catch (e: any) {\n const errorContent = `Error from bridge client when calling, method: ${call.method}, args: ${call.args}, error: ${e?.message || e}\\n${e?.stack || ''}`;\n console.error(errorContent);\n return this.socket?.emit(BridgeEvent.CallResponse, {\n id,\n error: errorContent,\n } as BridgeCallResponse);\n }\n this.socket?.emit(BridgeEvent.CallResponse, {\n id,\n response,\n } as BridgeCallResponse);\n })();\n });\n });\n }\n\n disconnect() {\n this.socket?.disconnect();\n this.socket = null;\n }\n}\n"]}
|
package/dist/lib/bridge-mode.js
CHANGED
|
@@ -31,7 +31,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var bridge_mode_exports = {};
|
|
32
32
|
__export(bridge_mode_exports, {
|
|
33
33
|
AgentOverChromeBridge: () => AgentOverChromeBridge,
|
|
34
|
-
DefaultBridgeServerPort: () => DefaultBridgeServerPort,
|
|
35
34
|
allConfigFromEnv: () => import_env7.allConfigFromEnv,
|
|
36
35
|
overrideAIConfig: () => import_env7.overrideAIConfig
|
|
37
36
|
});
|
|
@@ -1506,17 +1505,23 @@ var PageTaskExecutor = class {
|
|
|
1506
1505
|
executor: taskExecutor
|
|
1507
1506
|
};
|
|
1508
1507
|
}
|
|
1509
|
-
async
|
|
1510
|
-
const
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1508
|
+
async createTypeQueryTask(type, demand) {
|
|
1509
|
+
const taskExecutor = new import_core.Executor(
|
|
1510
|
+
taskTitleStr(
|
|
1511
|
+
type,
|
|
1512
|
+
typeof demand === "string" ? demand : JSON.stringify(demand)
|
|
1513
|
+
),
|
|
1514
|
+
{
|
|
1515
|
+
onTaskStart: this.onTaskStartCallback
|
|
1516
|
+
}
|
|
1517
|
+
);
|
|
1514
1518
|
const queryTask = {
|
|
1515
1519
|
type: "Insight",
|
|
1516
|
-
subType:
|
|
1520
|
+
subType: type,
|
|
1517
1521
|
locate: null,
|
|
1518
1522
|
param: {
|
|
1519
1523
|
dataDemand: demand
|
|
1524
|
+
// for user param presentation in report right sidebar
|
|
1520
1525
|
},
|
|
1521
1526
|
executor: async (param) => {
|
|
1522
1527
|
let insightDump;
|
|
@@ -1524,11 +1529,21 @@ var PageTaskExecutor = class {
|
|
|
1524
1529
|
insightDump = dump;
|
|
1525
1530
|
};
|
|
1526
1531
|
this.insight.onceDumpUpdatedFn = dumpCollector;
|
|
1527
|
-
const
|
|
1528
|
-
|
|
1529
|
-
)
|
|
1532
|
+
const ifTypeRestricted = type !== "Query";
|
|
1533
|
+
let demandInput = demand;
|
|
1534
|
+
if (ifTypeRestricted) {
|
|
1535
|
+
demandInput = {
|
|
1536
|
+
result: `${type}, ${demand}`
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
const { data, usage } = await this.insight.extract(demandInput);
|
|
1540
|
+
let outputResult = data;
|
|
1541
|
+
if (ifTypeRestricted) {
|
|
1542
|
+
(0, import_utils9.assert)(data?.result !== void 0, "No result in query data");
|
|
1543
|
+
outputResult = data.result;
|
|
1544
|
+
}
|
|
1530
1545
|
return {
|
|
1531
|
-
output:
|
|
1546
|
+
output: outputResult,
|
|
1532
1547
|
log: { dump: insightDump },
|
|
1533
1548
|
usage
|
|
1534
1549
|
};
|
|
@@ -1541,6 +1556,18 @@ var PageTaskExecutor = class {
|
|
|
1541
1556
|
executor: taskExecutor
|
|
1542
1557
|
};
|
|
1543
1558
|
}
|
|
1559
|
+
async query(demand) {
|
|
1560
|
+
return this.createTypeQueryTask("Query", demand);
|
|
1561
|
+
}
|
|
1562
|
+
async boolean(prompt) {
|
|
1563
|
+
return this.createTypeQueryTask("Boolean", prompt);
|
|
1564
|
+
}
|
|
1565
|
+
async number(prompt) {
|
|
1566
|
+
return this.createTypeQueryTask("Number", prompt);
|
|
1567
|
+
}
|
|
1568
|
+
async string(prompt) {
|
|
1569
|
+
return this.createTypeQueryTask("String", prompt);
|
|
1570
|
+
}
|
|
1544
1571
|
async assert(assertion) {
|
|
1545
1572
|
const description = `assert: ${assertion}`;
|
|
1546
1573
|
const taskExecutor = new import_core.Executor(taskTitleStr("Assert", description), {
|
|
@@ -1727,6 +1754,16 @@ function buildPlans(type, locateParam, param) {
|
|
|
1727
1754
|
};
|
|
1728
1755
|
returnPlans = [sleepPlan];
|
|
1729
1756
|
}
|
|
1757
|
+
if (type === "Locate") {
|
|
1758
|
+
(0, import_utils10.assert)(locateParam, `missing locate info for action "${type}"`);
|
|
1759
|
+
const locatePlan2 = {
|
|
1760
|
+
type,
|
|
1761
|
+
param: locateParam,
|
|
1762
|
+
locate: locateParam,
|
|
1763
|
+
thought: ""
|
|
1764
|
+
};
|
|
1765
|
+
returnPlans = [locatePlan2];
|
|
1766
|
+
}
|
|
1730
1767
|
if (returnPlans) {
|
|
1731
1768
|
debug3("buildPlans", returnPlans);
|
|
1732
1769
|
return returnPlans;
|
|
@@ -1926,6 +1963,35 @@ ${errorTask?.errorStack}`);
|
|
|
1926
1963
|
this.afterTaskRunning(executor);
|
|
1927
1964
|
return output;
|
|
1928
1965
|
}
|
|
1966
|
+
async aiBoolean(prompt) {
|
|
1967
|
+
const { output, executor } = await this.taskExecutor.boolean(prompt);
|
|
1968
|
+
this.afterTaskRunning(executor);
|
|
1969
|
+
return output;
|
|
1970
|
+
}
|
|
1971
|
+
async aiNumber(prompt) {
|
|
1972
|
+
const { output, executor } = await this.taskExecutor.number(prompt);
|
|
1973
|
+
this.afterTaskRunning(executor);
|
|
1974
|
+
return output;
|
|
1975
|
+
}
|
|
1976
|
+
async aiString(prompt) {
|
|
1977
|
+
const { output, executor } = await this.taskExecutor.string(prompt);
|
|
1978
|
+
this.afterTaskRunning(executor);
|
|
1979
|
+
return output;
|
|
1980
|
+
}
|
|
1981
|
+
async aiLocate(prompt, opt) {
|
|
1982
|
+
const detailedLocateParam = this.buildDetailedLocateParam(prompt, opt);
|
|
1983
|
+
const plans = buildPlans("Locate", detailedLocateParam);
|
|
1984
|
+
const { executor, output } = await this.taskExecutor.runPlans(
|
|
1985
|
+
taskTitleStr("Locate", locateParamStr(detailedLocateParam)),
|
|
1986
|
+
plans
|
|
1987
|
+
);
|
|
1988
|
+
this.afterTaskRunning(executor);
|
|
1989
|
+
const { element } = output;
|
|
1990
|
+
return {
|
|
1991
|
+
rect: element?.rect,
|
|
1992
|
+
center: element?.center
|
|
1993
|
+
};
|
|
1994
|
+
}
|
|
1929
1995
|
async aiAssert(assertion, msg, opt) {
|
|
1930
1996
|
const { output, executor } = await this.taskExecutor.assert(assertion);
|
|
1931
1997
|
this.afterTaskRunning(executor, true);
|
|
@@ -2011,6 +2077,7 @@ var BridgeErrorCodeNoClientConnected = "no-client-connected";
|
|
|
2011
2077
|
|
|
2012
2078
|
// src/bridge-mode/io-server.ts
|
|
2013
2079
|
var import_utils15 = require("@midscene/shared/utils");
|
|
2080
|
+
var import_fkill = __toESM(require("fkill"));
|
|
2014
2081
|
var import_socket = require("socket.io");
|
|
2015
2082
|
var BridgeServer = class {
|
|
2016
2083
|
constructor(port, onConnect, onDisconnect) {
|
|
@@ -2031,7 +2098,10 @@ var BridgeServer = class {
|
|
|
2031
2098
|
};
|
|
2032
2099
|
}
|
|
2033
2100
|
async listen(opts = {}) {
|
|
2034
|
-
const { timeout = 3e4 } = opts;
|
|
2101
|
+
const { timeout = 3e4, forceCloseServer = false } = opts;
|
|
2102
|
+
if (forceCloseServer) {
|
|
2103
|
+
await this.killPort();
|
|
2104
|
+
}
|
|
2035
2105
|
return new Promise((resolve2, reject) => {
|
|
2036
2106
|
if (this.listeningTimerFlag) {
|
|
2037
2107
|
return reject(new Error("already listening"));
|
|
@@ -2076,7 +2146,7 @@ var BridgeServer = class {
|
|
|
2076
2146
|
this.socket = socket;
|
|
2077
2147
|
const clientVersion = socket.handshake.query.version;
|
|
2078
2148
|
(0, import_utils15.logMsg)(
|
|
2079
|
-
`Bridge connected, cli-side version v${"0.16.
|
|
2149
|
+
`Bridge connected, cli-side version v${"0.16.6"}, browser-side version v${clientVersion}`
|
|
2080
2150
|
);
|
|
2081
2151
|
socket.on("bridge-call-response" /* CallResponse */, (params) => {
|
|
2082
2152
|
const id = params.id;
|
|
@@ -2107,7 +2177,7 @@ var BridgeServer = class {
|
|
|
2107
2177
|
setTimeout(() => {
|
|
2108
2178
|
this.onConnect?.();
|
|
2109
2179
|
const payload = {
|
|
2110
|
-
version: "0.16.
|
|
2180
|
+
version: "0.16.6"
|
|
2111
2181
|
};
|
|
2112
2182
|
socket.emit("bridge-connected" /* Connected */, payload);
|
|
2113
2183
|
Promise.resolve().then(() => {
|
|
@@ -2129,6 +2199,14 @@ var BridgeServer = class {
|
|
|
2129
2199
|
});
|
|
2130
2200
|
});
|
|
2131
2201
|
}
|
|
2202
|
+
async killPort() {
|
|
2203
|
+
if (!this.listeningTimerFlag) {
|
|
2204
|
+
try {
|
|
2205
|
+
await (0, import_fkill.default)(this.port);
|
|
2206
|
+
} catch (e) {
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2132
2210
|
async triggerCallResponseCallback(id, error, response) {
|
|
2133
2211
|
const call = this.calls[id];
|
|
2134
2212
|
if (!call) {
|
|
@@ -2198,10 +2276,11 @@ var BridgeServer = class {
|
|
|
2198
2276
|
|
|
2199
2277
|
// src/bridge-mode/agent-cli-side.ts
|
|
2200
2278
|
var sleep2 = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
2201
|
-
var getBridgePageInCliSide = (timeout) => {
|
|
2279
|
+
var getBridgePageInCliSide = (forceCloseServer, timeout) => {
|
|
2202
2280
|
const server = new BridgeServer(DefaultBridgeServerPort);
|
|
2203
2281
|
server.listen({
|
|
2204
|
-
timeout
|
|
2282
|
+
timeout,
|
|
2283
|
+
forceCloseServer
|
|
2205
2284
|
});
|
|
2206
2285
|
const bridgeCaller = (method) => {
|
|
2207
2286
|
return async (...args) => {
|
|
@@ -2265,7 +2344,10 @@ var getBridgePageInCliSide = (timeout) => {
|
|
|
2265
2344
|
};
|
|
2266
2345
|
var AgentOverChromeBridge = class extends PageAgent {
|
|
2267
2346
|
constructor(opts) {
|
|
2268
|
-
const page = getBridgePageInCliSide(
|
|
2347
|
+
const page = getBridgePageInCliSide(
|
|
2348
|
+
opts?.forceCloseServer,
|
|
2349
|
+
opts?.serverListeningTimeout
|
|
2350
|
+
);
|
|
2269
2351
|
super(
|
|
2270
2352
|
page,
|
|
2271
2353
|
Object.assign(opts || {}, {
|
|
@@ -2322,7 +2404,6 @@ var import_env7 = require("@midscene/shared/env");
|
|
|
2322
2404
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2323
2405
|
0 && (module.exports = {
|
|
2324
2406
|
AgentOverChromeBridge,
|
|
2325
|
-
DefaultBridgeServerPort,
|
|
2326
2407
|
allConfigFromEnv,
|
|
2327
2408
|
overrideAIConfig
|
|
2328
2409
|
});
|