@midscene/web 1.12.8 → 1.12.9-beta-20260917120835.0

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 (83) 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/cli.mjs +1 -1
  7. package/dist/es/common/test-runner/cookies.mjs +133 -0
  8. package/dist/es/common/test-runner/cookies.mjs.map +1 -0
  9. package/dist/es/common/test-runner/utils.mjs +24 -0
  10. package/dist/es/common/test-runner/utils.mjs.map +1 -0
  11. package/dist/es/playwright/test-runner/cookies.mjs +5 -136
  12. package/dist/es/playwright/test-runner/cookies.mjs.map +1 -1
  13. package/dist/es/playwright/test-runner/utils.mjs +1 -21
  14. package/dist/es/playwright/test-runner/utils.mjs.map +1 -1
  15. package/dist/es/puppeteer/browser-agent.mjs +9 -1
  16. package/dist/es/puppeteer/browser-agent.mjs.map +1 -1
  17. package/dist/es/puppeteer/page-agent.mjs +19 -1
  18. package/dist/es/puppeteer/page-agent.mjs.map +1 -1
  19. package/dist/es/puppeteer/test-runner/agent-nodes.mjs +13 -0
  20. package/dist/es/puppeteer/test-runner/agent-nodes.mjs.map +1 -0
  21. package/dist/es/puppeteer/test-runner/clear-cookies.mjs +36 -0
  22. package/dist/es/puppeteer/test-runner/clear-cookies.mjs.map +1 -0
  23. package/dist/es/puppeteer/test-runner/cookies.mjs +31 -0
  24. package/dist/es/puppeteer/test-runner/cookies.mjs.map +1 -0
  25. package/dist/es/puppeteer/test-runner/goto-url.mjs +57 -0
  26. package/dist/es/puppeteer/test-runner/goto-url.mjs.map +1 -0
  27. package/dist/es/puppeteer/test-runner/index.mjs +6 -0
  28. package/dist/es/puppeteer/test-runner/types.mjs +0 -0
  29. package/dist/es/puppeteer/test-runner/utils.mjs +8 -0
  30. package/dist/es/puppeteer/test-runner/utils.mjs.map +1 -0
  31. package/dist/es/puppeteer/test-runner/viewport.mjs +39 -0
  32. package/dist/es/puppeteer/test-runner/viewport.mjs.map +1 -0
  33. package/dist/lib/bridge-mode/io-client.js +1 -1
  34. package/dist/lib/bridge-mode/io-server.js +2 -2
  35. package/dist/lib/bridge-mode/io-server.js.map +1 -1
  36. package/dist/lib/bridge-mode/page-browser-side.js +1 -1
  37. package/dist/lib/bridge-mode/page-browser-side.js.map +1 -1
  38. package/dist/lib/cli.js +1 -1
  39. package/dist/lib/common/test-runner/cookies.js +170 -0
  40. package/dist/lib/common/test-runner/cookies.js.map +1 -0
  41. package/dist/lib/common/test-runner/utils.js +61 -0
  42. package/dist/lib/common/test-runner/utils.js.map +1 -0
  43. package/dist/lib/playwright/test-runner/cookies.js +6 -137
  44. package/dist/lib/playwright/test-runner/cookies.js.map +1 -1
  45. package/dist/lib/playwright/test-runner/utils.js +4 -24
  46. package/dist/lib/playwright/test-runner/utils.js.map +1 -1
  47. package/dist/lib/puppeteer/browser-agent.js +9 -1
  48. package/dist/lib/puppeteer/browser-agent.js.map +1 -1
  49. package/dist/lib/puppeteer/page-agent.js +19 -1
  50. package/dist/lib/puppeteer/page-agent.js.map +1 -1
  51. package/dist/lib/puppeteer/test-runner/agent-nodes.js +47 -0
  52. package/dist/lib/puppeteer/test-runner/agent-nodes.js.map +1 -0
  53. package/dist/lib/puppeteer/test-runner/clear-cookies.js +73 -0
  54. package/dist/lib/puppeteer/test-runner/clear-cookies.js.map +1 -0
  55. package/dist/lib/puppeteer/test-runner/cookies.js +68 -0
  56. package/dist/lib/puppeteer/test-runner/cookies.js.map +1 -0
  57. package/dist/lib/puppeteer/test-runner/goto-url.js +94 -0
  58. package/dist/lib/puppeteer/test-runner/goto-url.js.map +1 -0
  59. package/dist/lib/puppeteer/test-runner/index.js +54 -0
  60. package/dist/lib/puppeteer/test-runner/index.js.map +1 -0
  61. package/dist/lib/puppeteer/test-runner/types.js +20 -0
  62. package/dist/lib/puppeteer/test-runner/types.js.map +1 -0
  63. package/dist/lib/puppeteer/test-runner/utils.js +48 -0
  64. package/dist/lib/puppeteer/test-runner/utils.js.map +1 -0
  65. package/dist/lib/puppeteer/test-runner/viewport.js +76 -0
  66. package/dist/lib/puppeteer/test-runner/viewport.js.map +1 -0
  67. package/dist/types/common/test-runner/cookies.d.ts +51 -0
  68. package/dist/types/common/test-runner/utils.d.ts +2 -0
  69. package/dist/types/playwright/test-runner/cookies.d.ts +4 -31
  70. package/dist/types/playwright/test-runner/types.d.ts +4 -14
  71. package/dist/types/playwright/test-runner/utils.d.ts +1 -2
  72. package/dist/types/puppeteer/browser-agent.d.ts +5 -0
  73. package/dist/types/puppeteer/index.d.ts +1 -1
  74. package/dist/types/puppeteer/page-agent.d.ts +8 -1
  75. package/dist/types/puppeteer/test-runner/agent-nodes.d.ts +2 -0
  76. package/dist/types/puppeteer/test-runner/clear-cookies.d.ts +11 -0
  77. package/dist/types/puppeteer/test-runner/cookies.d.ts +5 -0
  78. package/dist/types/puppeteer/test-runner/goto-url.d.ts +19 -0
  79. package/dist/types/puppeteer/test-runner/index.d.ts +10 -0
  80. package/dist/types/puppeteer/test-runner/types.d.ts +18 -0
  81. package/dist/types/puppeteer/test-runner/utils.d.ts +3 -0
  82. package/dist/types/puppeteer/test-runner/viewport.d.ts +11 -0
  83. package/package.json +9 -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,OAAOD,WACR,IAAGH,oBAAoB,CAAC,CAACG,YAAYC,QAAQ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O,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;IACjB,OAAOA,AAAQ,kBAARA,OAAyBA,IAAI,UAAU,CAAC;AACjD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MnC,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.12.8",
