@midscene/web 1.7.5-beta-20260421030751.0 → 1.7.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.
Files changed (46) hide show
  1. package/dist/es/bridge-mode/io-client.mjs +1 -1
  2. package/dist/es/bridge-mode/io-server.mjs +2 -2
  3. package/dist/es/bridge-mode/io-server.mjs.map +1 -1
  4. package/dist/es/bridge-mode/page-browser-side.mjs +1 -1
  5. package/dist/es/bridge-mode/page-browser-side.mjs.map +1 -1
  6. package/dist/es/cdp-proxy-manager.mjs +219 -0
  7. package/dist/es/cdp-proxy-manager.mjs.map +1 -0
  8. package/dist/es/cdp-target-store.mjs +28 -0
  9. package/dist/es/cdp-target-store.mjs.map +1 -0
  10. package/dist/es/cli.mjs +3 -4
  11. package/dist/es/cli.mjs.map +1 -1
  12. package/dist/es/mcp-server.mjs +1 -1
  13. package/dist/es/mcp-tools-cdp.mjs +4 -218
  14. package/dist/es/mcp-tools-cdp.mjs.map +1 -1
  15. package/dist/es/mcp-tools-puppeteer.mjs +2 -1
  16. package/dist/es/mcp-tools-puppeteer.mjs.map +1 -1
  17. package/dist/es/mcp-tools.mjs +1 -1
  18. package/dist/es/mcp-tools.mjs.map +1 -1
  19. package/dist/es/playwright/ai-fixture.mjs +3 -3
  20. package/dist/es/playwright/ai-fixture.mjs.map +1 -1
  21. package/dist/lib/bridge-mode/io-client.js +1 -1
  22. package/dist/lib/bridge-mode/io-server.js +2 -2
  23. package/dist/lib/bridge-mode/io-server.js.map +1 -1
  24. package/dist/lib/bridge-mode/page-browser-side.js +1 -1
  25. package/dist/lib/bridge-mode/page-browser-side.js.map +1 -1
  26. package/dist/lib/cdp-proxy-manager.js +275 -0
  27. package/dist/lib/cdp-proxy-manager.js.map +1 -0
  28. package/dist/lib/cdp-target-store.js +68 -0
  29. package/dist/lib/cdp-target-store.js.map +1 -0
  30. package/dist/lib/cli.js +2 -3
  31. package/dist/lib/cli.js.map +1 -1
  32. package/dist/lib/mcp-server.js +1 -1
  33. package/dist/lib/mcp-tools-cdp.js +9 -227
  34. package/dist/lib/mcp-tools-cdp.js.map +1 -1
  35. package/dist/lib/mcp-tools-puppeteer.js +4 -3
  36. package/dist/lib/mcp-tools-puppeteer.js.map +1 -1
  37. package/dist/lib/mcp-tools.js +2 -2
  38. package/dist/lib/mcp-tools.js.map +1 -1
  39. package/dist/lib/playwright/ai-fixture.js +3 -3
  40. package/dist/lib/playwright/ai-fixture.js.map +1 -1
  41. package/dist/types/cdp-proxy-manager.d.ts +53 -0
  42. package/dist/types/cdp-target-store.d.ts +26 -0
  43. package/dist/types/mcp-tools-cdp.d.ts +2 -32
  44. package/dist/types/mcp-tools-puppeteer.d.ts +2 -1
  45. package/dist/types/mcp-tools.d.ts +2 -1
  46. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"playwright/ai-fixture.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/playwright/ai-fixture.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 { PlaywrightAgent, type PlaywrightWebPage } from '@/playwright/index';\nimport type { WebPageAgentOpt } from '@/web-element';\nimport type { Cache } from '@midscene/core';\nimport type { Agent as PageAgent } from '@midscene/core/agent';\nimport { processCacheConfig } from '@midscene/core/utils';\nimport {\n DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT,\n DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT,\n} from '@midscene/shared/constants';\nimport { getDebug } from '@midscene/shared/logger';\nimport { uuid } from '@midscene/shared/utils';\nimport { replaceIllegalPathCharsAndSpace } from '@midscene/shared/utils';\nimport { type TestInfo, type TestType, test } from '@playwright/test';\nimport type { Page as OriginPlaywrightPage } from 'playwright';\nexport type APITestType = Pick<TestType<any, any>, 'step'>;\n\nconst debugPage = getDebug('web:playwright:ai-fixture');\n\nconst groupAndCaseForTest = (testInfo: TestInfo) => {\n let taskFile: string;\n let taskTitle: string;\n const titlePath = [...testInfo.titlePath];\n\n if (titlePath.length > 1) {\n taskFile = titlePath.shift() || 'unnamed';\n taskTitle = titlePath.join('__');\n } else if (titlePath.length === 1) {\n taskTitle = titlePath[0];\n taskFile = `${taskTitle}`;\n } else {\n taskTitle = 'unnamed';\n taskFile = 'unnamed';\n }\n\n const taskTitleWithRetry = `${taskTitle}${testInfo.retry ? `(retry #${testInfo.retry})` : ''}`;\n\n return {\n file: taskFile,\n id: replaceIllegalPathCharsAndSpace(`${taskFile}(${taskTitle})`),\n title: replaceIllegalPathCharsAndSpace(taskTitleWithRetry),\n };\n};\n\nconst midsceneAgentKeyId = '_midsceneAgentId';\nexport const midsceneDumpAnnotationId = 'MIDSCENE_DUMP_ANNOTATION';\n\ntype AgentRecord = {\n agent: PageAgent<PlaywrightWebPage>;\n finalizePromise?: Promise<string | undefined>;\n finalReportPath?: string;\n};\n\ntype PlaywrightCacheConfig = {\n strategy?: 'read-only' | 'read-write' | 'write-only';\n id?: string;\n};\ntype PlaywrightCache = false | true | PlaywrightCacheConfig;\n\nexport type PlaywrightAiFixtureOptions = Omit<\n WebPageAgentOpt,\n | 'testId'\n | 'cacheId'\n | 'groupName'\n | 'groupDescription'\n | 'reportFileName'\n | 'cache'\n> & {\n cache?: PlaywrightCache;\n};\n\nexport const PlaywrightAiFixture = (options?: PlaywrightAiFixtureOptions) => {\n const {\n forceSameTabNavigation = true,\n waitForNetworkIdleTimeout = DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT,\n waitForNavigationTimeout = DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT,\n cache,\n ...sharedAgentOptions\n } = options ?? {};\n\n // Helper function to process cache configuration and auto-generate ID from test info\n const processTestCacheConfig = (testInfo: TestInfo): Cache | undefined => {\n // Generate ID from test info\n const { id } = groupAndCaseForTest(testInfo);\n\n // Use shared processCacheConfig with generated ID as fallback\n return processCacheConfig(cache as Cache, id);\n };\n\n const pageAgentMap: Record<string, PageAgent<PlaywrightWebPage>> = {};\n const testAgentRecords = new Map<string, Map<string, AgentRecord>>();\n\n const getAgentRecordsForTest = (testInfo: TestInfo) => {\n let records = testAgentRecords.get(testInfo.testId);\n if (!records) {\n records = new Map<string, AgentRecord>();\n testAgentRecords.set(testInfo.testId, records);\n }\n return records;\n };\n\n const setReportAnnotation = (testInfo: TestInfo, reportPaths: string[]) => {\n testInfo.annotations = testInfo.annotations.filter((item) => {\n return item.type !== midsceneDumpAnnotationId;\n });\n\n for (const reportPath of reportPaths) {\n testInfo.annotations.push({\n type: midsceneDumpAnnotationId,\n description: reportPath,\n });\n }\n };\n\n const finalizeAgentRecord = async (\n record: AgentRecord,\n ): Promise<string | undefined> => {\n if (!record.finalizePromise) {\n record.finalizePromise = (async () => {\n await record.agent.destroy();\n const reportPath = record.agent.reportFile || undefined;\n record.finalReportPath = reportPath;\n return reportPath;\n })();\n }\n\n return await record.finalizePromise;\n };\n\n const createOrReuseAgentForPage = (\n page: OriginPlaywrightPage,\n testInfo: TestInfo, // { testId: string; taskFile: string; taskTitle: string },\n opts?: WebPageAgentOpt,\n ) => {\n let idForPage = (page as any)[midsceneAgentKeyId];\n if (!idForPage) {\n idForPage = uuid();\n (page as any)[midsceneAgentKeyId] = idForPage;\n const { testId } = testInfo;\n const { file, title } = groupAndCaseForTest(testInfo);\n const cacheConfig = processTestCacheConfig(testInfo);\n\n const agent = new PlaywrightAgent(page, {\n testId: `playwright-${testId}-${idForPage}`,\n reportFileName: `playwright-${testId}-${idForPage}`,\n forceSameTabNavigation,\n cache: cacheConfig,\n groupName: title,\n groupDescription: file,\n generateReport: true,\n ...sharedAgentOptions,\n ...opts,\n });\n pageAgentMap[idForPage] = agent;\n const records = getAgentRecordsForTest(testInfo);\n const record: AgentRecord = { agent };\n records.set(idForPage, record);\n\n page.on('close', async () => {\n debugPage('page closed');\n try {\n await finalizeAgentRecord(record);\n } finally {\n delete pageAgentMap[idForPage];\n }\n });\n }\n\n return pageAgentMap[idForPage];\n };\n\n async function generateAiFunction(options: {\n page: OriginPlaywrightPage;\n testInfo: TestInfo;\n use: any;\n aiActionType:\n | 'ai'\n | 'aiAct'\n | 'aiAction'\n | 'aiHover'\n | 'aiInput'\n | 'aiKeyboardPress'\n | 'aiScroll'\n | 'aiTap'\n | 'aiRightClick'\n | 'aiDoubleClick'\n | 'aiQuery'\n | 'aiAssert'\n | 'aiWaitFor'\n | 'aiLocate'\n | 'aiNumber'\n | 'aiString'\n | 'aiBoolean'\n | 'aiAsk'\n | 'runYaml'\n | 'setAIActionContext'\n | 'evaluateJavaScript'\n | 'recordToReport'\n | 'logScreenshot'\n | 'freezePageContext'\n | 'unfreezePageContext';\n }) {\n const { page, testInfo, use, aiActionType } = options;\n const agent = createOrReuseAgentForPage(page, testInfo, {\n waitForNavigationTimeout,\n waitForNetworkIdleTimeout,\n }) as PlaywrightAgent;\n\n await use(async (taskPrompt: string, ...args: any[]) => {\n return new Promise((resolve, reject) => {\n test.step(`ai-${aiActionType} - ${JSON.stringify(taskPrompt)}`, async () => {\n try {\n debugPage(\n `waitForNetworkIdle timeout: ${waitForNetworkIdleTimeout}`,\n );\n await agent.waitForNetworkIdle(waitForNetworkIdleTimeout);\n } catch (error) {\n console.warn(\n '[midscene:warning] Waiting for network idle has timed out, but Midscene will continue execution. Please check https://midscenejs.com/faq.html#customize-the-network-timeout for more information on customizing the network timeout',\n );\n }\n try {\n type AgentMethod = (\n prompt: string,\n ...restArgs: any[]\n ) => Promise<any>;\n const result = await (agent[aiActionType] as AgentMethod).bind(\n agent,\n )(taskPrompt, ...args);\n resolve(result);\n } catch (error) {\n reject(error);\n }\n });\n });\n });\n }\n\n return {\n _midsceneFinalizeReports: [\n // biome-ignore lint/correctness/noEmptyPattern: Playwright fixture callbacks must use object destructuring for the first parameter even when no fixtures are consumed.\n async ({}: Record<string, unknown>, use: any, testInfo: TestInfo) => {\n await use();\n\n const records = testAgentRecords.get(testInfo.testId);\n if (!records || records.size === 0) {\n return;\n }\n\n const reportPaths = (\n await Promise.all(\n Array.from(records.values()).map((record) =>\n finalizeAgentRecord(record),\n ),\n )\n ).filter((reportPath): reportPath is string => Boolean(reportPath));\n\n if (reportPaths.length > 0) {\n setReportAnnotation(testInfo, reportPaths);\n }\n\n testAgentRecords.delete(testInfo.testId);\n },\n { auto: true },\n ],\n agentForPage: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await use(\n async (\n propsPage?: OriginPlaywrightPage | undefined,\n opts?: WebPageAgentOpt,\n ) => {\n const cacheConfig = processTestCacheConfig(testInfo);\n\n // Handle cache configuration priority:\n // 1. If user provides cache in opts, use it (but auto-generate ID if missing)\n // 2. Otherwise use fixture's cache config\n let finalCacheConfig = cacheConfig;\n if (opts?.cache !== undefined) {\n const userCache = opts.cache;\n if (userCache === false) {\n finalCacheConfig = false;\n } else if (userCache === true) {\n // Auto-generate ID for user's cache: true\n const { id } = groupAndCaseForTest(testInfo);\n finalCacheConfig = { id };\n } else if (typeof userCache === 'object') {\n if (!userCache.id) {\n // Auto-generate ID for user's cache object without ID\n const { id } = groupAndCaseForTest(testInfo);\n finalCacheConfig = { ...userCache, id };\n } else {\n finalCacheConfig = userCache;\n }\n }\n }\n\n const agent = createOrReuseAgentForPage(propsPage || page, testInfo, {\n waitForNavigationTimeout,\n waitForNetworkIdleTimeout,\n cache: finalCacheConfig,\n ...opts,\n });\n return agent;\n },\n );\n },\n ai: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'ai',\n });\n },\n aiAct: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiAct',\n });\n },\n /**\n * @deprecated Use {@link PlaywrightAiFixture.aiAct} instead.\n */\n aiAction: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiAction',\n });\n },\n aiTap: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiTap',\n });\n },\n aiRightClick: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiRightClick',\n });\n },\n aiDoubleClick: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiDoubleClick',\n });\n },\n aiHover: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiHover',\n });\n },\n aiInput: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiInput',\n });\n },\n aiKeyboardPress: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiKeyboardPress',\n });\n },\n aiScroll: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiScroll',\n });\n },\n aiQuery: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiQuery',\n });\n },\n aiAssert: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiAssert',\n });\n },\n aiWaitFor: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiWaitFor',\n });\n },\n aiLocate: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiLocate',\n });\n },\n aiNumber: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiNumber',\n });\n },\n aiString: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiString',\n });\n },\n aiBoolean: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiBoolean',\n });\n },\n aiAsk: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiAsk',\n });\n },\n runYaml: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'runYaml',\n });\n },\n setAIActionContext: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'setAIActionContext',\n });\n },\n evaluateJavaScript: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'evaluateJavaScript',\n });\n },\n recordToReport: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'recordToReport',\n });\n },\n logScreenshot: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'logScreenshot',\n });\n },\n freezePageContext: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'freezePageContext',\n });\n },\n unfreezePageContext: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'unfreezePageContext',\n });\n },\n };\n};\n\nexport type PlayWrightAiFixtureType = {\n agentForPage: (\n page?: OriginPlaywrightPage,\n opts?: WebPageAgentOpt,\n ) => Promise<PageAgent<PlaywrightWebPage>>;\n ai: <T = any>(...args: Parameters<PageAgent['ai']>) => Promise<T>;\n aiAct: (\n ...args: Parameters<PageAgent['aiAct']>\n ) => ReturnType<PageAgent['aiAct']>;\n /**\n * @deprecated Use {@link PlayWrightAiFixtureType.aiAct} instead.\n */\n aiAction: (\n ...args: Parameters<PageAgent['aiAction']>\n ) => ReturnType<PageAgent['aiAction']>;\n aiTap: (\n ...args: Parameters<PageAgent['aiTap']>\n ) => ReturnType<PageAgent['aiTap']>;\n aiRightClick: (\n ...args: Parameters<PageAgent['aiRightClick']>\n ) => ReturnType<PageAgent['aiRightClick']>;\n aiDoubleClick: (\n ...args: Parameters<PageAgent['aiDoubleClick']>\n ) => ReturnType<PageAgent['aiDoubleClick']>;\n aiHover: (\n ...args: Parameters<PageAgent['aiHover']>\n ) => ReturnType<PageAgent['aiHover']>;\n aiInput: (\n ...args: Parameters<PageAgent['aiInput']>\n ) => ReturnType<PageAgent['aiInput']>;\n aiKeyboardPress: (\n ...args: Parameters<PageAgent['aiKeyboardPress']>\n ) => ReturnType<PageAgent['aiKeyboardPress']>;\n aiScroll: (\n ...args: Parameters<PageAgent['aiScroll']>\n ) => ReturnType<PageAgent['aiScroll']>;\n aiQuery: <T = any>(...args: Parameters<PageAgent['aiQuery']>) => Promise<T>;\n aiAssert: (\n ...args: Parameters<PageAgent['aiAssert']>\n ) => ReturnType<PageAgent['aiAssert']>;\n aiWaitFor: (...args: Parameters<PageAgent['aiWaitFor']>) => Promise<void>;\n aiLocate: (\n ...args: Parameters<PageAgent['aiLocate']>\n ) => ReturnType<PageAgent['aiLocate']>;\n aiNumber: (\n ...args: Parameters<PageAgent['aiNumber']>\n ) => ReturnType<PageAgent['aiNumber']>;\n aiString: (\n ...args: Parameters<PageAgent['aiString']>\n ) => ReturnType<PageAgent['aiString']>;\n aiBoolean: (\n ...args: Parameters<PageAgent['aiBoolean']>\n ) => ReturnType<PageAgent['aiBoolean']>;\n aiAsk: (\n ...args: Parameters<PageAgent['aiAsk']>\n ) => ReturnType<PageAgent['aiAsk']>;\n runYaml: (\n ...args: Parameters<PageAgent['runYaml']>\n ) => ReturnType<PageAgent['runYaml']>;\n setAIActionContext: (\n ...args: Parameters<PageAgent['setAIActionContext']>\n ) => ReturnType<PageAgent['setAIActionContext']>;\n evaluateJavaScript: (\n ...args: Parameters<PageAgent['evaluateJavaScript']>\n ) => ReturnType<PageAgent['evaluateJavaScript']>;\n recordToReport: (\n ...args: Parameters<PageAgent['recordToReport']>\n ) => ReturnType<PageAgent['recordToReport']>;\n logScreenshot: (\n ...args: Parameters<PageAgent['logScreenshot']>\n ) => ReturnType<PageAgent['logScreenshot']>;\n freezePageContext: (\n ...args: Parameters<PageAgent['freezePageContext']>\n ) => ReturnType<PageAgent['freezePageContext']>;\n unfreezePageContext: (\n ...args: Parameters<PageAgent['unfreezePageContext']>\n ) => ReturnType<PageAgent['unfreezePageContext']>;\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","debugPage","getDebug","groupAndCaseForTest","testInfo","taskFile","taskTitle","titlePath","taskTitleWithRetry","replaceIllegalPathCharsAndSpace","midsceneAgentKeyId","midsceneDumpAnnotationId","PlaywrightAiFixture","options","forceSameTabNavigation","waitForNetworkIdleTimeout","DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT","waitForNavigationTimeout","DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT","cache","sharedAgentOptions","processTestCacheConfig","id","processCacheConfig","pageAgentMap","testAgentRecords","Map","getAgentRecordsForTest","records","setReportAnnotation","reportPaths","item","reportPath","finalizeAgentRecord","record","undefined","createOrReuseAgentForPage","page","opts","idForPage","uuid","testId","file","title","cacheConfig","agent","PlaywrightAgent","generateAiFunction","use","aiActionType","taskPrompt","args","Promise","resolve","reject","test","JSON","error","console","result","Array","Boolean","propsPage","finalCacheConfig","userCache"],"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;QAE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BACA4C;gBACA,cAAc;YAChB;QACF;QACA,gBAAgB,OACd,EAAEX,IAAI,EAAkC,EACxCW,KACA5C;YAEA,MAAM2C,mBAAmB;gBACvBV;gBACAjC;gBACA4C;gBACA,cAAc;YAChB;QACF;QACA,eAAe,OACb,EAAEX,IAAI,EAAkC,EACxCW,KACA5C;YAEA,MAAM2C,mBAAmB;gBACvBV;gBACAjC;gBACA4C;gBACA,cAAc;YAChB;QACF;QACA,mBAAmB,OACjB,EAAEX,IAAI,EAAkC,EACxCW,KACA5C;YAEA,MAAM2C,mBAAmB;gBACvBV;gBACAjC;gBACA4C;gBACA,cAAc;YAChB;QACF;QACA,qBAAqB,OACnB,EAAEX,IAAI,EAAkC,EACxCW,KACA5C;YAEA,MAAM2C,mBAAmB;gBACvBV;gBACAjC;gBACA4C;gBACA,cAAc;YAChB;QACF;IACF;AACF"}
