@midscene/web 1.17.5-beta-20261102094111.0 → 1.17.5
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/bridge-mode/io-client.mjs +1 -1
- package/dist/es/bridge-mode/io-server.mjs +2 -2
- package/dist/es/bridge-mode/io-server.mjs.map +1 -1
- package/dist/es/bridge-mode/page-browser-side.mjs +1 -1
- package/dist/es/bridge-mode/page-browser-side.mjs.map +1 -1
- package/dist/es/cli.mjs +1 -1
- package/dist/es/playwright/reporter/index.mjs +4 -59
- package/dist/es/playwright/reporter/index.mjs.map +1 -1
- package/dist/es/puppeteer/base-page.mjs +44 -113
- package/dist/es/puppeteer/base-page.mjs.map +1 -1
- package/dist/lib/bridge-mode/io-client.js +1 -1
- package/dist/lib/bridge-mode/io-server.js +2 -2
- package/dist/lib/bridge-mode/io-server.js.map +1 -1
- package/dist/lib/bridge-mode/page-browser-side.js +1 -1
- package/dist/lib/bridge-mode/page-browser-side.js.map +1 -1
- package/dist/lib/cli.js +1 -1
- package/dist/lib/playwright/reporter/index.js +2 -57
- package/dist/lib/playwright/reporter/index.js.map +1 -1
- package/dist/lib/puppeteer/base-page.js +43 -112
- package/dist/lib/puppeteer/base-page.js.map +1 -1
- package/dist/types/playwright/reporter/index.d.ts +0 -2
- package/dist/types/playwright/reporter/index.d.ts.map +1 -1
- package/dist/types/puppeteer/base-page.d.ts +0 -2
- package/dist/types/puppeteer/base-page.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-mode/page-browser-side.js","sources":["webpack/runtime/compat_get_default_export","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/bridge-mode/page-browser-side.ts"],"sourcesContent":["// getDefaultExport function for compatibility with non-ESM modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { assert } from '@midscene/shared/utils';\nimport ChromeExtensionProxyPage from '../chrome-extension/page';\nimport type {\n ChromePageDestroyOptions,\n KeyboardAction,\n MouseAction,\n} from '../web-page';\nimport {\n type BridgeConnectTabOptions,\n BridgeEvent,\n DefaultBridgeServerHost,\n DefaultBridgeServerPort,\n KeyboardEvent,\n MouseEvent,\n} from './common';\nimport { BridgeClient } from './io-client';\n\ndeclare const __VERSION__: string;\n\nconst NEW_TAB_LOAD_TIMEOUT_MS = 30_000;\n\nfunction isBlankUrl(url: string | undefined): boolean {\n if (!url) return true;\n return url === 'about:blank' || url.startsWith('chrome://newtab');\n}\n\n// Wait until the freshly created tab has navigated away from about:blank\n// and reached `status === 'complete'`. Resolves on timeout instead of\n// throwing so callers degrade to the existing lazy-attach behavior.\nfunction waitForTabNavigationComplete(\n tabId: number,\n targetUrl: string,\n timeoutMs = NEW_TAB_LOAD_TIMEOUT_MS,\n): Promise<void> {\n return new Promise((resolve) => {\n let settled = false;\n const finish = () => {\n if (settled) return;\n settled = true;\n try {\n chrome.tabs.onUpdated.removeListener(onUpdated);\n } catch {}\n clearTimeout(timer);\n resolve();\n };\n\n const isReady = (tab: chrome.tabs.Tab | undefined): boolean => {\n if (!tab) return false;\n if (tab.status !== 'complete') return false;\n const currentUrl = tab.url || tab.pendingUrl || '';\n // Skip the initial about:blank \"complete\" that fires before\n // the target URL navigation kicks in.\n if (isBlankUrl(currentUrl) && !isBlankUrl(targetUrl)) return false;\n return true;\n };\n\n const onUpdated = (\n id: number,\n _info: chrome.tabs.TabChangeInfo,\n tab: chrome.tabs.Tab,\n ) => {\n if (id !== tabId) return;\n if (isReady(tab)) finish();\n };\n\n chrome.tabs.onUpdated.addListener(onUpdated);\n const timer = setTimeout(finish, timeoutMs);\n\n // Handle the race where the tab already finished loading before\n // we registered the listener.\n chrome.tabs\n .get(tabId)\n .then((tab) => {\n if (isReady(tab)) finish();\n })\n .catch(() => {});\n });\n}\n\nexport class ExtensionBridgePageBrowserSide extends ChromeExtensionProxyPage {\n public bridgeClient: BridgeClient | null = null;\n\n private destroyOptions?: ChromePageDestroyOptions;\n\n private newlyCreatedTabIds: number[] = [];\n\n // Connection confirmation state\n private confirmationPromise: Promise<boolean> | null = null;\n\n constructor(\n public serverEndpoint?: string,\n public onDisconnect: () => void = () => {},\n public onLogMessage: (\n message: string,\n type: 'log' | 'status',\n ) => void = () => {},\n forceSameTabNavigation = true,\n public onConnectionRequest?: () => Promise<boolean>,\n ) {\n super(forceSameTabNavigation);\n }\n\n private async setupBridgeClient() {\n const endpoint =\n this.serverEndpoint ||\n `ws://${DefaultBridgeServerHost}:${DefaultBridgeServerPort}`;\n\n // Create confirmation gate BEFORE establishing connection,\n // so that any calls received immediately after connection are blocked\n // until user confirms. This prevents a race condition where server-side\n // queued calls bypass the confirmation dialog.\n let resolveConfirmationGate: (allowed: boolean) => void = () => {};\n if (this.onConnectionRequest) {\n this.confirmationPromise = new Promise<boolean>((resolve) => {\n resolveConfirmationGate = resolve;\n });\n }\n\n this.bridgeClient = new BridgeClient(\n endpoint,\n async (method, args: any[]) => {\n // Wait for user confirmation before processing any commands\n if (this.confirmationPromise) {\n const allowed = await this.confirmationPromise;\n if (!allowed) {\n throw new Error('Connection denied by user');\n }\n }\n\n this.onLogMessage(`bridge call from cli side: ${method}`, 'log');\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 // Generic method lookup. Methods like `setWaterFlowAnimationEnabled`\n // and `getWaterFlowAnimationEnabled` are inherited from\n // ChromeExtensionProxyPage and found via `this[method]`.\n if (!this[method as keyof ChromeExtensionProxyPage]) {\n this.onLogMessage(`method not found: ${method}`, 'log');\n return undefined;\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 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\n // Show confirmation dialog after connection is established\n if (this.onConnectionRequest) {\n this.onLogMessage('Waiting for user confirmation...', 'log');\n const allowed = await this.onConnectionRequest();\n resolveConfirmationGate(allowed);\n this.confirmationPromise = null;\n\n if (!allowed) {\n this.onLogMessage('Connection denied by user', 'log');\n this.bridgeClient.disconnect();\n this.bridgeClient = null;\n throw new Error('Connection denied by user');\n }\n }\n\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 // Set the water-flow animation flag BEFORE any debugger commands are\n // sent (which trigger enableWaterFlowAnimation via sendCommandToDebugger).\n // Otherwise the animation gets injected during the connection flow\n // before the CLI side's setWaterFlowAnimationEnabled(false) arrives.\n if (options.enableWaterFlowAnimation !== undefined) {\n this.waterFlowAnimationEnabled = options.enableWaterFlowAnimation;\n }\n\n // Preserve the historical default: activate the new tab unless the caller opts into background mode.\n const activate = options.activateTab ?? true;\n const tab = await chrome.tabs.create({ url, active: activate });\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 // chrome.tabs.create returns immediately with an about:blank target,\n // then navigates to `url`. If we attach the debugger during that\n // cross-origin transition Site Isolation will detach it again, leaving\n // the first CDP command to fail with \"Debugger is not attached to the\n // tab\". Wait for navigation to settle so the lazy attach lands on a\n // stable target.\n await waitForTabNavigationComplete(tabId, url);\n\n await this.setActiveTabId(tabId, { activate });\n }\n\n public async connectCurrentTab(\n options: BridgeConnectTabOptions = {\n forceSameTabNavigation: true,\n },\n ) {\n // Set the water-flow animation flag BEFORE any debugger commands are\n // sent (which trigger enableWaterFlowAnimation via sendCommandToDebugger).\n if (options.enableWaterFlowAnimation !== undefined) {\n this.waterFlowAnimationEnabled = options.enableWaterFlowAnimation;\n }\n\n const tabs = await chrome.tabs.query({ active: true, currentWindow: true });\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"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol","NEW_TAB_LOAD_TIMEOUT_MS","isBlankUrl","url","waitForTabNavigationComplete","tabId","targetUrl","timeoutMs","Promise","resolve","settled","finish","chrome","onUpdated","clearTimeout","timer","isReady","tab","currentUrl","id","_info","setTimeout","ExtensionBridgePageBrowserSide","ChromeExtensionProxyPage","endpoint","DefaultBridgeServerHost","DefaultBridgeServerPort","resolveConfirmationGate","BridgeClient","method","args","allowed","Error","BridgeEvent","MouseEvent","actionName","KeyboardEvent","result","e","errorMessage","options","undefined","activate","assert","tabs","serverEndpoint","onDisconnect","onLogMessage","forceSameTabNavigation","onConnectionRequest"],"mappings":";;;IACAA,oBAAoB,CAAC,GAAG,CAACC;QACxB,IAAIC,SAASD,UAAUA,OAAO,UAAU,GACvC,IAAOA,MAAM,CAAC,UAAU,GACxB,IAAOA;QACRD,oBAAoB,CAAC,CAACE,QAAQ;YAAE,GAAGA;QAAO;QAC1C,OAAOA;IACR;;;ICPAF,oBAAoB,CAAC,GAAG,CAAC,UAASG;QACjC,IAAI,IAAIC,OAA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AAAA,IAAAA,EAAAA,uBAAAA,KAAAA,IAnBR,uBAAO,gBAAP,SAEA,uBAAQ,kBAAR,SAEA,uBAAQ,sBAAR,SAGA,uBAAQ,uBAAR,cAGSH,cAAc,GAAdA,gBAAAA,IAAAA,CACAC,YAAY,GAAZA,cAAAA,IAAAA,CACAC,YAAY,GAAZA,cAAAA,IAAAA,CAKAE,mBAAmB,GAAnBA,qBAAAA,IAAAA,CAjBF,YAAY,GAAwB,WAInC,kBAAkB,GAAa,EAAE,OAGjC,mBAAmB,GAA4B;IAavD;AAuNF"}
|
|
1
|
+
{"version":3,"file":"bridge-mode/page-browser-side.js","sources":["webpack/runtime/compat_get_default_export","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/bridge-mode/page-browser-side.ts"],"sourcesContent":["// getDefaultExport function for compatibility with non-ESM modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { assert } from '@midscene/shared/utils';\nimport ChromeExtensionProxyPage from '../chrome-extension/page';\nimport type {\n ChromePageDestroyOptions,\n KeyboardAction,\n MouseAction,\n} from '../web-page';\nimport {\n type BridgeConnectTabOptions,\n BridgeEvent,\n DefaultBridgeServerHost,\n DefaultBridgeServerPort,\n KeyboardEvent,\n MouseEvent,\n} from './common';\nimport { BridgeClient } from './io-client';\n\ndeclare const __VERSION__: string;\n\nconst NEW_TAB_LOAD_TIMEOUT_MS = 30_000;\n\nfunction isBlankUrl(url: string | undefined): boolean {\n if (!url) return true;\n return url === 'about:blank' || url.startsWith('chrome://newtab');\n}\n\n// Wait until the freshly created tab has navigated away from about:blank\n// and reached `status === 'complete'`. Resolves on timeout instead of\n// throwing so callers degrade to the existing lazy-attach behavior.\nfunction waitForTabNavigationComplete(\n tabId: number,\n targetUrl: string,\n timeoutMs = NEW_TAB_LOAD_TIMEOUT_MS,\n): Promise<void> {\n return new Promise((resolve) => {\n let settled = false;\n const finish = () => {\n if (settled) return;\n settled = true;\n try {\n chrome.tabs.onUpdated.removeListener(onUpdated);\n } catch {}\n clearTimeout(timer);\n resolve();\n };\n\n const isReady = (tab: chrome.tabs.Tab | undefined): boolean => {\n if (!tab) return false;\n if (tab.status !== 'complete') return false;\n const currentUrl = tab.url || tab.pendingUrl || '';\n // Skip the initial about:blank \"complete\" that fires before\n // the target URL navigation kicks in.\n if (isBlankUrl(currentUrl) && !isBlankUrl(targetUrl)) return false;\n return true;\n };\n\n const onUpdated = (\n id: number,\n _info: chrome.tabs.TabChangeInfo,\n tab: chrome.tabs.Tab,\n ) => {\n if (id !== tabId) return;\n if (isReady(tab)) finish();\n };\n\n chrome.tabs.onUpdated.addListener(onUpdated);\n const timer = setTimeout(finish, timeoutMs);\n\n // Handle the race where the tab already finished loading before\n // we registered the listener.\n chrome.tabs\n .get(tabId)\n .then((tab) => {\n if (isReady(tab)) finish();\n })\n .catch(() => {});\n });\n}\n\nexport class ExtensionBridgePageBrowserSide extends ChromeExtensionProxyPage {\n public bridgeClient: BridgeClient | null = null;\n\n private destroyOptions?: ChromePageDestroyOptions;\n\n private newlyCreatedTabIds: number[] = [];\n\n // Connection confirmation state\n private confirmationPromise: Promise<boolean> | null = null;\n\n constructor(\n public serverEndpoint?: string,\n public onDisconnect: () => void = () => {},\n public onLogMessage: (\n message: string,\n type: 'log' | 'status',\n ) => void = () => {},\n forceSameTabNavigation = true,\n public onConnectionRequest?: () => Promise<boolean>,\n ) {\n super(forceSameTabNavigation);\n }\n\n private async setupBridgeClient() {\n const endpoint =\n this.serverEndpoint ||\n `ws://${DefaultBridgeServerHost}:${DefaultBridgeServerPort}`;\n\n // Create confirmation gate BEFORE establishing connection,\n // so that any calls received immediately after connection are blocked\n // until user confirms. This prevents a race condition where server-side\n // queued calls bypass the confirmation dialog.\n let resolveConfirmationGate: (allowed: boolean) => void = () => {};\n if (this.onConnectionRequest) {\n this.confirmationPromise = new Promise<boolean>((resolve) => {\n resolveConfirmationGate = resolve;\n });\n }\n\n this.bridgeClient = new BridgeClient(\n endpoint,\n async (method, args: any[]) => {\n // Wait for user confirmation before processing any commands\n if (this.confirmationPromise) {\n const allowed = await this.confirmationPromise;\n if (!allowed) {\n throw new Error('Connection denied by user');\n }\n }\n\n this.onLogMessage(`bridge call from cli side: ${method}`, 'log');\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 // Generic method lookup. Methods like `setWaterFlowAnimationEnabled`\n // and `getWaterFlowAnimationEnabled` are inherited from\n // ChromeExtensionProxyPage and found via `this[method]`.\n if (!this[method as keyof ChromeExtensionProxyPage]) {\n this.onLogMessage(`method not found: ${method}`, 'log');\n return undefined;\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 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\n // Show confirmation dialog after connection is established\n if (this.onConnectionRequest) {\n this.onLogMessage('Waiting for user confirmation...', 'log');\n const allowed = await this.onConnectionRequest();\n resolveConfirmationGate(allowed);\n this.confirmationPromise = null;\n\n if (!allowed) {\n this.onLogMessage('Connection denied by user', 'log');\n this.bridgeClient.disconnect();\n this.bridgeClient = null;\n throw new Error('Connection denied by user');\n }\n }\n\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 // Set the water-flow animation flag BEFORE any debugger commands are\n // sent (which trigger enableWaterFlowAnimation via sendCommandToDebugger).\n // Otherwise the animation gets injected during the connection flow\n // before the CLI side's setWaterFlowAnimationEnabled(false) arrives.\n if (options.enableWaterFlowAnimation !== undefined) {\n this.waterFlowAnimationEnabled = options.enableWaterFlowAnimation;\n }\n\n // Preserve the historical default: activate the new tab unless the caller opts into background mode.\n const activate = options.activateTab ?? true;\n const tab = await chrome.tabs.create({ url, active: activate });\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 // chrome.tabs.create returns immediately with an about:blank target,\n // then navigates to `url`. If we attach the debugger during that\n // cross-origin transition Site Isolation will detach it again, leaving\n // the first CDP command to fail with \"Debugger is not attached to the\n // tab\". Wait for navigation to settle so the lazy attach lands on a\n // stable target.\n await waitForTabNavigationComplete(tabId, url);\n\n await this.setActiveTabId(tabId, { activate });\n }\n\n public async connectCurrentTab(\n options: BridgeConnectTabOptions = {\n forceSameTabNavigation: true,\n },\n ) {\n // Set the water-flow animation flag BEFORE any debugger commands are\n // sent (which trigger enableWaterFlowAnimation via sendCommandToDebugger).\n if (options.enableWaterFlowAnimation !== undefined) {\n this.waterFlowAnimationEnabled = options.enableWaterFlowAnimation;\n }\n\n const tabs = await chrome.tabs.query({ active: true, currentWindow: true });\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"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol","NEW_TAB_LOAD_TIMEOUT_MS","isBlankUrl","url","waitForTabNavigationComplete","tabId","targetUrl","timeoutMs","Promise","resolve","settled","finish","chrome","onUpdated","clearTimeout","timer","isReady","tab","currentUrl","id","_info","setTimeout","ExtensionBridgePageBrowserSide","ChromeExtensionProxyPage","endpoint","DefaultBridgeServerHost","DefaultBridgeServerPort","resolveConfirmationGate","BridgeClient","method","args","allowed","Error","BridgeEvent","MouseEvent","actionName","KeyboardEvent","result","e","errorMessage","options","undefined","activate","assert","tabs","serverEndpoint","onDisconnect","onLogMessage","forceSameTabNavigation","onConnectionRequest"],"mappings":";;;IACAA,oBAAoB,CAAC,GAAG,CAACC;QACxB,IAAIC,SAASD,UAAUA,OAAO,UAAU,GACvC,IAAOA,MAAM,CAAC,UAAU,GACxB,IAAOA;QACRD,oBAAoB,CAAC,CAACE,QAAQ;YAAE,GAAGA;QAAO;QAC1C,OAAOA;IACR;;;ICPAF,oBAAoB,CAAC,GAAG,CAAC,UAASG;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGH,oBAAoB,CAAC,CAACG,YAAYC,QAAQ,CAACJ,oBAAoB,CAAC,CAAC,UAASI,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAJ,oBAAoB,CAAC,GAAG,CAACM,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFP,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOQ,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;;;;;;;;ACaA,MAAMI,0BAA0B;AAEhC,SAASC,WAAWC,GAAuB;IACzC,IAAI,CAACA,KAAK,OAAO;IACj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;YACvE,IAAI,CAAC,YAAY,CAAC,+CAA+C;YACjE,KAAK,MAAMnC,SAAS,IAAI,CAAC,kBAAkB,CACzC,MAAMO,OAAO,IAAI,CAAC,MAAM,CAACP;YAE3B,IAAI,CAAC,kBAAkB,GAAG,EAAE;QAC9B;QAEA,MAAM,KAAK,CAAC;QAEZ,IAAI,IAAI,CAAC,YAAY,EAAE;YACrB,IAAI,CAAC,YAAY,CAAC,UAAU;YAC5B,IAAI,CAAC,YAAY,GAAG;YACpB,IAAI,CAAC,YAAY;QACnB;IACF;IAjOA,YACSwC,cAAuB,EACvBC,eAA2B,KAAO,CAAC,EACnCC,eAGK,KAAO,CAAC,EACpBC,yBAAyB,IAAI,EACtBC,mBAA4C,CACnD;QACA,KAAK,CAACD,yBAAAA,iBAAAA,IAAAA,EAAAA,kBAAAA,KAAAA,IAAAA,iBAAAA,IAAAA,EAAAA,gBAAAA,KAAAA,IAAAA,iBAAAA,IAAAA,EAAAA,gBAAAA,KAAAA,IAAAA,iBAAAA,IAAAA,EAAAA,uBAAAA,KAAAA,IAnBR,uBAAO,gBAAP,SAEA,uBAAQ,kBAAR,SAEA,uBAAQ,sBAAR,SAGA,uBAAQ,uBAAR,cAGSH,cAAc,GAAdA,gBAAAA,IAAAA,CACAC,YAAY,GAAZA,cAAAA,IAAAA,CACAC,YAAY,GAAZA,cAAAA,IAAAA,CAKAE,mBAAmB,GAAnBA,qBAAAA,IAAAA,CAjBF,YAAY,GAAwB,WAInC,kBAAkB,GAAa,EAAE,OAGjC,mBAAmB,GAA4B;IAavD;AAuNF"}
|
package/dist/lib/cli.js
CHANGED
|
@@ -42,7 +42,7 @@ Promise.resolve().then(()=>{
|
|
|
42
42
|
return (0, cli_namespaceObject.runToolsCLI)(tools, 'midscene-web', {
|
|
43
43
|
stripPrefix: 'web_',
|
|
44
44
|
argv: parsedOptions.argv,
|
|
45
|
-
version: "1.17.5
|
|
45
|
+
version: "1.17.5",
|
|
46
46
|
extraCommands: (0, core_namespaceObject.createReportCliCommands)()
|
|
47
47
|
});
|
|
48
48
|
}).catch((e)=>{
|
|
@@ -27,7 +27,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
default: ()=>reporter
|
|
28
28
|
});
|
|
29
29
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
30
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
31
30
|
const agent_namespaceObject = require("@midscene/core/agent");
|
|
32
31
|
const report_namespaceObject = require("@midscene/core/report");
|
|
33
32
|
const common_namespaceObject = require("@midscene/shared/common");
|
|
@@ -69,43 +68,16 @@ class MidsceneReporter {
|
|
|
69
68
|
}
|
|
70
69
|
throw new Error(`Unknown mode: ${this.mode}`);
|
|
71
70
|
}
|
|
72
|
-
getReportPath(testTitle, testId) {
|
|
73
|
-
const fileName = this.getReportFilename(testTitle, testId);
|
|
74
|
-
if ('html-and-external-assets' === this.outputFormat) return (0, external_node_path_namespaceObject.join)((0, common_namespaceObject.getMidsceneRunSubDir)('report'), fileName, 'index.html');
|
|
75
|
-
return (0, external_node_path_namespaceObject.join)((0, common_namespaceObject.getMidsceneRunSubDir)('report'), `${fileName}.html`);
|
|
76
|
-
}
|
|
77
71
|
ensureOutputRoot() {
|
|
78
72
|
(0, external_node_fs_namespaceObject.mkdirSync)((0, common_namespaceObject.getMidsceneRunSubDir)('report'), {
|
|
79
73
|
recursive: true
|
|
80
74
|
});
|
|
81
75
|
}
|
|
82
|
-
finalizeSingleReport(reportFilePath, targetPath) {
|
|
83
|
-
if ((0, external_node_path_namespaceObject.resolve)(reportFilePath) === (0, external_node_path_namespaceObject.resolve)(targetPath)) return;
|
|
84
|
-
if ((0, report_namespaceObject.isDirectoryModeReport)(reportFilePath)) {
|
|
85
|
-
const targetDir = (0, external_node_path_namespaceObject.dirname)(targetPath);
|
|
86
|
-
(0, external_node_fs_namespaceObject.mkdirSync)(targetDir, {
|
|
87
|
-
recursive: true
|
|
88
|
-
});
|
|
89
|
-
(0, external_node_fs_namespaceObject.cpSync)((0, external_node_path_namespaceObject.dirname)(reportFilePath), targetDir, {
|
|
90
|
-
recursive: true,
|
|
91
|
-
force: true
|
|
92
|
-
});
|
|
93
|
-
} else {
|
|
94
|
-
(0, external_node_fs_namespaceObject.mkdirSync)((0, external_node_path_namespaceObject.dirname)(targetPath), {
|
|
95
|
-
recursive: true
|
|
96
|
-
});
|
|
97
|
-
(0, external_node_fs_namespaceObject.copyFileSync)(reportFilePath, targetPath);
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
(0, report_namespaceObject.removeReportArtifact)(reportFilePath);
|
|
101
|
-
} catch (error) {
|
|
102
|
-
(0, utils_namespaceObject.logMsg)(`Error deleting report ${reportFilePath}: ${error}`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
76
|
mergeOwnedReports(tool, targetName) {
|
|
106
77
|
return tool.mergeReports(targetName, {
|
|
107
78
|
overwrite: true,
|
|
108
|
-
rmOriginalReports: true
|
|
79
|
+
rmOriginalReports: true,
|
|
80
|
+
outputFormat: this.outputFormat
|
|
109
81
|
});
|
|
110
82
|
}
|
|
111
83
|
collectReportInfo(test, result) {
|
|
@@ -146,19 +118,6 @@ class MidsceneReporter {
|
|
|
146
118
|
}
|
|
147
119
|
if (0 === reportCount) return;
|
|
148
120
|
const targetName = this.getReportFilename();
|
|
149
|
-
if (1 === reportCount) {
|
|
150
|
-
const firstReport = Array.from(this.reportsByTestId.values())[0]?.reports[0];
|
|
151
|
-
if (!firstReport) return;
|
|
152
|
-
if (firstReport.reportFilePath) {
|
|
153
|
-
const targetPath = this.getReportPath();
|
|
154
|
-
this.finalizeSingleReport(firstReport.reportFilePath, targetPath);
|
|
155
|
-
(0, agent_namespaceObject.printReportMsg)(targetPath);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const mergedReportPath = this.mergeOwnedReports(tool, targetName);
|
|
159
|
-
if (mergedReportPath) (0, agent_namespaceObject.printReportMsg)(mergedReportPath);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
121
|
const mergedReportPath = this.mergeOwnedReports(tool, targetName);
|
|
163
122
|
if (mergedReportPath) (0, agent_namespaceObject.printReportMsg)(mergedReportPath);
|
|
164
123
|
}
|
|
@@ -166,20 +125,6 @@ class MidsceneReporter {
|
|
|
166
125
|
this.ensureOutputRoot();
|
|
167
126
|
for (const [testId, entry] of this.reportsByTestId){
|
|
168
127
|
const targetName = this.getReportFilename(entry.testTitle, testId);
|
|
169
|
-
if (1 === entry.reports.length) {
|
|
170
|
-
const firstReport = entry.reports[0];
|
|
171
|
-
if (firstReport.reportFilePath) {
|
|
172
|
-
const targetPath = this.getReportPath(entry.testTitle, testId);
|
|
173
|
-
this.finalizeSingleReport(firstReport.reportFilePath, targetPath);
|
|
174
|
-
(0, agent_namespaceObject.printReportMsg)(targetPath);
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
const tool = new report_namespaceObject.ReportMergingTool();
|
|
178
|
-
tool.append(firstReport);
|
|
179
|
-
const reportPath = this.mergeOwnedReports(tool, targetName);
|
|
180
|
-
if (reportPath) (0, agent_namespaceObject.printReportMsg)(reportPath);
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
128
|
const tool = new report_namespaceObject.ReportMergingTool();
|
|
184
129
|
for (const report of entry.reports)tool.append(report);
|
|
185
130
|
const reportPath = this.mergeOwnedReports(tool, targetName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playwright/reporter/index.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/playwright/reporter/index.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { copyFileSync, cpSync, existsSync, mkdirSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport type { ReportFileWithAttributes, TestStatus } from '@midscene/core';\nimport { getReportFileName, printReportMsg } from '@midscene/core/agent';\nimport {\n ReportMergingTool,\n isDirectoryModeReport,\n removeReportArtifact,\n} from '@midscene/core/report';\nimport { getMidsceneRunSubDir } from '@midscene/shared/common';\nimport { logMsg } from '@midscene/shared/utils';\nimport type {\n FullConfig,\n Reporter,\n Suite,\n TestCase,\n TestResult,\n} from '@playwright/test/reporter';\nimport { buildPlaywrightReportTag } from '../report-filename';\n\ninterface MidsceneReporterOptions {\n type?: 'merged' | 'separate';\n outputFormat?: 'single-html' | 'html-and-external-assets';\n}\n\nclass MidsceneReporter implements Reporter {\n private mergedFilename?: string;\n private testIdToFilename = new Map<string, string>();\n private reportsByTestId = new Map<\n string,\n {\n testTitle: string;\n reports: ReportFileWithAttributes[];\n }\n >();\n mode?: 'merged' | 'separate';\n outputFormat: 'single-html' | 'html-and-external-assets';\n private hasMultipleProjects = false;\n\n constructor(options: MidsceneReporterOptions = {}) {\n this.mode = MidsceneReporter.getMode(options.type ?? 'merged');\n this.outputFormat = options.outputFormat ?? 'single-html';\n }\n\n private static getMode(reporterType: string): 'merged' | 'separate' {\n if (!reporterType) {\n return 'merged';\n }\n if (reporterType !== 'merged' && reporterType !== 'separate') {\n throw new Error(\n `Unknown reporter type in playwright config: ${reporterType}, only support 'merged' or 'separate'`,\n );\n }\n return reporterType;\n }\n\n private getSeparatedFilename(testTitle: string, testId: string): string {\n if (!this.testIdToFilename.has(testId)) {\n const baseTag = buildPlaywrightReportTag(testTitle, undefined, testId);\n const generatedFilename = getReportFileName(baseTag);\n this.testIdToFilename.set(testId, generatedFilename);\n }\n return this.testIdToFilename.get(testId)!;\n }\n\n private getReportFilename(testTitle?: string, testId?: string): string {\n if (this.mode === 'merged') {\n if (!this.mergedFilename) {\n this.mergedFilename = getReportFileName('playwright-merged');\n }\n return this.mergedFilename;\n }\n if (this.mode === 'separate') {\n if (!testTitle) throw new Error('testTitle is required in separate mode');\n if (!testId) throw new Error('testId is required in separate mode');\n return this.getSeparatedFilename(testTitle, testId);\n }\n throw new Error(`Unknown mode: ${this.mode}`);\n }\n\n private getReportPath(testTitle?: string, testId?: string): string {\n const fileName = this.getReportFilename(testTitle, testId);\n if (this.outputFormat === 'html-and-external-assets') {\n return join(getMidsceneRunSubDir('report'), fileName, 'index.html');\n }\n return join(getMidsceneRunSubDir('report'), `${fileName}.html`);\n }\n\n private ensureOutputRoot(): void {\n mkdirSync(getMidsceneRunSubDir('report'), { recursive: true });\n }\n\n private finalizeSingleReport(\n reportFilePath: string,\n targetPath: string,\n ): void {\n if (resolve(reportFilePath) === resolve(targetPath)) {\n return;\n }\n\n if (isDirectoryModeReport(reportFilePath)) {\n const targetDir = dirname(targetPath);\n mkdirSync(targetDir, { recursive: true });\n cpSync(dirname(reportFilePath), targetDir, {\n recursive: true,\n force: true,\n });\n } else {\n mkdirSync(dirname(targetPath), { recursive: true });\n copyFileSync(reportFilePath, targetPath);\n }\n\n try {\n removeReportArtifact(reportFilePath);\n } catch (error) {\n logMsg(`Error deleting report ${reportFilePath}: ${error}`);\n }\n }\n\n private mergeOwnedReports(\n tool: ReportMergingTool,\n targetName: string,\n ): string | null {\n return tool.mergeReports(targetName, {\n overwrite: true,\n rmOriginalReports: true,\n });\n }\n\n private collectReportInfo(test: TestCase, result: TestResult) {\n const reportAnnotations = test.annotations.filter((annotation) => {\n return (\n annotation.type === 'MIDSCENE_DUMP_ANNOTATION' && annotation.description\n );\n });\n if (reportAnnotations.length === 0 || !this.mode) {\n return;\n }\n\n const retry = result.retry ? `(retry #${result.retry})` : '';\n const testId = `${test.id}${retry}`;\n const projectName = this.hasMultipleProjects\n ? test.parent?.project()?.name\n : undefined;\n const projectSuffix = projectName ? ` [${projectName}]` : '';\n const testTitle = `${test.title}${projectSuffix}${retry}`;\n const reports = reportAnnotations\n .map((annotation) => annotation.description!)\n .filter((reportFilePath) => {\n if (existsSync(reportFilePath)) {\n return true;\n }\n logMsg(\n `Failed to read Midscene report file: ${reportFilePath}`,\n new Error('Report file does not exist'),\n );\n return false;\n })\n .map((reportFilePath): ReportFileWithAttributes => {\n return {\n reportFilePath,\n reportAttributes: {\n testDuration: result.duration,\n testStatus: result.status as TestStatus,\n testTitle,\n testId,\n testDescription: test.parent?.title || '',\n },\n };\n });\n\n if (reports.length === 0) {\n return;\n }\n\n this.reportsByTestId.set(testId, {\n testTitle,\n reports,\n });\n }\n\n private finalizeMergedReport(): void {\n this.ensureOutputRoot();\n const tool = new ReportMergingTool();\n let reportCount = 0;\n for (const entry of this.reportsByTestId.values()) {\n for (const report of entry.reports) {\n tool.append(report);\n reportCount += 1;\n }\n }\n\n if (reportCount === 0) {\n return;\n }\n\n const targetName = this.getReportFilename();\n if (reportCount === 1) {\n const firstReport = Array.from(this.reportsByTestId.values())[0]\n ?.reports[0];\n if (!firstReport) {\n return;\n }\n if (firstReport.reportFilePath) {\n const targetPath = this.getReportPath();\n this.finalizeSingleReport(firstReport.reportFilePath, targetPath);\n printReportMsg(targetPath);\n return;\n }\n\n const mergedReportPath = this.mergeOwnedReports(tool, targetName);\n if (mergedReportPath) {\n printReportMsg(mergedReportPath);\n }\n return;\n }\n\n const mergedReportPath = this.mergeOwnedReports(tool, targetName);\n if (mergedReportPath) {\n printReportMsg(mergedReportPath);\n }\n }\n\n private finalizeSeparateReports(): void {\n this.ensureOutputRoot();\n for (const [testId, entry] of this.reportsByTestId) {\n const targetName = this.getReportFilename(entry.testTitle, testId);\n if (entry.reports.length === 1) {\n const firstReport = entry.reports[0];\n if (firstReport.reportFilePath) {\n const targetPath = this.getReportPath(entry.testTitle, testId);\n this.finalizeSingleReport(firstReport.reportFilePath, targetPath);\n printReportMsg(targetPath);\n continue;\n }\n\n const tool = new ReportMergingTool();\n tool.append(firstReport);\n const reportPath = this.mergeOwnedReports(tool, targetName);\n if (reportPath) {\n printReportMsg(reportPath);\n }\n continue;\n }\n\n const tool = new ReportMergingTool();\n for (const report of entry.reports) {\n tool.append(report);\n }\n const reportPath = this.mergeOwnedReports(tool, targetName);\n if (reportPath) {\n printReportMsg(reportPath);\n }\n }\n }\n\n async onBegin(config: FullConfig, _suite: Suite) {\n this.hasMultipleProjects = (config.projects?.length || 0) > 1;\n }\n\n onTestBegin(_test: TestCase, _result: TestResult) {}\n\n onTestEnd(test: TestCase, result: TestResult) {\n this.collectReportInfo(test, result);\n }\n\n async onEnd() {\n if (this.mode === 'merged') {\n this.finalizeMergedReport();\n return;\n }\n\n if (this.mode === 'separate') {\n this.finalizeSeparateReports();\n }\n }\n}\n\nexport default MidsceneReporter;\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","MidsceneReporter","reporterType","Error","testTitle","testId","baseTag","buildPlaywrightReportTag","undefined","generatedFilename","getReportFileName","fileName","join","getMidsceneRunSubDir","mkdirSync","reportFilePath","targetPath","resolve","isDirectoryModeReport","targetDir","dirname","cpSync","copyFileSync","removeReportArtifact","error","logMsg","tool","targetName","test","result","reportAnnotations","annotation","retry","projectName","projectSuffix","reports","existsSync","ReportMergingTool","reportCount","entry","report","firstReport","Array","printReportMsg","mergedReportPath","reportPath","config","_suite","_test","_result","options","Map"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI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EC,MAAkB,EAAE;QAC5C,IAAI,CAAC,iBAAiB,CAACD,MAAMC;IAC/B;IAEA,MAAM,QAAQ;QACZ,IAAI,AAAc,aAAd,IAAI,CAAC,IAAI,EAAe,YAC1B,IAAI,CAAC,oBAAoB;QAI3B,IAAI,AAAc,eAAd,IAAI,CAAC,IAAI,EACX,IAAI,CAAC,uBAAuB;IAEhC;IA5OA,YAAYqB,UAAmC,CAAC,CAAC,CAAE;QAbnD,uBAAQ,kBAAR;QACA,uBAAQ,oBAAmB,IAAIC;QAC/B,uBAAQ,mBAAkB,IAAIA;QAO9B;QACA;QACA,uBAAQ,uBAAsB;QAG5B,IAAI,CAAC,IAAI,GAAGlD,iBAAiB,OAAO,CAACiD,QAAQ,IAAI,IAAI;QACrD,IAAI,CAAC,YAAY,GAAGA,QAAQ,YAAY,IAAI;IAC9C;AA0OF;AAEA,iBAAejD"}
|
|
1
|
+
{"version":3,"file":"playwright/reporter/index.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/playwright/reporter/index.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { existsSync, mkdirSync } from 'node:fs';\nimport type { ReportFileWithAttributes, TestStatus } from '@midscene/core';\nimport { getReportFileName, printReportMsg } from '@midscene/core/agent';\nimport { ReportMergingTool } from '@midscene/core/report';\nimport { getMidsceneRunSubDir } from '@midscene/shared/common';\nimport { logMsg } from '@midscene/shared/utils';\nimport type {\n FullConfig,\n Reporter,\n Suite,\n TestCase,\n TestResult,\n} from '@playwright/test/reporter';\nimport { buildPlaywrightReportTag } from '../report-filename';\n\ninterface MidsceneReporterOptions {\n type?: 'merged' | 'separate';\n outputFormat?: 'single-html' | 'html-and-external-assets';\n}\n\nclass MidsceneReporter implements Reporter {\n private mergedFilename?: string;\n private testIdToFilename = new Map<string, string>();\n private reportsByTestId = new Map<\n string,\n {\n testTitle: string;\n reports: ReportFileWithAttributes[];\n }\n >();\n mode?: 'merged' | 'separate';\n outputFormat: 'single-html' | 'html-and-external-assets';\n private hasMultipleProjects = false;\n\n constructor(options: MidsceneReporterOptions = {}) {\n this.mode = MidsceneReporter.getMode(options.type ?? 'merged');\n this.outputFormat = options.outputFormat ?? 'single-html';\n }\n\n private static getMode(reporterType: string): 'merged' | 'separate' {\n if (!reporterType) {\n return 'merged';\n }\n if (reporterType !== 'merged' && reporterType !== 'separate') {\n throw new Error(\n `Unknown reporter type in playwright config: ${reporterType}, only support 'merged' or 'separate'`,\n );\n }\n return reporterType;\n }\n\n private getSeparatedFilename(testTitle: string, testId: string): string {\n if (!this.testIdToFilename.has(testId)) {\n const baseTag = buildPlaywrightReportTag(testTitle, undefined, testId);\n const generatedFilename = getReportFileName(baseTag);\n this.testIdToFilename.set(testId, generatedFilename);\n }\n return this.testIdToFilename.get(testId)!;\n }\n\n private getReportFilename(testTitle?: string, testId?: string): string {\n if (this.mode === 'merged') {\n if (!this.mergedFilename) {\n this.mergedFilename = getReportFileName('playwright-merged');\n }\n return this.mergedFilename;\n }\n if (this.mode === 'separate') {\n if (!testTitle) throw new Error('testTitle is required in separate mode');\n if (!testId) throw new Error('testId is required in separate mode');\n return this.getSeparatedFilename(testTitle, testId);\n }\n throw new Error(`Unknown mode: ${this.mode}`);\n }\n\n private ensureOutputRoot(): void {\n mkdirSync(getMidsceneRunSubDir('report'), { recursive: true });\n }\n\n private mergeOwnedReports(\n tool: ReportMergingTool,\n targetName: string,\n ): string | null {\n return tool.mergeReports(targetName, {\n overwrite: true,\n rmOriginalReports: true,\n outputFormat: this.outputFormat,\n });\n }\n\n private collectReportInfo(test: TestCase, result: TestResult) {\n const reportAnnotations = test.annotations.filter((annotation) => {\n return (\n annotation.type === 'MIDSCENE_DUMP_ANNOTATION' && annotation.description\n );\n });\n if (reportAnnotations.length === 0 || !this.mode) {\n return;\n }\n\n const retry = result.retry ? `(retry #${result.retry})` : '';\n const testId = `${test.id}${retry}`;\n const projectName = this.hasMultipleProjects\n ? test.parent?.project()?.name\n : undefined;\n const projectSuffix = projectName ? ` [${projectName}]` : '';\n const testTitle = `${test.title}${projectSuffix}${retry}`;\n const reports = reportAnnotations\n .map((annotation) => annotation.description!)\n .filter((reportFilePath) => {\n if (existsSync(reportFilePath)) {\n return true;\n }\n logMsg(\n `Failed to read Midscene report file: ${reportFilePath}`,\n new Error('Report file does not exist'),\n );\n return false;\n })\n .map((reportFilePath): ReportFileWithAttributes => {\n return {\n reportFilePath,\n reportAttributes: {\n testDuration: result.duration,\n testStatus: result.status as TestStatus,\n testTitle,\n testId,\n testDescription: test.parent?.title || '',\n },\n };\n });\n\n if (reports.length === 0) {\n return;\n }\n\n this.reportsByTestId.set(testId, {\n testTitle,\n reports,\n });\n }\n\n private finalizeMergedReport(): void {\n this.ensureOutputRoot();\n const tool = new ReportMergingTool();\n let reportCount = 0;\n for (const entry of this.reportsByTestId.values()) {\n for (const report of entry.reports) {\n tool.append(report);\n reportCount += 1;\n }\n }\n\n if (reportCount === 0) {\n return;\n }\n\n const targetName = this.getReportFilename();\n const mergedReportPath = this.mergeOwnedReports(tool, targetName);\n if (mergedReportPath) {\n printReportMsg(mergedReportPath);\n }\n }\n\n private finalizeSeparateReports(): void {\n this.ensureOutputRoot();\n for (const [testId, entry] of this.reportsByTestId) {\n const targetName = this.getReportFilename(entry.testTitle, testId);\n const tool = new ReportMergingTool();\n for (const report of entry.reports) {\n tool.append(report);\n }\n const reportPath = this.mergeOwnedReports(tool, targetName);\n if (reportPath) {\n printReportMsg(reportPath);\n }\n }\n }\n\n async onBegin(config: FullConfig, _suite: Suite) {\n this.hasMultipleProjects = (config.projects?.length || 0) > 1;\n }\n\n onTestBegin(_test: TestCase, _result: TestResult) {}\n\n onTestEnd(test: TestCase, result: TestResult) {\n this.collectReportInfo(test, result);\n }\n\n async onEnd() {\n if (this.mode === 'merged') {\n this.finalizeMergedReport();\n return;\n }\n\n if (this.mode === 'separate') {\n this.finalizeSeparateReports();\n }\n }\n}\n\nexport default MidsceneReporter;\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","MidsceneReporter","reporterType","Error","testTitle","testId","baseTag","buildPlaywrightReportTag","undefined","generatedFilename","getReportFileName","mkdirSync","getMidsceneRunSubDir","tool","targetName","test","result","reportAnnotations","annotation","retry","projectName","projectSuffix","reports","reportFilePath","existsSync","logMsg","ReportMergingTool","reportCount","entry","report","mergedReportPath","printReportMsg","reportPath","config","_suite","_test","_result","options","Map"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;;;;;;;;;ACcA,MAAMI;IAmBJ,OAAe,QAAQC,YAAo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AAd,IAAI,CAAC,IAAI,EAAe,YAC1B,IAAI,CAAC,oBAAoB;QAI3B,IAAI,AAAc,eAAd,IAAI,CAAC,IAAI,EACX,IAAI,CAAC,uBAAuB;IAEhC;IApKA,YAAYqB,UAAmC,CAAC,CAAC,CAAE;QAbnD,uBAAQ,kBAAR;QACA,uBAAQ,oBAAmB,IAAIC;QAC/B,uBAAQ,mBAAkB,IAAIA;QAO9B;QACA;QACA,uBAAQ,uBAAsB;QAG5B,IAAI,CAAC,IAAI,GAAGrC,iBAAiB,OAAO,CAACoC,QAAQ,IAAI,IAAI;QACrD,IAAI,CAAC,YAAY,GAAGA,QAAQ,YAAY,IAAI;IAC9C;AAkKF;AAEA,iBAAepC"}
|
|
@@ -227,59 +227,35 @@ class Page {
|
|
|
227
227
|
const imgType = 'jpeg';
|
|
228
228
|
const quality = 90;
|
|
229
229
|
const startTime = Date.now();
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
230
|
+
debugPage('screenshotBase64 begin');
|
|
231
|
+
let base64;
|
|
232
|
+
if ('puppeteer' === this.interfaceType) {
|
|
233
|
+
const result = await (0, external_screenshot_js_namespaceObject.capturePuppeteerScreenshot)(this.underlyingPage, {
|
|
234
|
+
type: imgType,
|
|
235
|
+
quality,
|
|
236
|
+
encoding: 'base64'
|
|
237
|
+
});
|
|
238
|
+
base64 = (0, img_namespaceObject.createImgBase64ByFormat)(imgType, result);
|
|
239
|
+
} else if ('playwright' === this.interfaceType) {
|
|
240
|
+
const page = this.underlyingPage;
|
|
241
|
+
try {
|
|
242
|
+
const buffer = await page.screenshot({
|
|
240
243
|
type: imgType,
|
|
241
244
|
quality,
|
|
242
|
-
|
|
245
|
+
timeout: 10000
|
|
243
246
|
});
|
|
244
|
-
base64 = (0, img_namespaceObject.createImgBase64ByFormat)(imgType,
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
257
|
-
warnPage(`[Midscene] Playwright screenshot failed: ${errorMsg}. Falling back to CDP screenshot.`);
|
|
258
|
-
debugPage('playwright screenshot failed, trying CDP fallback: %s', error);
|
|
259
|
-
source = 'cdp-fallback';
|
|
260
|
-
debugPage('screenshotBase64 fallback %o', {
|
|
261
|
-
...operation,
|
|
262
|
-
source
|
|
263
|
-
});
|
|
264
|
-
base64 = await this.screenshotBase64ByPlaywrightCdp(imgType, quality);
|
|
265
|
-
}
|
|
266
|
-
} else throw new Error('Unsupported page type for screenshot');
|
|
267
|
-
const endTime = Date.now();
|
|
268
|
-
debugPage('screenshotBase64 end %o', {
|
|
269
|
-
...operation,
|
|
270
|
-
source,
|
|
271
|
-
durationMs: endTime - startTime,
|
|
272
|
-
screenshotHash: (0, shared_utils_namespaceObject.sha256Hex)(base64).slice(0, 16)
|
|
273
|
-
});
|
|
274
|
-
return base64;
|
|
275
|
-
} catch (error) {
|
|
276
|
-
debugPage('screenshotBase64 error %o', {
|
|
277
|
-
...operation,
|
|
278
|
-
source,
|
|
279
|
-
errorName: error instanceof Error ? error.name : 'UnknownError'
|
|
280
|
-
});
|
|
281
|
-
throw error;
|
|
282
|
-
}
|
|
247
|
+
base64 = (0, img_namespaceObject.createImgBase64ByFormat)(imgType, buffer.toString('base64'));
|
|
248
|
+
} catch (error) {
|
|
249
|
+
if (isClosedPageError(error) || page.isClosed()) throw error;
|
|
250
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
251
|
+
console.warn(`[Midscene] Playwright screenshot failed: ${errorMsg}. Falling back to CDP screenshot.`);
|
|
252
|
+
debugPage('playwright screenshot failed, trying CDP fallback: %s', error);
|
|
253
|
+
base64 = await this.screenshotBase64ByPlaywrightCdp(imgType, quality);
|
|
254
|
+
}
|
|
255
|
+
} else throw new Error('Unsupported page type for screenshot');
|
|
256
|
+
const endTime = Date.now();
|
|
257
|
+
debugPage(`screenshotBase64 end, cost: ${endTime - startTime}ms`);
|
|
258
|
+
return base64;
|
|
283
259
|
}
|
|
284
260
|
async screenshotBase64ByPlaywrightCdp(imgType, quality) {
|
|
285
261
|
const client = await this.createPageCdpSession('CDP screenshot fallback');
|
|
@@ -576,47 +552,23 @@ class Page {
|
|
|
576
552
|
get mouse() {
|
|
577
553
|
return {
|
|
578
554
|
click: async (x, y, options)=>{
|
|
579
|
-
|
|
580
|
-
const operation = {
|
|
581
|
-
pageId: this.diagnosticPageId,
|
|
582
|
-
operationId: ++this.diagnosticOperationSequence
|
|
583
|
-
};
|
|
584
|
-
debugPage('mouse click begin %o', operation);
|
|
555
|
+
await this.mouse.move(x, y);
|
|
585
556
|
const { button = 'left', count = 1 } = options || {};
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
557
|
+
debugPage(`mouse click ${x}, ${y}, ${button}, ${count}`);
|
|
558
|
+
if (2 === count && 'playwright' === this.interfaceType) await this.underlyingPage.mouse.dblclick(x, y, {
|
|
559
|
+
button
|
|
560
|
+
});
|
|
561
|
+
else if ('puppeteer' === this.interfaceType) {
|
|
562
|
+
const page = this.underlyingPage;
|
|
563
|
+
if ('left' === button && 1 === count) await page.mouse.click(x, y);
|
|
564
|
+
else await page.mouse.click(x, y, {
|
|
592
565
|
button,
|
|
593
566
|
count
|
|
594
567
|
});
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
const page = this.underlyingPage;
|
|
600
|
-
if ('left' === button && 1 === count) await page.mouse.click(x, y);
|
|
601
|
-
else await page.mouse.click(x, y, {
|
|
602
|
-
button,
|
|
603
|
-
count
|
|
604
|
-
});
|
|
605
|
-
} else if ('playwright' === this.interfaceType) await this.underlyingPage.mouse.click(x, y, {
|
|
606
|
-
button,
|
|
607
|
-
clickCount: count
|
|
608
|
-
});
|
|
609
|
-
debugPage('mouse click returned %o', {
|
|
610
|
-
...operation,
|
|
611
|
-
durationMs: Date.now() - startedAt
|
|
612
|
-
});
|
|
613
|
-
} catch (error) {
|
|
614
|
-
debugPage('mouse click error %o', {
|
|
615
|
-
...operation,
|
|
616
|
-
errorName: error instanceof Error ? error.name : 'UnknownError'
|
|
617
|
-
});
|
|
618
|
-
throw error;
|
|
619
|
-
}
|
|
568
|
+
} else if ('playwright' === this.interfaceType) await this.underlyingPage.mouse.click(x, y, {
|
|
569
|
+
button,
|
|
570
|
+
clickCount: count
|
|
571
|
+
});
|
|
620
572
|
},
|
|
621
573
|
wheel: async (deltaX, deltaY)=>{
|
|
622
574
|
debugPage(`mouse wheel ${deltaX}, ${deltaY}`);
|
|
@@ -855,29 +807,10 @@ class Page {
|
|
|
855
807
|
if (this.onBeforeInvokeAction) await this.onBeforeInvokeAction(name, param);
|
|
856
808
|
}
|
|
857
809
|
async defaultActionWait(name, _param) {
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
actionName: name
|
|
863
|
-
};
|
|
864
|
-
debugPage('defaultActionWait begin %o', operation);
|
|
865
|
-
try {
|
|
866
|
-
await Promise.all([
|
|
867
|
-
this.waitForNavigation('afterInvokeAction', name),
|
|
868
|
-
this.waitForNetworkIdle('afterInvokeAction', name)
|
|
869
|
-
]);
|
|
870
|
-
debugPage('defaultActionWait end %o', {
|
|
871
|
-
...operation,
|
|
872
|
-
durationMs: Date.now() - startedAt
|
|
873
|
-
});
|
|
874
|
-
} catch (error) {
|
|
875
|
-
debugPage('defaultActionWait error %o', {
|
|
876
|
-
...operation,
|
|
877
|
-
errorName: error instanceof Error ? error.name : 'UnknownError'
|
|
878
|
-
});
|
|
879
|
-
throw error;
|
|
880
|
-
}
|
|
810
|
+
await Promise.all([
|
|
811
|
+
this.waitForNavigation('afterInvokeAction', name),
|
|
812
|
+
this.waitForNetworkIdle('afterInvokeAction', name)
|
|
813
|
+
]);
|
|
881
814
|
}
|
|
882
815
|
async afterInvokeAction(name, param) {
|
|
883
816
|
if (this.onAfterInvokeAction) await this.onAfterInvokeAction(name, param);
|
|
@@ -1053,8 +986,6 @@ class Page {
|
|
|
1053
986
|
}
|
|
1054
987
|
constructor(underlyingPage, interfaceType, opts){
|
|
1055
988
|
_define_property(this, "underlyingPage", void 0);
|
|
1056
|
-
_define_property(this, "diagnosticPageId", (0, shared_utils_namespaceObject.uuid)());
|
|
1057
|
-
_define_property(this, "diagnosticOperationSequence", 0);
|
|
1058
989
|
_define_property(this, "waitForNavigationTimeout", void 0);
|
|
1059
990
|
_define_property(this, "waitForNetworkIdleTimeout", void 0);
|
|
1060
991
|
_define_property(this, "viewportSize", void 0);
|