45
+ version: "1.12.9-beta-20260917120835.0",
46
46
  extraCommands: (0, core_namespaceObject.createReportCliCommands)()
47
47
  });
48
48
  }).catch((e)=>{
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ resolveCookieInput: ()=>resolveCookieInput,
28
+ setCookiesInputSchema: ()=>setCookiesInputSchema
29
+ });
30
+ const promises_namespaceObject = require("node:fs/promises");
31
+ const external_node_path_namespaceObject = require("node:path");
32
+ const v4_namespaceObject = require("zod/v4");
33
+ const external_utils_js_namespaceObject = require("./utils.js");
34
+ const setCookiesInputSchema = v4_namespaceObject.z.strictObject({
35
+ cookiesEnv: v4_namespaceObject.z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).optional().describe('The environment variable containing a Cookie header, cookie array JSON, or browser storage-state JSON.'),
36
+ profile: v4_namespaceObject.z.string().regex(/\S/).optional().describe('A cookie profile resolved by getCookieProfile().'),
37
+ storageStatePath: v4_namespaceObject.z.string().regex(/\S/).optional().describe('A path to a browser storage-state JSON file.'),
38
+ url: v4_namespaceObject.z.string().url().optional().describe('The HTTP(S) URL used to scope Cookie-header values or cookies without domain/path.')
39
+ }).superRefine((input, ctx)=>{
40
+ const sourceCount = [
41
+ input.cookiesEnv,
42
+ input.profile,
43
+ input.storageStatePath
44
+ ].filter((value)=>void 0 !== value).length;
45
+ if (1 !== sourceCount) ctx.addIssue({
46
+ code: 'custom',
47
+ message: 'exactly one of cookiesEnv, profile, and storageStatePath is required'
48
+ });
49
+ });
50
+ const toCookieSourceReference = (input)=>{
51
+ if (void 0 !== input.cookiesEnv) return {
52
+ kind: 'env',
53
+ name: input.cookiesEnv
54
+ };
55
+ if (void 0 !== input.profile) return {
56
+ kind: 'profile',
57
+ name: input.profile
58
+ };
59
+ if (void 0 !== input.storageStatePath) return {
60
+ kind: 'storage-state',
61
+ name: input.storageStatePath
62
+ };
63
+ throw new TypeError('setCookies requires one cookie source.');
64
+ };
65
+ const parseCookieHeader = (raw, url)=>{
66
+ if (void 0 === url) throw new TypeError('setCookies.url is required when cookiesEnv contains a Cookie header.');
67
+ const segments = raw.split(';').map((segment)=>segment.trim()).filter(Boolean);
68
+ if (0 === segments.length) throw new TypeError('setCookies Cookie header contains no cookies.');
69
+ return segments.map((segment)=>{
70
+ const separator = segment.indexOf('=');
71
+ if (separator <= 0) throw new TypeError('setCookies Cookie header contains an invalid name/value pair.');
72
+ const name = segment.slice(0, separator).trim();
73
+ const value = segment.slice(separator + 1).trim();
74
+ if (!name) throw new TypeError('setCookies Cookie header contains an empty name.');
75
+ return {
76
+ name,
77
+ value,
78
+ url
79
+ };
80
+ });
81
+ };
82
+ const parseCookieJson = (raw)=>{
83
+ try {
84
+ return JSON.parse(raw);
85
+ } catch {
86
+ throw new TypeError('setCookies source must contain valid JSON or a Cookie header.');
87
+ }
88
+ };
89
+ const normalizeCookie = (candidate, defaultUrl, index)=>{
90
+ if (!candidate || 'object' != typeof candidate || Array.isArray(candidate)) throw new TypeError(`setCookies cookie at index ${index} must be an object.`);
91
+ const cookie = candidate;
92
+ if ('string' != typeof cookie.name || !cookie.name.trim()) throw new TypeError(`setCookies cookie at index ${index} requires a non-blank name.`);
93
+ if ('string' != typeof cookie.value) throw new TypeError(`setCookies cookie at index ${index} requires a string value.`);
94
+ const normalized = {
95
+ ...cookie
96
+ };
97
+ const hasUrl = 'string' == typeof cookie.url && cookie.url.length > 0;
98
+ const hasDomain = 'string' == typeof cookie.domain && cookie.domain.length > 0;
99
+ if (!hasUrl && !hasDomain) {
100
+ if (void 0 === defaultUrl) throw new TypeError(`setCookies cookie at index ${index} requires url or domain, or setCookies.url must be provided.`);
101
+ normalized.url = defaultUrl;
102
+ }
103
+ if (hasDomain && 'string' != typeof cookie.path) normalized.path = '/';
104
+ return normalized;
105
+ };
106
+ const normalizeCookies = (source, defaultUrl)=>{
107
+ const candidates = Array.isArray(source) ? source : source && 'object' == typeof source && Array.isArray(source.cookies) ? source.cookies : void 0;
108
+ if (!candidates) throw new TypeError('setCookies JSON must be a cookie array or an object with a cookies array.');
109
+ if (0 === candidates.length) throw new TypeError('setCookies source contains no cookies.');
110
+ return candidates.map((cookie, index)=>normalizeCookie(cookie, defaultUrl, index));
111
+ };
112
+ const resolveCookieInput = async (input, ctx, options)=>{
113
+ const defaultUrl = void 0 === input.url ? void 0 : (0, external_utils_js_namespaceObject.resolveWebUrl)(input.url, void 0, 'setCookies.url');
114
+ const reference = toCookieSourceReference(input);
115
+ let source;
116
+ switch(reference.kind){
117
+ case 'env':
118
+ {
119
+ let env;
120
+ try {
121
+ env = await options.getEnv?.(ctx) ?? process.env;
122
+ } catch {
123
+ throw new Error(`Failed to resolve cookie environment ${reference.name}; the original error was redacted because it may contain cookie values.`);
124
+ }
125
+ const raw = env[reference.name];
126
+ if (!raw?.trim()) throw new Error(`Environment variable ${reference.name} is missing or blank.`);
127
+ const trimmed = raw.trim();
128
+ source = /^[\[{]/.test(trimmed) ? parseCookieJson(trimmed) : parseCookieHeader(trimmed, defaultUrl);
129
+ break;
130
+ }
131
+ case 'profile':
132
+ if (!options.getCookieProfile) throw new Error('setCookies.profile requires a configured getCookieProfile callback.');
133
+ try {
134
+ source = await options.getCookieProfile({
135
+ profile: reference.name,
136
+ context: ctx.context,
137
+ signal: ctx.signal
138
+ });
139
+ } catch {
140
+ throw new Error(`Failed to resolve cookie profile ${reference.name}; the original error was redacted because it may contain cookie values.`);
141
+ }
142
+ break;
143
+ case 'storage-state':
144
+ {
145
+ const path = options.resolveStorageStatePath ? await options.resolveStorageStatePath(reference.name, ctx) : (0, external_node_path_namespaceObject.resolve)(process.cwd(), reference.name);
146
+ source = parseCookieJson(await (0, promises_namespaceObject.readFile)(path, 'utf8'));
147
+ break;
148
+ }
149
+ }
150
+ const cookies = normalizeCookies(source, defaultUrl);
151
+ return {
152
+ cookies,
153
+ result: {
154
+ source: reference.kind,
155
+ sourceName: reference.name,
156
+ count: cookies.length
157
+ }
158
+ };
159
+ };
160
+ exports.resolveCookieInput = __webpack_exports__.resolveCookieInput;
161
+ exports.setCookiesInputSchema = __webpack_exports__.setCookiesInputSchema;
162
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
163
+ "resolveCookieInput",
164
+ "setCookiesInputSchema"
165
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
166
+ Object.defineProperty(exports, '__esModule', {
167
+ value: true
168
+ });
169
+
170
+ //# sourceMappingURL=cookies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common/test-runner/cookies.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/common/test-runner/cookies.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 { readFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport { z } from 'zod/v4';\nimport { resolveWebUrl } from './utils';\n\ntype Awaitable<T> = T | Promise<T>;\n\nexport type CookieSourceReference =\n | { kind: 'env'; name: string }\n | { kind: 'profile'; name: string }\n | { kind: 'storage-state'; name: string };\n\nexport interface WebNodeContext<TContext> {\n input: unknown;\n context: TContext;\n signal: AbortSignal;\n}\n\nexport interface CookieProfileContext<TContext> {\n profile: string;\n context: TContext;\n signal: AbortSignal;\n}\n\nexport interface WebCookieSourceOptions<TAgent> {\n getEnv?(\n ctx: WebNodeContext<TAgent>,\n ): Awaitable<Readonly<Record<string, string | undefined>>>;\n getCookieProfile?(input: CookieProfileContext<TAgent>): Awaitable<unknown>;\n resolveStorageStatePath?(\n path: string,\n ctx: WebNodeContext<TAgent>,\n ): Awaitable<string>;\n}\n\nexport interface PortableWebCookie extends Record<string, unknown> {\n name: string;\n value: string;\n url?: string;\n domain?: string;\n path?: string;\n}\n\nexport const setCookiesInputSchema = z\n .strictObject({\n cookiesEnv: z\n .string()\n .regex(/^[A-Za-z_][A-Za-z0-9_]*$/)\n .optional()\n .describe(\n 'The environment variable containing a Cookie header, cookie array JSON, or browser storage-state JSON.',\n ),\n profile: z\n .string()\n .regex(/\\S/)\n .optional()\n .describe('A cookie profile resolved by getCookieProfile().'),\n storageStatePath: z\n .string()\n .regex(/\\S/)\n .optional()\n .describe('A path to a browser storage-state JSON file.'),\n url: z\n .string()\n .url()\n .optional()\n .describe(\n 'The HTTP(S) URL used to scope Cookie-header values or cookies without domain/path.',\n ),\n })\n .superRefine((input, ctx) => {\n const sourceCount = [\n input.cookiesEnv,\n input.profile,\n input.storageStatePath,\n ].filter((value) => value !== undefined).length;\n if (sourceCount !== 1) {\n ctx.addIssue({\n code: 'custom',\n message:\n 'exactly one of cookiesEnv, profile, and storageStatePath is required',\n });\n }\n });\n\nexport type SetCookiesNodeInput = z.infer<typeof setCookiesInputSchema>;\n\nexport interface SetCookiesNodeResult {\n source: CookieSourceReference['kind'];\n sourceName: string;\n count: number;\n}\n\nconst toCookieSourceReference = (\n input: SetCookiesNodeInput,\n): CookieSourceReference => {\n if (input.cookiesEnv !== undefined) {\n return { kind: 'env', name: input.cookiesEnv };\n }\n if (input.profile !== undefined) {\n return { kind: 'profile', name: input.profile };\n }\n if (input.storageStatePath !== undefined) {\n return { kind: 'storage-state', name: input.storageStatePath };\n }\n throw new TypeError('setCookies requires one cookie source.');\n};\n\nconst parseCookieHeader = (raw: string, url: string | undefined) => {\n if (url === undefined) {\n throw new TypeError(\n 'setCookies.url is required when cookiesEnv contains a Cookie header.',\n );\n }\n const segments = raw\n .split(';')\n .map((segment) => segment.trim())\n .filter(Boolean);\n if (segments.length === 0) {\n throw new TypeError('setCookies Cookie header contains no cookies.');\n }\n return segments.map((segment) => {\n const separator = segment.indexOf('=');\n if (separator <= 0) {\n throw new TypeError(\n 'setCookies Cookie header contains an invalid name/value pair.',\n );\n }\n const name = segment.slice(0, separator).trim();\n const value = segment.slice(separator + 1).trim();\n if (!name) {\n throw new TypeError('setCookies Cookie header contains an empty name.');\n }\n return { name, value, url } satisfies PortableWebCookie;\n });\n};\n\nconst parseCookieJson = (raw: string): unknown => {\n try {\n return JSON.parse(raw);\n } catch {\n throw new TypeError(\n 'setCookies source must contain valid JSON or a Cookie header.',\n );\n }\n};\n\nconst normalizeCookie = (\n candidate: unknown,\n defaultUrl: string | undefined,\n index: number,\n): PortableWebCookie => {\n if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) {\n throw new TypeError(\n `setCookies cookie at index ${index} must be an object.`,\n );\n }\n const cookie = candidate as Record<string, unknown>;\n if (typeof cookie.name !== 'string' || !cookie.name.trim()) {\n throw new TypeError(\n `setCookies cookie at index ${index} requires a non-blank name.`,\n );\n }\n if (typeof cookie.value !== 'string') {\n throw new TypeError(\n `setCookies cookie at index ${index} requires a string value.`,\n );\n }\n\n const normalized = { ...cookie } as PortableWebCookie;\n const hasUrl = typeof cookie.url === 'string' && cookie.url.length > 0;\n const hasDomain =\n typeof cookie.domain === 'string' && cookie.domain.length > 0;\n if (!hasUrl && !hasDomain) {\n if (defaultUrl === undefined) {\n throw new TypeError(\n `setCookies cookie at index ${index} requires url or domain, or setCookies.url must be provided.`,\n );\n }\n normalized.url = defaultUrl;\n }\n if (hasDomain && typeof cookie.path !== 'string') normalized.path = '/';\n return normalized;\n};\n\nconst normalizeCookies = (\n source: unknown,\n defaultUrl: string | undefined,\n): PortableWebCookie[] => {\n const candidates = Array.isArray(source)\n ? source\n : source &&\n typeof source === 'object' &&\n Array.isArray((source as { cookies?: unknown }).cookies)\n ? (source as { cookies: unknown[] }).cookies\n : undefined;\n if (!candidates) {\n throw new TypeError(\n 'setCookies JSON must be a cookie array or an object with a cookies array.',\n );\n }\n if (candidates.length === 0) {\n throw new TypeError('setCookies source contains no cookies.');\n }\n return candidates.map((cookie, index) =>\n normalizeCookie(cookie, defaultUrl, index),\n );\n};\n\nexport const resolveCookieInput = async <TAgent>(\n input: SetCookiesNodeInput,\n ctx: WebNodeContext<TAgent>,\n options: WebCookieSourceOptions<TAgent>,\n): Promise<{\n cookies: PortableWebCookie[];\n result: SetCookiesNodeResult;\n}> => {\n const defaultUrl =\n input.url === undefined\n ? undefined\n : resolveWebUrl(input.url, undefined, 'setCookies.url');\n const reference = toCookieSourceReference(input);\n let source: unknown;\n switch (reference.kind) {\n case 'env': {\n let env: Readonly<Record<string, string | undefined>>;\n try {\n env = (await options.getEnv?.(ctx)) ?? process.env;\n } catch {\n throw new Error(\n `Failed to resolve cookie environment ${reference.name}; the original error was redacted because it may contain cookie values.`,\n );\n }\n const raw = env[reference.name];\n if (!raw?.trim()) {\n throw new Error(\n `Environment variable ${reference.name} is missing or blank.`,\n );\n }\n const trimmed = raw.trim();\n source = /^[\\[{]/.test(trimmed)\n ? parseCookieJson(trimmed)\n : parseCookieHeader(trimmed, defaultUrl);\n break;\n }\n case 'profile': {\n if (!options.getCookieProfile) {\n throw new Error(\n 'setCookies.profile requires a configured getCookieProfile callback.',\n );\n }\n try {\n source = await options.getCookieProfile({\n profile: reference.name,\n context: ctx.context,\n signal: ctx.signal,\n });\n } catch {\n throw new Error(\n `Failed to resolve cookie profile ${reference.name}; the original error was redacted because it may contain cookie values.`,\n );\n }\n break;\n }\n case 'storage-state': {\n const path = options.resolveStorageStatePath\n ? await options.resolveStorageStatePath(reference.name, ctx)\n : resolve(process.cwd(), reference.name);\n source = parseCookieJson(await readFile(path, 'utf8'));\n break;\n }\n }\n const cookies = normalizeCookies(source, defaultUrl);\n return {\n cookies,\n result: {\n source: reference.kind,\n sourceName: reference.name,\n count: cookies.length,\n },\n };\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","setCookiesInputSchema","z","input","ctx","sourceCount","value","undefined","toCookieSourceReference","TypeError","parseCookieHeader","raw","url","segments","segment","Boolean","separator","name","parseCookieJson","JSON","normalizeCookie","candidate","defaultUrl","index","Array","cookie","normalized","hasUrl","hasDomain","normalizeCookies","source","candidates","resolveCookieInput","options","resolveWebUrl","reference","env","process","Error","trimmed","path","resolve","readFile","cookies"],"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;;;;;;;;;;;;ACqCO,MAAMI,wBAAwBC,mBAAAA,CAAAA,CAAA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xBmB,SAAS,SAAS,IAAI,CAACS,WACnBrB,gBAAgBqB,WAChB7B,kBAAkB6B,SAASjB;gBAC/B;YACF;QACA,KAAK;YACH,IAAI,CAACW,QAAQ,gBAAgB,EAC3B,MAAM,IAAIK,MACR;YAGJ,IAAI;gBACFR,SAAS,MAAMG,QAAQ,gBAAgB,CAAC;oBACtC,SAASE,UAAU,IAAI;oBACvB,SAAS/B,IAAI,OAAO;oBACpB,QAAQA,IAAI,MAAM;gBACpB;YACF,EAAE,OAAM;gBACN,MAAM,IAAIkC,MACR,CAAC,iCAAiC,EAAEH,UAAU,IAAI,CAAC,uEAAuE,CAAC;YAE/H;YACA;QAEF,KAAK;YAAiB;gBACpB,MAAMK,OAAOP,QAAQ,uBAAuB,GACxC,MAAMA,QAAQ,uBAAuB,CAACE,UAAU,IAAI,EAAE/B,OACtDqC,AAAAA,IAAAA,mCAAAA,OAAAA,AAAAA,EAAQJ,QAAQ,GAAG,IAAIF,UAAU,IAAI;gBACzCL,SAASZ,gBAAgB,MAAMwB,AAAAA,IAAAA,yBAAAA,QAAAA,AAAAA,EAASF,MAAM;gBAC9C;YACF;IACF;IACA,MAAMG,UAAUd,iBAAiBC,QAAQR;IACzC,OAAO;QACLqB;QACA,QAAQ;YACN,QAAQR,UAAU,IAAI;YACtB,YAAYA,UAAU,IAAI;YAC1B,OAAOQ,QAAQ,MAAM;QACvB;IACF;AACF"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ resolveWebUrl: ()=>resolveWebUrl,
28
+ throwIfAborted: ()=>throwIfAborted
29
+ });
30
+ const SUPPORTED_WEB_PROTOCOLS = new Set([
31
+ 'http:',
32
+ 'https:'
33
+ ]);
34
+ const throwIfAborted = (signal, operation)=>{
35
+ if (signal.aborted) throw signal.reason ?? new Error(`${operation} aborted.`);
36
+ };
37
+ const resolveWebUrl = (target, baseUrl, label)=>{
38
+ const trimmed = target.trim();
39
+ if (!trimmed) throw new TypeError(`${label} must not be blank.`);
40
+ let resolved;
41
+ try {
42
+ resolved = void 0 === baseUrl ? new URL(trimmed) : new URL(trimmed, baseUrl);
43
+ } catch (error) {
44
+ throw new TypeError(void 0 === baseUrl ? `${label} must be an absolute HTTP(S) URL.` : `${label} is not a valid URL.`, {
45
+ cause: error
46
+ });
47
+ }
48
+ if (!SUPPORTED_WEB_PROTOCOLS.has(resolved.protocol)) throw new TypeError(`${label} does not support the ${resolved.protocol} protocol.`);
49
+ return resolved.toString();
50
+ };
51
+ exports.resolveWebUrl = __webpack_exports__.resolveWebUrl;
52
+ exports.throwIfAborted = __webpack_exports__.throwIfAborted;
53
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
54
+ "resolveWebUrl",
55
+ "throwIfAborted"
56
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
57
+ Object.defineProperty(exports, '__esModule', {
58
+ value: true
59
+ });
60
+
61
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common/test-runner/utils.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/common/test-runner/utils.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};","const SUPPORTED_WEB_PROTOCOLS = new Set(['http:', 'https:']);\n\nexport const throwIfAborted = (signal: AbortSignal, operation: string) => {\n if (signal.aborted) {\n throw signal.reason ?? new Error(`${operation} aborted.`);\n }\n};\n\nexport const resolveWebUrl = (\n target: string,\n baseUrl: string | undefined,\n label: string,\n): string => {\n const trimmed = target.trim();\n if (!trimmed) throw new TypeError(`${label} must not be blank.`);\n\n let resolved: URL;\n try {\n resolved =\n baseUrl === undefined ? new URL(trimmed) : new URL(trimmed, baseUrl);\n } catch (error) {\n throw new TypeError(\n baseUrl === undefined\n ? `${label} must be an absolute HTTP(S) URL.`\n : `${label} is not a valid URL.`,\n { cause: error },\n );\n }\n if (!SUPPORTED_WEB_PROTOCOLS.has(resolved.protocol)) {\n throw new TypeError(\n `${label} does not support the ${resolved.protocol} protocol.`,\n );\n }\n return resolved.toString();\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","SUPPORTED_WEB_PROTOCOLS","Set","throwIfAborted","signal","operation","Error","resolveWebUrl","target","baseUrl","label","trimmed","TypeError","resolved","undefined","URL","error"],"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,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r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  setCookiesNode: ()=>setCookiesNode,
28
- setCookiesInputSchema: ()=>setCookiesInputSchema
28
+ setCookiesInputSchema: ()=>cookies_js_namespaceObject.setCookiesInputSchema
29
29
  });