1
+ {"version":3,"file":"playwright/ai-fixture.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/playwright/ai-fixture.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 { PlaywrightAgent, type PlaywrightWebPage } from '@/playwright/index';\nimport type { WebPageAgentOpt } from '@/web-element';\nimport type { Cache } from '@midscene/core';\nimport type { Agent as PageAgent } from '@midscene/core/agent';\nimport { processCacheConfig } from '@midscene/core/utils';\nimport {\n DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT,\n DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT,\n} from '@midscene/shared/constants';\nimport { getDebug } from '@midscene/shared/logger';\nimport { uuid } from '@midscene/shared/utils';\nimport { replaceIllegalPathCharsAndSpace } from '@midscene/shared/utils';\nimport { type TestInfo, type TestType, test } from '@playwright/test';\nimport type { Page as OriginPlaywrightPage } from 'playwright';\nexport type APITestType = Pick<TestType<any, any>, 'step'>;\n\nconst debugPage = getDebug('web:playwright:ai-fixture');\n\nconst groupAndCaseForTest = (testInfo: TestInfo) => {\n let taskFile: string;\n let taskTitle: string;\n const titlePath = [...testInfo.titlePath];\n\n if (titlePath.length > 1) {\n taskFile = titlePath.shift() || 'unnamed';\n taskTitle = titlePath.join('__');\n } else if (titlePath.length === 1) {\n taskTitle = titlePath[0];\n taskFile = `${taskTitle}`;\n } else {\n taskTitle = 'unnamed';\n taskFile = 'unnamed';\n }\n\n const taskTitleWithRetry = `${taskTitle}${testInfo.retry ? `(retry #${testInfo.retry})` : ''}`;\n\n return {\n file: taskFile,\n id: replaceIllegalPathCharsAndSpace(`${taskFile}(${taskTitle})`),\n title: replaceIllegalPathCharsAndSpace(taskTitleWithRetry),\n };\n};\n\nconst midsceneAgentKeyId = '_midsceneAgentId';\nexport const midsceneDumpAnnotationId = 'MIDSCENE_DUMP_ANNOTATION';\n\ntype AgentRecord = {\n agent: PageAgent<PlaywrightWebPage>;\n finalizePromise?: Promise<string | undefined>;\n finalReportPath?: string;\n};\n\ntype PlaywrightCacheConfig = {\n strategy?: 'read-only' | 'read-write' | 'write-only';\n id?: string;\n};\ntype PlaywrightCache = false | true | PlaywrightCacheConfig;\n\nexport type PlaywrightAiFixtureOptions = Omit<\n WebPageAgentOpt,\n | 'testId'\n | 'cacheId'\n | 'groupName'\n | 'groupDescription'\n | 'reportFileName'\n | 'cache'\n> & {\n cache?: PlaywrightCache;\n};\n\nexport const PlaywrightAiFixture = (options?: PlaywrightAiFixtureOptions) => {\n const {\n forceSameTabNavigation = true,\n waitForNetworkIdleTimeout = DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT,\n waitForNavigationTimeout = DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT,\n cache,\n ...sharedAgentOptions\n } = options ?? {};\n\n // Helper function to process cache configuration and auto-generate ID from test info\n const processTestCacheConfig = (testInfo: TestInfo): Cache | undefined => {\n // Generate ID from test info\n const { id } = groupAndCaseForTest(testInfo);\n\n // Use shared processCacheConfig with generated ID as fallback\n return processCacheConfig(cache as Cache, id);\n };\n\n const pageAgentMap: Record<string, PageAgent<PlaywrightWebPage>> = {};\n const testAgentRecords = new Map<string, Map<string, AgentRecord>>();\n\n const getAgentRecordsForTest = (testInfo: TestInfo) => {\n let records = testAgentRecords.get(testInfo.testId);\n if (!records) {\n records = new Map<string, AgentRecord>();\n testAgentRecords.set(testInfo.testId, records);\n }\n return records;\n };\n\n const setReportAnnotation = (testInfo: TestInfo, reportPaths: string[]) => {\n testInfo.annotations = testInfo.annotations.filter((item) => {\n return item.type !== midsceneDumpAnnotationId;\n });\n\n for (const reportPath of reportPaths) {\n testInfo.annotations.push({\n type: midsceneDumpAnnotationId,\n description: reportPath,\n });\n }\n };\n\n const finalizeAgentRecord = async (\n record: AgentRecord,\n ): Promise<string | undefined> => {\n if (!record.finalizePromise) {\n record.finalizePromise = (async () => {\n await record.agent.destroy();\n const reportPath = record.agent.reportFile || undefined;\n record.finalReportPath = reportPath;\n return reportPath;\n })();\n }\n\n return await record.finalizePromise;\n };\n\n const createOrReuseAgentForPage = (\n page: OriginPlaywrightPage,\n testInfo: TestInfo, // { testId: string; taskFile: string; taskTitle: string },\n opts?: WebPageAgentOpt,\n ) => {\n let idForPage = (page as any)[midsceneAgentKeyId];\n if (!idForPage) {\n idForPage = uuid();\n (page as any)[midsceneAgentKeyId] = idForPage;\n const { file, title } = groupAndCaseForTest(testInfo);\n const cacheConfig = processTestCacheConfig(testInfo);\n // `replaceIllegalPathCharsAndSpace` intentionally preserves `/` and `\\`\n // so groupName/groupDescription can still carry hierarchy. But\n // ReportGenerator rejects path separators in the file name, so strip\n // them here for the report tag only.\n const reportTag = `playwright-${title.replace(/[\\\\/]/g, '-')}-${idForPage}`;\n\n const agent = new PlaywrightAgent(page, {\n testId: reportTag,\n reportFileName: reportTag,\n forceSameTabNavigation,\n cache: cacheConfig,\n groupName: title,\n groupDescription: file,\n generateReport: true,\n ...sharedAgentOptions,\n ...opts,\n });\n pageAgentMap[idForPage] = agent;\n const records = getAgentRecordsForTest(testInfo);\n const record: AgentRecord = { agent };\n records.set(idForPage, record);\n\n page.on('close', async () => {\n debugPage('page closed');\n try {\n await finalizeAgentRecord(record);\n } finally {\n delete pageAgentMap[idForPage];\n }\n });\n }\n\n return pageAgentMap[idForPage];\n };\n\n async function generateAiFunction(options: {\n page: OriginPlaywrightPage;\n testInfo: TestInfo;\n use: any;\n aiActionType:\n | 'ai'\n | 'aiAct'\n | 'aiAction'\n | 'aiHover'\n | 'aiInput'\n | 'aiKeyboardPress'\n | 'aiScroll'\n | 'aiTap'\n | 'aiRightClick'\n | 'aiDoubleClick'\n | 'aiQuery'\n | 'aiAssert'\n | 'aiWaitFor'\n | 'aiLocate'\n | 'aiNumber'\n | 'aiString'\n | 'aiBoolean'\n | 'aiAsk'\n | 'runYaml'\n | 'setAIActionContext'\n | 'evaluateJavaScript'\n | 'recordToReport'\n | 'logScreenshot'\n | 'freezePageContext'\n | 'unfreezePageContext';\n }) {\n const { page, testInfo, use, aiActionType } = options;\n const agent = createOrReuseAgentForPage(page, testInfo, {\n waitForNavigationTimeout,\n waitForNetworkIdleTimeout,\n }) as PlaywrightAgent;\n\n await use(async (taskPrompt: string, ...args: any[]) => {\n return new Promise((resolve, reject) => {\n test.step(`ai-${aiActionType} - ${JSON.stringify(taskPrompt)}`, async () => {\n try {\n debugPage(\n `waitForNetworkIdle timeout: ${waitForNetworkIdleTimeout}`,\n );\n await agent.waitForNetworkIdle(waitForNetworkIdleTimeout);\n } catch (error) {\n console.warn(\n '[midscene:warning] Waiting for network idle has timed out, but Midscene will continue execution. Please check https://midscenejs.com/faq.html#customize-the-network-timeout for more information on customizing the network timeout',\n );\n }\n try {\n type AgentMethod = (\n prompt: string,\n ...restArgs: any[]\n ) => Promise<any>;\n const result = await (agent[aiActionType] as AgentMethod).bind(\n agent,\n )(taskPrompt, ...args);\n resolve(result);\n } catch (error) {\n reject(error);\n }\n });\n });\n });\n }\n\n return {\n _midsceneFinalizeReports: [\n // biome-ignore lint/correctness/noEmptyPattern: Playwright fixture callbacks must use object destructuring for the first parameter even when no fixtures are consumed.\n async ({}: Record<string, unknown>, use: any, testInfo: TestInfo) => {\n await use();\n\n const records = testAgentRecords.get(testInfo.testId);\n if (!records || records.size === 0) {\n return;\n }\n\n const reportPaths = (\n await Promise.all(\n Array.from(records.values()).map((record) =>\n finalizeAgentRecord(record),\n ),\n )\n ).filter((reportPath): reportPath is string => Boolean(reportPath));\n\n if (reportPaths.length > 0) {\n setReportAnnotation(testInfo, reportPaths);\n }\n\n testAgentRecords.delete(testInfo.testId);\n },\n { auto: true },\n ],\n agentForPage: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await use(\n async (\n propsPage?: OriginPlaywrightPage | undefined,\n opts?: WebPageAgentOpt,\n ) => {\n const cacheConfig = processTestCacheConfig(testInfo);\n\n // Handle cache configuration priority:\n // 1. If user provides cache in opts, use it (but auto-generate ID if missing)\n // 2. Otherwise use fixture's cache config\n let finalCacheConfig = cacheConfig;\n if (opts?.cache !== undefined) {\n const userCache = opts.cache;\n if (userCache === false) {\n finalCacheConfig = false;\n } else if (userCache === true) {\n // Auto-generate ID for user's cache: true\n const { id } = groupAndCaseForTest(testInfo);\n finalCacheConfig = { id };\n } else if (typeof userCache === 'object') {\n if (!userCache.id) {\n // Auto-generate ID for user's cache object without ID\n const { id } = groupAndCaseForTest(testInfo);\n finalCacheConfig = { ...userCache, id };\n } else {\n finalCacheConfig = userCache;\n }\n }\n }\n\n const agent = createOrReuseAgentForPage(propsPage || page, testInfo, {\n waitForNavigationTimeout,\n waitForNetworkIdleTimeout,\n cache: finalCacheConfig,\n ...opts,\n });\n return agent;\n },\n );\n },\n ai: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'ai',\n });\n },\n aiAct: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiAct',\n });\n },\n /**\n * @deprecated Use {@link PlaywrightAiFixture.aiAct} instead.\n */\n aiAction: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiAction',\n });\n },\n aiTap: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiTap',\n });\n },\n aiRightClick: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiRightClick',\n });\n },\n aiDoubleClick: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiDoubleClick',\n });\n },\n aiHover: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiHover',\n });\n },\n aiInput: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiInput',\n });\n },\n aiKeyboardPress: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiKeyboardPress',\n });\n },\n aiScroll: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiScroll',\n });\n },\n aiQuery: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiQuery',\n });\n },\n aiAssert: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiAssert',\n });\n },\n aiWaitFor: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiWaitFor',\n });\n },\n aiLocate: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiLocate',\n });\n },\n aiNumber: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiNumber',\n });\n },\n aiString: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiString',\n });\n },\n aiBoolean: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiBoolean',\n });\n },\n aiAsk: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'aiAsk',\n });\n },\n runYaml: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'runYaml',\n });\n },\n setAIActionContext: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'setAIActionContext',\n });\n },\n evaluateJavaScript: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'evaluateJavaScript',\n });\n },\n recordToReport: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'recordToReport',\n });\n },\n logScreenshot: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'logScreenshot',\n });\n },\n freezePageContext: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'freezePageContext',\n });\n },\n unfreezePageContext: async (\n { page }: { page: OriginPlaywrightPage },\n use: any,\n testInfo: TestInfo,\n ) => {\n await generateAiFunction({\n page,\n testInfo,\n use,\n aiActionType: 'unfreezePageContext',\n });\n },\n };\n};\n\nexport type PlayWrightAiFixtureType = {\n agentForPage: (\n page?: OriginPlaywrightPage,\n opts?: WebPageAgentOpt,\n ) => Promise<PageAgent<PlaywrightWebPage>>;\n ai: <T = any>(...args: Parameters<PageAgent['ai']>) => Promise<T>;\n aiAct: (\n ...args: Parameters<PageAgent['aiAct']>\n ) => ReturnType<PageAgent['aiAct']>;\n /**\n * @deprecated Use {@link PlayWrightAiFixtureType.aiAct} instead.\n */\n aiAction: (\n ...args: Parameters<PageAgent['aiAction']>\n ) => ReturnType<PageAgent['aiAction']>;\n aiTap: (\n ...args: Parameters<PageAgent['aiTap']>\n ) => ReturnType<PageAgent['aiTap']>;\n aiRightClick: (\n ...args: Parameters<PageAgent['aiRightClick']>\n ) => ReturnType<PageAgent['aiRightClick']>;\n aiDoubleClick: (\n ...args: Parameters<PageAgent['aiDoubleClick']>\n ) => ReturnType<PageAgent['aiDoubleClick']>;\n aiHover: (\n ...args: Parameters<PageAgent['aiHover']>\n ) => ReturnType<PageAgent['aiHover']>;\n aiInput: (\n ...args: Parameters<PageAgent['aiInput']>\n ) => ReturnType<PageAgent['aiInput']>;\n aiKeyboardPress: (\n ...args: Parameters<PageAgent['aiKeyboardPress']>\n ) => ReturnType<PageAgent['aiKeyboardPress']>;\n aiScroll: (\n ...args: Parameters<PageAgent['aiScroll']>\n ) => ReturnType<PageAgent['aiScroll']>;\n aiQuery: <T = any>(...args: Parameters<PageAgent['aiQuery']>) => Promise<T>;\n aiAssert: (\n ...args: Parameters<PageAgent['aiAssert']>\n ) => ReturnType<PageAgent['aiAssert']>;\n aiWaitFor: (...args: Parameters<PageAgent['aiWaitFor']>) => Promise<void>;\n aiLocate: (\n ...args: Parameters<PageAgent['aiLocate']>\n ) => ReturnType<PageAgent['aiLocate']>;\n aiNumber: (\n ...args: Parameters<PageAgent['aiNumber']>\n ) => ReturnType<PageAgent['aiNumber']>;\n aiString: (\n ...args: Parameters<PageAgent['aiString']>\n ) => ReturnType<PageAgent['aiString']>;\n aiBoolean: (\n ...args: Parameters<PageAgent['aiBoolean']>\n ) => ReturnType<PageAgent['aiBoolean']>;\n aiAsk: (\n ...args: Parameters<PageAgent['aiAsk']>\n ) => ReturnType<PageAgent['aiAsk']>;\n runYaml: (\n ...args: Parameters<PageAgent['runYaml']>\n ) => ReturnType<PageAgent['runYaml']>;\n setAIActionContext: (\n ...args: Parameters<PageAgent['setAIActionContext']>\n ) => ReturnType<PageAgent['setAIActionContext']>;\n evaluateJavaScript: (\n ...args: Parameters<PageAgent['evaluateJavaScript']>\n ) => ReturnType<PageAgent['evaluateJavaScript']>;\n recordToReport: (\n ...args: Parameters<PageAgent['recordToReport']>\n ) => ReturnType<PageAgent['recordToReport']>;\n logScreenshot: (\n ...args: Parameters<PageAgent['logScreenshot']>\n ) => ReturnType<PageAgent['logScreenshot']>;\n freezePageContext: (\n ...args: Parameters<PageAgent['freezePageContext']>\n ) => ReturnType<PageAgent['freezePageContext']>;\n unfreezePageContext: (\n ...args: Parameters<PageAgent['unfreezePageContext']>\n ) => ReturnType<PageAgent['unfreezePageContext']>;\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","debugPage","getDebug","groupAndCaseForTest","testInfo","taskFile","taskTitle","titlePath","taskTitleWithRetry","replaceIllegalPathCharsAndSpace","midsceneAgentKeyId","midsceneDumpAnnotationId","PlaywrightAiFixture","options","forceSameTabNavigation","waitForNetworkIdleTimeout","DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT","waitForNavigationTimeout","DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT","cache","sharedAgentOptions","processTestCacheConfig","id","processCacheConfig","pageAgentMap","testAgentRecords","Map","getAgentRecordsForTest","records","setReportAnnotation","reportPaths","item","reportPath","finalizeAgentRecord","record","undefined","createOrReuseAgentForPage","page","opts","idForPage","uuid","file","title","cacheConfig","reportTag","agent","PlaywrightAgent","generateAiFunction","use","aiActionType","taskPrompt","args","Promise","resolve","reject","test","JSON","error","console","result","Array","Boolean","propsPage","finalCacheConfig","userCache"],"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,oBAAo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ACF;QACA,oBAAoB,OAClB,EAAEX,IAAI,EAAkC,EACxCW,KACA5C;YAEA,MAAM2C,mBAAmB;gBACvBV;gBACAjC;gBACA4C;gBACA,cAAc;YAChB;QACF;QACA,gBAAgB,OACd,EAAEX,IAAI,EAAkC,EACxCW,KACA5C;YAEA,MAAM2C,mBAAmB;gBACvBV;gBACAjC;gBACA4C;gBACA,cAAc;YAChB;QACF;QACA,eAAe,OACb,EAAEX,IAAI,EAAkC,EACxCW,KACA5C;YAEA,MAAM2C,mBAAmB;gBACvBV;gBACAjC;gBACA4C;gBACA,cAAc;YAChB;QACF;QACA,mBAAmB,OACjB,EAAEX,IAAI,EAAkC,EACxCW,KACA5C;YAEA,MAAM2C,mBAAmB;gBACvBV;gBACAjC;gBACA4C;gBACA,cAAc;YAChB;QACF;QACA,qBAAqB,OACnB,EAAEX,IAAI,EAAkC,EACxCW,KACA5C;YAEA,MAAM2C,mBAAmB;gBACvBV;gBACAjC;gBACA4C;gBACA,cAAc;YAChB;QACF;IACF;AACF"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * CDP proxy lifecycle manager (parent-side).
3
+ *
4
+ * Owns everything the CLI needs to start, locate, replace and kill the
5
+ * standalone `cdp-proxy.ts` child process — including its on-disk
6
+ * metadata files (PROXY_ENDPOINT_FILE / PROXY_PID_FILE /
7
+ * PROXY_UPSTREAM_FILE). Also handles auto-resolving page-level CDP URLs
8
+ * to browser-level endpoints via `/json/version`, since puppeteer-core
9
+ * cannot connect to page-level URLs directly.
10
+ *
11
+ * Other modules (notably `mcp-tools-cdp.ts`) use this through the
12
+ * `getProxyEndpoint()` entry point and never touch the metadata files
13
+ * themselves. The cross-command targetId is a separate concern owned by
14
+ * `cdp-target-store.ts`.
15
+ */
16
+ /**
17
+ * True if the previously spawned proxy process is still running.
18
+ */
19
+ export declare function isProxyAlive(): boolean;
20
+ /**
21
+ * The local WebSocket URL the running proxy is serving, or null.
22
+ */
23
+ export declare function readProxyEndpoint(): string | null;
24
+ /**
25
+ * The Chrome endpoint the running proxy is connected to, or null.
26
+ */
27
+ export declare function readProxyUpstream(): string | null;
28
+ /**
29
+ * Stop the running proxy and discard the cross-command targetId.
30
+ *
31
+ * Sends SIGTERM and waits for the proxy's own SIGTERM handler to remove
32
+ * its PROXY_*_FILE metadata via `cleanupIfOwned()`. When the PID file
33
+ * disappears we know the next `spawnProxy()` can safely take over
34
+ * without tripping the duplicate-proxy guard. Falls back to SIGKILL +
35
+ * manual sweep if the proxy is unresponsive within `PROXY_TERM_GRACE_MS`.
36
+ *
37
+ * The targetId file is cleared regardless of the proxy's state because
38
+ * it points into the outgoing Chrome's tab list.
39
+ */
40
+ export declare function killProxy(): Promise<void>;
41
+ /**
42
+ * Resolve the proxy endpoint to use for the given Chrome endpoint.
43
+ *
44
+ * - Page-level URLs are auto-resolved to browser-level via /json/version.
45
+ * - If a proxy is already running and connected to the same upstream,
46
+ * reuse it.
47
+ * - If a proxy is running but pointed at a different upstream, kill it
48
+ * and start a fresh one.
49
+ * - If spawning the proxy fails, fall back to the raw Chrome endpoint
50
+ * (the caller will hit Chrome's permission popup directly but at
51
+ * least the command does not fail outright).
52
+ */
53
+ export declare function getProxyEndpoint(chromeEndpoint: string): Promise<string>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Persistent store for the CDP-mode "current tab" targetId.
3
+ *
4
+ * The Midscene CLI runs each command as a fresh Node process, so anything
5
+ * the previous command knew about which tab was being driven must survive
6
+ * across processes. This store writes the chosen targetId to a temp file
7
+ * after `connect`/`act`/etc. succeed, and the next command reads it back
8
+ * to bind to the exact same tab — even when Chrome holds 14 of them.
9
+ *
10
+ * Owns nothing else. The CDP proxy lifecycle and its own metadata files
11
+ * live in `cdp-proxy-manager.ts`.
12
+ */
13
+ /**
14
+ * Read the saved targetId, or null if no command has stored one yet.
15
+ */
16
+ export declare function readSavedTargetId(): string | null;
17
+ /**
18
+ * Save a targetId so the next CLI command can rebind to the same tab.
19
+ */
20
+ export declare function saveTargetId(targetId: string): void;
21
+ /**
22
+ * Discard the saved targetId — call when disconnecting or when the
23
+ * upstream Chrome changes (the targetId would point into the old
24
+ * browser's tab list).
25
+ */
26
+ export declare function cleanupTargetIdFile(): void;
@@ -1,27 +1,7 @@
1
- import { BaseMidsceneTools, type ToolDefinition } from '@midscene/shared/mcp';
1
+ import { BaseMidsceneTools } from '@midscene/shared/mcp/base-tools';
2
+ import type { ToolDefinition } from '@midscene/shared/mcp/types';
2
3
  import { PuppeteerAgent } from './puppeteer';