30
- const promises_namespaceObject = require("node:fs/promises");
31
- const external_node_path_namespaceObject = require("node:path");
32
- const v4_namespaceObject = require("zod/v4");
30
+ const cookies_js_namespaceObject = require("../../common/test-runner/cookies.js");
33
31
  const external_utils_js_namespaceObject = require("./utils.js");
34
- const setCookiesInputSchema = v4_namespaceObject.z.strictObject({
35
- cookiesEnv: v4_namespaceObject.z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).optional().describe('The environment variable containing a Cookie header, cookie array JSON, or Playwright storage-state JSON.'),
36
- profile: v4_namespaceObject.z.string().regex(/\S/).optional().describe('A cookie profile resolved by getCookieProfile().'),
37
- storageStatePath: v4_namespaceObject.z.string().regex(/\S/).optional().describe('A path to a Playwright storage-state JSON file.'),
38
- url: v4_namespaceObject.z.string().url().optional().describe('The HTTP(S) URL used to scope Cookie-header values or cookies without domain/path.')
39
- }).superRefine((input, ctx)=>{
40
- const sourceCount = [
41
- input.cookiesEnv,
42
- input.profile,
43
- input.storageStatePath
44
- ].filter((value)=>void 0 !== value).length;
45
- if (1 !== sourceCount) ctx.addIssue({
46
- code: 'custom',
47
- message: 'exactly one of cookiesEnv, profile, and storageStatePath is required'
48
- });
49
- });
50
- const toCookieSourceReference = (input)=>{
51
- if (void 0 !== input.cookiesEnv) return {
52
- kind: 'env',
53
- name: input.cookiesEnv
54
- };
55
- if (void 0 !== input.profile) return {
56
- kind: 'profile',
57
- name: input.profile
58
- };
59
- if (void 0 !== input.storageStatePath) return {
60
- kind: 'storage-state',
61
- name: input.storageStatePath
62
- };
63
- throw new TypeError('setCookies requires one cookie source.');
64
- };
65
- const parseCookieHeader = (raw, url)=>{
66
- if (void 0 === url) throw new TypeError('setCookies.url is required when cookiesEnv contains a Cookie header.');
67
- const segments = raw.split(';').map((segment)=>segment.trim()).filter(Boolean);
68
- if (0 === segments.length) throw new TypeError('setCookies Cookie header contains no cookies.');
69
- return segments.map((segment)=>{
70
- const separator = segment.indexOf('=');
71
- if (separator <= 0) throw new TypeError('setCookies Cookie header contains an invalid name/value pair.');
72
- const name = segment.slice(0, separator).trim();
73
- const value = segment.slice(separator + 1).trim();
74
- if (!name) throw new TypeError('setCookies Cookie header contains an empty name.');
75
- return {
76
- name,
77
- value,
78
- url
79
- };
80
- });
81
- };
82
- const parseCookieJson = (raw)=>{
83
- try {
84
- return JSON.parse(raw);
85
- } catch {
86
- throw new TypeError('setCookies source must contain valid JSON or a Cookie header.');
87
- }
88
- };
89
- const resolveCookieSource = async (reference, defaultUrl, ctx, options)=>{
90
- switch(reference.kind){
91
- case 'env':
92
- {
93
- let env;
94
- try {
95
- env = await options.getEnv?.(ctx) ?? process.env;
96
- } catch {
97
- throw new Error(`Failed to resolve cookie environment ${reference.name}; the original error was redacted because it may contain cookie values.`);
98
- }
99
- const raw = env[reference.name];
100
- if (!raw?.trim()) throw new Error(`Environment variable ${reference.name} is missing or blank.`);
101
- const trimmed = raw.trim();
102
- return {
103
- reference,
104
- cookies: /^[\[{]/.test(trimmed) ? parseCookieJson(trimmed) : parseCookieHeader(trimmed, defaultUrl)
105
- };
106
- }
107
- case 'profile':
108
- if (!options.getCookieProfile) throw new Error('setCookies.profile requires a configured getCookieProfile callback.');
109
- try {
110
- return {
111
- reference,
112
- cookies: await options.getCookieProfile({
113
- profile: reference.name,
114
- context: ctx.context,
115
- signal: ctx.signal
116
- })
117
- };
118
- } catch {
119
- throw new Error(`Failed to resolve cookie profile ${reference.name}; the original error was redacted because it may contain cookie values.`);
120
- }
121
- case 'storage-state':
122
- {
123
- const path = options.resolveStorageStatePath ? await options.resolveStorageStatePath(reference.name, ctx) : (0, external_node_path_namespaceObject.resolve)(process.cwd(), reference.name);
124
- return {
125
- reference,
126
- cookies: parseCookieJson(await (0, promises_namespaceObject.readFile)(path, 'utf8'))
127
- };
128
- }
129
- }
130
- };
131
- const normalizeCookie = (candidate, defaultUrl, index)=>{
132
- if (!candidate || 'object' != typeof candidate || Array.isArray(candidate)) throw new TypeError(`setCookies cookie at index ${index} must be an object.`);
133
- const cookie = candidate;
134
- if ('string' != typeof cookie.name || !cookie.name.trim()) throw new TypeError(`setCookies cookie at index ${index} requires a non-blank name.`);
135
- if ('string' != typeof cookie.value) throw new TypeError(`setCookies cookie at index ${index} requires a string value.`);
136
- const normalized = {
137
- ...cookie
138
- };
139
- const hasUrl = 'string' == typeof cookie.url && cookie.url.length > 0;
140
- const hasDomain = 'string' == typeof cookie.domain && cookie.domain.length > 0;
141
- if (!hasUrl && !hasDomain) {
142
- if (void 0 === defaultUrl) throw new TypeError(`setCookies cookie at index ${index} requires url or domain, or setCookies.url must be provided.`);
143
- normalized.url = defaultUrl;
144
- }
145
- if (hasDomain && 'string' != typeof cookie.path) normalized.path = '/';
146
- return normalized;
147
- };
148
- const normalizeCookies = (source, defaultUrl)=>{
149
- const candidates = Array.isArray(source) ? source : source && 'object' == typeof source && Array.isArray(source.cookies) ? source.cookies : void 0;
150
- if (!candidates) throw new TypeError('setCookies JSON must be a cookie array or an object with a cookies array.');
151
- if (0 === candidates.length) throw new TypeError('setCookies source contains no cookies.');
152
- return candidates.map((cookie, index)=>normalizeCookie(cookie, defaultUrl, index));
153
- };
154
32
  const setCookiesNode = {
155
33
  name: 'setCookies',
156
34
  title: 'Set browser cookies',
157
- description: 'Load cookies from an environment variable, configured profile, or Playwright storage-state file without persisting cookie values in workflow input or output.',
35
+ description: 'Load cookies from an environment variable, configured profile, or browser storage-state file without persisting cookie values in workflow input or output.',
158
36
  stringInputKey: false,
159
- inputSchema: setCookiesInputSchema,
37
+ inputSchema: cookies_js_namespaceObject.setCookiesInputSchema,
160
38
  async execute (agent, input, executionContext) {
161
39
  const ctx = {
162
40
  ...executionContext,
@@ -164,22 +42,13 @@ const setCookiesNode = {
164
42
  context: (0, external_utils_js_namespaceObject.requirePlaywrightAgent)(agent)
165
43
  };
166
44
  (0, external_utils_js_namespaceObject.throwIfAborted)(ctx.signal, 'setCookies');
167
- const page = ctx.context.interface.underlyingPage;
168
- const defaultUrl = void 0 === ctx.input.url ? void 0 : (0, external_utils_js_namespaceObject.resolveWebUrl)(ctx.input.url, void 0, 'setCookies.url');
169
- const reference = toCookieSourceReference(ctx.input);
170
- const resolved = await resolveCookieSource(reference, defaultUrl, ctx, ctx.context.testRunner ?? {});
171
- const cookies = normalizeCookies(resolved.cookies, defaultUrl);
45
+ const { cookies, result } = await (0, cookies_js_namespaceObject.resolveCookieInput)(input, ctx, ctx.context.testRunner ?? {});
172
46
  (0, external_utils_js_namespaceObject.throwIfAborted)(ctx.signal, 'setCookies');
173
47
  try {
174
- await page.context().addCookies(cookies);
48
+ await ctx.context.interface.underlyingPage.context().addCookies(cookies);
175
49
  } catch {
176
50
  throw new Error(`Failed to set ${cookies.length} browser cookie(s); the browser error was redacted because it may contain cookie values.`);
177
51
  }
178
- const result = {
179
- source: resolved.reference.kind,
180
- sourceName: resolved.reference.name,
181
- count: cookies.length
182
- };
183
52
  return {
184
53
  summary: `Set ${result.count} browser cookie(s) from ${result.source} source ${result.sourceName}`,
185
54
  data: result
@@ -1 +1 @@
1
- {"version":3,"file":"playwright/test-runner/cookies.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/playwright/test-runner/cookies.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 { readFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport type { AgentTestRunnerNodeDefinition } from '@midscene/core/agent';\nimport { z } from 'zod/v4';\nimport type {\n PlaywrightCookie,\n PlaywrightNodeContext,\n PlaywrightTestRunnerAgent,\n PlaywrightTestRunnerOptions,\n} from './types';\nimport { requirePlaywrightAgent, resolveWebUrl, throwIfAborted } from './utils';\n\ntype CookieSourceReference =\n | { kind: 'env'; name: string }\n | { kind: 'profile'; name: string }\n | { kind: 'storage-state'; name: string };\n\ninterface ResolvedCookieSource {\n reference: CookieSourceReference;\n cookies: unknown;\n}\n\n/** Input schema for the Playwright setCookies Node. */\nexport const setCookiesInputSchema = z\n .strictObject({\n cookiesEnv: z\n .string()\n .regex(/^[A-Za-z_][A-Za-z0-9_]*$/)\n .optional()\n .describe(\n 'The environment variable containing a Cookie header, cookie array JSON, or Playwright storage-state JSON.',\n ),\n profile: z\n .string()\n .regex(/\\S/)\n .optional()\n .describe('A cookie profile resolved by getCookieProfile().'),\n storageStatePath: z\n .string()\n .regex(/\\S/)\n .optional()\n .describe('A path to a Playwright storage-state JSON file.'),\n url: z\n .string()\n .url()\n .optional()\n .describe(\n 'The HTTP(S) URL used to scope Cookie-header values or cookies without domain/path.',\n ),\n })\n .superRefine((input, ctx) => {\n const sourceCount = [\n input.cookiesEnv,\n input.profile,\n input.storageStatePath,\n ].filter((value) => value !== undefined).length;\n if (sourceCount !== 1) {\n ctx.addIssue({\n code: 'custom',\n message:\n 'exactly one of cookiesEnv, profile, and storageStatePath is required',\n });\n }\n });\n\n/** Validated input accepted by the Playwright setCookies Node. */\nexport type SetCookiesNodeInput = z.infer<typeof setCookiesInputSchema>;\n\n/** Secret-free metadata returned by the Playwright setCookies Node. */\nexport interface SetCookiesNodeResult {\n /** Kind of configured reference used to resolve the cookies. */\n source: CookieSourceReference['kind'];\n /** Environment variable, profile, or storage-state reference name. */\n sourceName: string;\n /** Number of cookies passed to the BrowserContext. */\n count: number;\n}\n\nconst toCookieSourceReference = (\n input: SetCookiesNodeInput,\n): CookieSourceReference => {\n if (input.cookiesEnv !== undefined) {\n return { kind: 'env', name: input.cookiesEnv };\n }\n if (input.profile !== undefined) {\n return { kind: 'profile', name: input.profile };\n }\n if (input.storageStatePath !== undefined) {\n return { kind: 'storage-state', name: input.storageStatePath };\n }\n throw new TypeError('setCookies requires one cookie source.');\n};\n\nconst parseCookieHeader = (raw: string, url: string | undefined) => {\n if (url === undefined) {\n throw new TypeError(\n 'setCookies.url is required when cookiesEnv contains a Cookie header.',\n );\n }\n const segments = raw\n .split(';')\n .map((segment) => segment.trim())\n .filter(Boolean);\n if (segments.length === 0) {\n throw new TypeError('setCookies Cookie header contains no cookies.');\n }\n return segments.map((segment) => {\n const separator = segment.indexOf('=');\n if (separator <= 0) {\n throw new TypeError(\n 'setCookies Cookie header contains an invalid name/value pair.',\n );\n }\n const name = segment.slice(0, separator).trim();\n const value = segment.slice(separator + 1).trim();\n if (!name) {\n throw new TypeError('setCookies Cookie header contains an empty name.');\n }\n return { name, value, url } satisfies PlaywrightCookie;\n });\n};\n\nconst parseCookieJson = (raw: string): unknown => {\n try {\n return JSON.parse(raw);\n } catch {\n throw new TypeError(\n 'setCookies source must contain valid JSON or a Cookie header.',\n );\n }\n};\n\nconst resolveCookieSource = async (\n reference: CookieSourceReference,\n defaultUrl: string | undefined,\n ctx: PlaywrightNodeContext<PlaywrightTestRunnerAgent>,\n options: PlaywrightTestRunnerOptions,\n): Promise<ResolvedCookieSource> => {\n switch (reference.kind) {\n case 'env': {\n let env: Readonly<Record<string, string | undefined>>;\n try {\n env = (await options.getEnv?.(ctx)) ?? process.env;\n } catch {\n throw new Error(\n `Failed to resolve cookie environment ${reference.name}; the original error was redacted because it may contain cookie values.`,\n );\n }\n const raw = env[reference.name];\n if (!raw?.trim()) {\n throw new Error(\n `Environment variable ${reference.name} is missing or blank.`,\n );\n }\n const trimmed = raw.trim();\n return {\n reference,\n cookies: /^[\\[{]/.test(trimmed)\n ? parseCookieJson(trimmed)\n : parseCookieHeader(trimmed, defaultUrl),\n };\n }\n case 'profile': {\n if (!options.getCookieProfile) {\n throw new Error(\n 'setCookies.profile requires a configured getCookieProfile callback.',\n );\n }\n try {\n return {\n reference,\n cookies: await options.getCookieProfile({\n profile: reference.name,\n context: ctx.context,\n signal: ctx.signal,\n }),\n };\n } catch {\n throw new Error(\n `Failed to resolve cookie profile ${reference.name}; the original error was redacted because it may contain cookie values.`,\n );\n }\n }\n case 'storage-state': {\n const path = options.resolveStorageStatePath\n ? await options.resolveStorageStatePath(reference.name, ctx)\n : resolve(process.cwd(), reference.name);\n return {\n reference,\n cookies: parseCookieJson(await readFile(path, 'utf8')),\n };\n }\n }\n};\n\nconst normalizeCookie = (\n candidate: unknown,\n defaultUrl: string | undefined,\n index: number,\n): PlaywrightCookie => {\n if (!candidate || typeof candidate !== 'object' || Array.isArray(candidate)) {\n throw new TypeError(\n `setCookies cookie at index ${index} must be an object.`,\n );\n }\n const cookie = candidate as Record<string, unknown>;\n if (typeof cookie.name !== 'string' || !cookie.name.trim()) {\n throw new TypeError(\n `setCookies cookie at index ${index} requires a non-blank name.`,\n );\n }\n if (typeof cookie.value !== 'string') {\n throw new TypeError(\n `setCookies cookie at index ${index} requires a string value.`,\n );\n }\n\n const normalized = { ...cookie } as unknown as PlaywrightCookie;\n const hasUrl = typeof cookie.url === 'string' && cookie.url.length > 0;\n const hasDomain =\n typeof cookie.domain === 'string' && cookie.domain.length > 0;\n if (!hasUrl && !hasDomain) {\n if (defaultUrl === undefined) {\n throw new TypeError(\n `setCookies cookie at index ${index} requires url or domain, or setCookies.url must be provided.`,\n );\n }\n normalized.url = defaultUrl;\n }\n if (hasDomain && typeof cookie.path !== 'string') {\n normalized.path = '/';\n }\n return normalized;\n};\n\nconst normalizeCookies = (\n source: unknown,\n defaultUrl: string | undefined,\n): PlaywrightCookie[] => {\n const candidates = Array.isArray(source)\n ? source\n : source &&\n typeof source === 'object' &&\n Array.isArray((source as { cookies?: unknown }).cookies)\n ? (source as { cookies: unknown[] }).cookies\n : undefined;\n if (!candidates) {\n throw new TypeError(\n 'setCookies JSON must be a cookie array or an object with a cookies array.',\n );\n }\n if (candidates.length === 0) {\n throw new TypeError('setCookies source contains no cookies.');\n }\n return candidates.map((cookie, index) =>\n normalizeCookie(cookie, defaultUrl, index),\n );\n};\n\nexport const setCookiesNode: AgentTestRunnerNodeDefinition<\n z.output<typeof setCookiesInputSchema>,\n SetCookiesNodeResult\n> = {\n name: 'setCookies',\n title: 'Set browser cookies',\n description:\n 'Load cookies from an environment variable, configured profile, or Playwright storage-state file without persisting cookie values in workflow input or output.',\n stringInputKey: false,\n inputSchema: setCookiesInputSchema,\n async execute(agent, input, executionContext) {\n const ctx = {\n ...executionContext,\n input,\n context: requirePlaywrightAgent(agent),\n };\n throwIfAborted(ctx.signal, 'setCookies');\n const page = ctx.context.interface.underlyingPage;\n const defaultUrl =\n ctx.input.url === undefined\n ? undefined\n : resolveWebUrl(ctx.input.url, undefined, 'setCookies.url');\n const reference = toCookieSourceReference(ctx.input);\n const resolved = await resolveCookieSource(\n reference,\n defaultUrl,\n ctx,\n ctx.context.testRunner ?? {},\n );\n const cookies = normalizeCookies(resolved.cookies, defaultUrl);\n\n throwIfAborted(ctx.signal, 'setCookies');\n try {\n await page.context().addCookies(cookies);\n } catch {\n throw new Error(\n `Failed to set ${cookies.length} browser cookie(s); the browser error was redacted because it may contain cookie values.`,\n );\n }\n\n const result: SetCookiesNodeResult = {\n source: resolved.reference.kind,\n sourceName: resolved.reference.name,\n count: cookies.length,\n };\n return {\n summary: `Set ${result.count} browser cookie(s) from ${result.source} source ${result.sourceName}`,\n data: result,\n };\n },\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","setCookiesInputSchema","z","input","ctx","sourceCount","value","undefined","toCookieSourceReference","TypeError","parseCookieHeader","raw","url","segments","segment","Boolean","separator","name","parseCookieJson","JSON","resolveCookieSource","reference","defaultUrl","options","env","process","Error","trimmed","path","resolve","readFile","normalizeCookie","candidate","index","Array","cookie","normalized","hasUrl","hasDomain","normalizeCookies","source","candidates","setCookiesNode","agent","executionContext","requirePlaywrightAgent","throwIfAborted","page","resolveWebUrl","resolved","cookies","result"],"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;;;;;;;;;;;;ACiBO,MAAMI,wBAAwBC,mBAAAA,CAAAA,CAAAA,YACtB,CAAC;IACZ,YAAYA,mBAAAA,CAAAA,CAAAA,MACH,GACN,KAAK,CAAC,4BACN,QAAQ,GACR,QAAQ,CACP;IAEJ,SAASA,mBAAAA,CAAAA,CAAAA,MACA,GACN,KAAK,CAAC,MACN,QAAQ,GACR,QAAQ,CAAC;IACZ,kBAAkBA,mBAAAA,CAAAA,CAAAA,MACT,GACN,KAAK,CAAC,MACN,QAAQ,GACR,QAAQ,CAAC;IACZ,KAAKA,mBAAAA,CAAAA,CAAAA,MACI,GACN,GAAG,GACH,QAAQ,GACR,QAAQ,CACP;AAEN,GACC,WAAW,CAAC,CAACC,OAAOC;IACnB,MAAMC,cAAc;Q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AQ,MAAM;QACvB;QACA,OAAO;YACL,SAAS,CAAC,IAAI,EAAEC,OAAO,KAAK,CAAC,wBAAwB,EAAEA,OAAO,MAAM,CAAC,QAAQ,EAAEA,OAAO,UAAU,EAAE;YAClG,MAAMA;QACR;IACF;AACF"}
1
+ {"version":3,"file":"playwright/test-runner/cookies.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/playwright/test-runner/cookies.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 {\n type SetCookiesNodeInput,\n type SetCookiesNodeResult,\n resolveCookieInput,\n setCookiesInputSchema,\n} from '@/common/test-runner/cookies';\nimport type { AgentTestRunnerNodeDefinition } from '@midscene/core/agent';\nimport { requirePlaywrightAgent, throwIfAborted } from './utils';\n\nexport { setCookiesInputSchema };\nexport type { SetCookiesNodeInput, SetCookiesNodeResult };\n\nexport const setCookiesNode: AgentTestRunnerNodeDefinition<\n SetCookiesNodeInput,\n SetCookiesNodeResult\n> = {\n name: 'setCookies',\n title: 'Set browser cookies',\n description:\n 'Load cookies from an environment variable, configured profile, or browser storage-state file without persisting cookie values in workflow input or output.',\n stringInputKey: false,\n inputSchema: setCookiesInputSchema,\n async execute(agent, input, executionContext) {\n const ctx = {\n ...executionContext,\n input,\n context: requirePlaywrightAgent(agent),\n };\n throwIfAborted(ctx.signal, 'setCookies');\n const { cookies, result } = await resolveCookieInput(\n input,\n ctx,\n ctx.context.testRunner ?? {},\n );\n\n throwIfAborted(ctx.signal, 'setCookies');\n try {\n await ctx.context.interface.underlyingPage.context().addCookies(cookies);\n } catch {\n throw new Error(\n `Failed to set ${cookies.length} browser cookie(s); the browser error was redacted because it may contain cookie values.`,\n );\n }\n return {\n summary: `Set ${result.count} browser cookie(s) from ${result.source} source ${result.sourceName}`,\n data: result,\n };\n },\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","setCookiesNode","setCookiesInputSchema","agent","input","executionContext","ctx","requirePlaywrightAgent","throwIfAborted","cookies","result","resolveCookieInput","Error"],"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;;;;;;;;;;ACMO,MAAMI,iBAGT;IACF,MAAM;IACN,OAAO;IACP,aACE;IACF,gBAAgB;IAChB,aAAaC,2BAAAA,qBAAqBA;IAClC,MAAM,SAAQC,KAAK,EAAEC,KAAK,EAAEC,gBAAgB;QAC1C,MAAMC,MAAM;YACV,GAAGD,gBAAgB;YACnBD;YACA,SAASG,AAAAA,IAAAA,kCAAAA,sBAAAA,AAAAA,EAAuBJ;QAClC;QACAK,IAAAA,kCAAAA,c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