3
4
  import { StaticPage } from './static';
4
- /**
5
- * Check if a previously spawned proxy process is still alive.
6
- */
7
- declare function isProxyAlive(): boolean;
8
- /**
9
- * Read the Chrome endpoint that the running proxy is connected to.
10
- */
11
- declare function readProxyUpstream(): string | null;
12
- /**
13
- * Kill the running proxy process and clear all CDP-mode metadata files
14
- * (proxy endpoint/pid/upstream and the cross-command targetId).
15
- */
16
- declare function killProxy(): void;
17
- /**
18
- * Get the proxy endpoint, spawning the proxy if needed.
19
- * Falls back to direct connection if proxy cannot be started.
20
- *
21
- * If the user provides a page-level CDP URL, automatically resolves it
22
- * to a browser-level endpoint via /json/version.
23
- */
24
- declare function getProxyEndpoint(chromeEndpoint: string): Promise<string>;
25
5
  /**
26
6
  * Tools manager for Web CDP-mode MCP.
27
7
  * Connects to an existing Chrome browser via CDP (Chrome DevTools Protocol) endpoint.
@@ -40,13 +20,3 @@ export declare class WebCdpMidsceneTools extends BaseMidsceneTools<PuppeteerAgen
40
20
  destroy(): Promise<void>;
41
21
  protected preparePlatformTools(): ToolDefinition[];
42
22
  }
43
- /**
44
- * Internal helpers exposed for unit tests. Not part of the public API.
45
- */
46
- export declare const __test__: {
47
- getProxyEndpoint: typeof getProxyEndpoint;
48
- killProxy: typeof killProxy;
49
- readProxyUpstream: typeof readProxyUpstream;
50
- isProxyAlive: typeof isProxyAlive;
51
- };
52
- export {};
@@ -1,4 +1,5 @@
1
- import { BaseMidsceneTools, type ToolDefinition } from '@midscene/shared/mcp';
1
+ import { BaseMidsceneTools } from '@midscene/shared/mcp/base-tools';
2
+ import type { ToolDefinition } from '@midscene/shared/mcp/types';
2
3
  import { PuppeteerAgent } from './puppeteer';
3
4
  import { StaticPage } from './static';
4
5
  /**
@@ -1,4 +1,5 @@
1
- import { BaseMidsceneTools, type ToolDefinition } from '@midscene/shared/mcp';
1
+ import { BaseMidsceneTools } from '@midscene/shared/mcp/base-tools';
2
+ import type { ToolDefinition } from '@midscene/shared/mcp/types';
2
3
  import { AgentOverChromeBridge } from './bridge-mode';
3
4
  import { StaticPage } from './static';
4
5
  /**
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "Browser use",
9
9
  "Android use"
10
10
  ],
11
- "version": "1.7.5-beta-20260421030751.0",
11
+ "version": "1.7.5",
12
12
  "repository": "https://github.com/web-infra-dev/midscene",
13
13
  "homepage": "https://midscenejs.com/",
14
14
  "main": "./dist/lib/index.js",
@@ -110,9 +110,9 @@
110
110
  "socket.io": "^4.8.1",
111
111
  "socket.io-client": "4.8.1",
112
112
  "ws": "^8.18.1",
113
- "@midscene/core": "1.7.5-beta-20260421030751.0",
114
- "@midscene/playground": "1.7.5-beta-20260421030751.0",
115
- "@midscene/shared": "1.7.5-beta-20260421030751.0"
113
+ "@midscene/core": "1.7.5",
114
+ "@midscene/playground": "1.7.5",
115
+ "@midscene/shared": "1.7.5"
116
116
  },
117
117
  "devDependencies": {
118
118
  "@playwright/test": "^1.45.0",