@midscene/web 0.30.10 → 1.0.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 (112) hide show
  1. package/dist/es/bin.mjs +0 -4
  2. package/dist/es/bin.mjs.map +1 -1
  3. package/dist/es/bridge-mode/agent-cli-side.mjs +22 -11
  4. package/dist/es/bridge-mode/agent-cli-side.mjs.map +1 -1
  5. package/dist/es/bridge-mode/common.mjs +8 -2
  6. package/dist/es/bridge-mode/common.mjs.map +1 -1
  7. package/dist/es/bridge-mode/io-client.mjs +10 -16
  8. package/dist/es/bridge-mode/io-client.mjs.map +1 -1
  9. package/dist/es/bridge-mode/io-server.mjs +21 -19
  10. package/dist/es/bridge-mode/io-server.mjs.map +1 -1
  11. package/dist/es/bridge-mode/page-browser-side.mjs +10 -11
  12. package/dist/es/bridge-mode/page-browser-side.mjs.map +1 -1
  13. package/dist/es/chrome-extension/agent.mjs.map +1 -1
  14. package/dist/es/chrome-extension/cdpInput.mjs.map +1 -1
  15. package/dist/es/chrome-extension/dynamic-scripts.mjs.map +1 -1
  16. package/dist/es/chrome-extension/page.mjs +85 -89
  17. package/dist/es/chrome-extension/page.mjs.map +1 -1
  18. package/dist/es/playwright/ai-fixture.mjs +43 -14
  19. package/dist/es/playwright/ai-fixture.mjs.map +1 -1
  20. package/dist/es/playwright/index.mjs +18 -2
  21. package/dist/es/playwright/index.mjs.map +1 -1
  22. package/dist/es/playwright/page.mjs.map +1 -1
  23. package/dist/es/playwright/reporter/index.mjs +30 -16
  24. package/dist/es/playwright/reporter/index.mjs.map +1 -1
  25. package/dist/es/puppeteer/agent-launcher.mjs +48 -22
  26. package/dist/es/puppeteer/agent-launcher.mjs.map +1 -1
  27. package/dist/es/puppeteer/base-page.mjs +67 -26
  28. package/dist/es/puppeteer/base-page.mjs.map +1 -1
  29. package/dist/es/puppeteer/index.mjs +18 -2
  30. package/dist/es/puppeteer/index.mjs.map +1 -1
  31. package/dist/es/puppeteer/page.mjs.map +1 -1
  32. package/dist/es/static/static-agent.mjs.map +1 -1
  33. package/dist/es/static/static-page.mjs +1 -10
  34. package/dist/es/static/static-page.mjs.map +1 -1
  35. package/dist/es/utils.mjs +8 -0
  36. package/dist/es/utils.mjs.map +1 -0
  37. package/dist/es/web-element.mjs +2 -24
  38. package/dist/es/web-element.mjs.map +1 -1
  39. package/dist/es/web-page.mjs +71 -41
  40. package/dist/es/web-page.mjs.map +1 -1
  41. package/dist/lib/bin.js +1 -5
  42. package/dist/lib/bin.js.map +1 -1
  43. package/dist/lib/bridge-mode/agent-cli-side.js +23 -12
  44. package/dist/lib/bridge-mode/agent-cli-side.js.map +1 -1
  45. package/dist/lib/bridge-mode/browser.js +2 -2
  46. package/dist/lib/bridge-mode/browser.js.map +1 -1
  47. package/dist/lib/bridge-mode/common.js +17 -5
  48. package/dist/lib/bridge-mode/common.js.map +1 -1
  49. package/dist/lib/bridge-mode/index.js +3 -3
  50. package/dist/lib/bridge-mode/index.js.map +1 -1
  51. package/dist/lib/bridge-mode/io-client.js +12 -18
  52. package/dist/lib/bridge-mode/io-client.js.map +1 -1
  53. package/dist/lib/bridge-mode/io-server.js +25 -23
  54. package/dist/lib/bridge-mode/io-server.js.map +1 -1
  55. package/dist/lib/bridge-mode/page-browser-side.js +12 -13
  56. package/dist/lib/bridge-mode/page-browser-side.js.map +1 -1
  57. package/dist/lib/chrome-extension/agent.js +2 -2
  58. package/dist/lib/chrome-extension/agent.js.map +1 -1
  59. package/dist/lib/chrome-extension/cdpInput.js +2 -2
  60. package/dist/lib/chrome-extension/cdpInput.js.map +1 -1
  61. package/dist/lib/chrome-extension/dynamic-scripts.js +2 -2
  62. package/dist/lib/chrome-extension/dynamic-scripts.js.map +1 -1
  63. package/dist/lib/chrome-extension/index.js +3 -3
  64. package/dist/lib/chrome-extension/index.js.map +1 -1
  65. package/dist/lib/chrome-extension/page.js +87 -91
  66. package/dist/lib/chrome-extension/page.js.map +1 -1
  67. package/dist/lib/index.js +6 -6
  68. package/dist/lib/index.js.map +1 -1
  69. package/dist/lib/playwright/ai-fixture.js +46 -17
  70. package/dist/lib/playwright/ai-fixture.js.map +1 -1
  71. package/dist/lib/playwright/index.js +32 -6
  72. package/dist/lib/playwright/index.js.map +1 -1
  73. package/dist/lib/playwright/page.js +2 -2
  74. package/dist/lib/playwright/page.js.map +1 -1
  75. package/dist/lib/playwright/reporter/index.js +32 -18
  76. package/dist/lib/playwright/reporter/index.js.map +1 -1
  77. package/dist/lib/puppeteer/agent-launcher.js +57 -28
  78. package/dist/lib/puppeteer/agent-launcher.js.map +1 -1
  79. package/dist/lib/puppeteer/base-page.js +73 -29
  80. package/dist/lib/puppeteer/base-page.js.map +1 -1
  81. package/dist/lib/puppeteer/index.js +31 -5
  82. package/dist/lib/puppeteer/index.js.map +1 -1
  83. package/dist/lib/puppeteer/page.js +2 -2
  84. package/dist/lib/puppeteer/page.js.map +1 -1
  85. package/dist/lib/static/index.js +4 -4
  86. package/dist/lib/static/index.js.map +1 -1
  87. package/dist/lib/static/static-agent.js +2 -2
  88. package/dist/lib/static/static-agent.js.map +1 -1
  89. package/dist/lib/static/static-page.js +3 -12
  90. package/dist/lib/static/static-page.js.map +1 -1
  91. package/dist/lib/utils.js +40 -0
  92. package/dist/lib/utils.js.map +1 -0
  93. package/dist/lib/web-element.js +6 -28
  94. package/dist/lib/web-element.js.map +1 -1
  95. package/dist/lib/web-page.js +73 -43
  96. package/dist/lib/web-page.js.map +1 -1
  97. package/dist/types/bridge-mode/agent-cli-side.d.ts +23 -2
  98. package/dist/types/bridge-mode/common.d.ts +9 -0
  99. package/dist/types/bridge-mode/io-server.d.ts +3 -2
  100. package/dist/types/bridge-mode/page-browser-side.d.ts +2 -1
  101. package/dist/types/chrome-extension/page.d.ts +19 -6
  102. package/dist/types/playwright/ai-fixture.d.ts +16 -2
  103. package/dist/types/playwright/index.d.ts +1 -0
  104. package/dist/types/playwright/reporter/index.d.ts +2 -0
  105. package/dist/types/puppeteer/agent-launcher.d.ts +3 -4
  106. package/dist/types/puppeteer/base-page.d.ts +18 -5
  107. package/dist/types/puppeteer/index.d.ts +1 -0
  108. package/dist/types/static/static-page.d.ts +0 -1
  109. package/dist/types/utils.d.ts +6 -0
  110. package/dist/types/web-element.d.ts +10 -0
  111. package/dist/types/web-page.d.ts +4 -1
  112. package/package.json +13 -20
@@ -1 +1 @@
1
- {"version":3,"file":"chrome-extension/cdpInput.js","sources":["webpack://@midscene/web/webpack/runtime/define_property_getters","webpack://@midscene/web/webpack/runtime/has_own_property","webpack://@midscene/web/webpack/runtime/make_namespace_object","webpack://@midscene/web/./src/chrome-extension/cdpInput.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};","// From https://github.com/puppeteer/puppeteer/blob/15abcc390862fd08cc3475532f2d9a11284aee6b/packages/puppeteer-core/src/cdp/Input.ts#L55\n// with some modifications to fit the session type\n/**\n * @license\n * Copyright 2017 Google Inc.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type KeyDefinition,\n type KeyInput,\n _keyDefinitions,\n} from '@midscene/shared/us-keyboard-layout';\nimport { assert } from '@midscene/shared/utils';\n\ntype KeyDescription = Required<\n Pick<KeyDefinition, 'keyCode' | 'key' | 'text' | 'code' | 'location'>\n>;\n\n/**\n * @public\n */\nexport interface KeyDownOptions {\n /**\n * @deprecated Do not use. This is automatically handled.\n */\n text?: string;\n /**\n * @deprecated Do not use. This is automatically handled.\n */\n commands?: string[];\n}\n\n/**\n * @public\n */\nexport interface KeyboardTypeOptions {\n /**\n * Time to wait between key presses in milliseconds\n * @default undefined\n */\n delay?: number;\n}\n\n/**\n * @public\n */\nexport type KeyPressOptions = KeyDownOptions & KeyboardTypeOptions;\n\ntype InternalCDPSession = {\n send: (command: string, params: any) => Promise<void>;\n};\n\n/**\n * @internal\n */\nexport class CdpKeyboard {\n #pressedKeys = new Set<string>();\n\n #client: InternalCDPSession;\n\n _modifiers = 0;\n\n constructor(client: InternalCDPSession) {\n this.#client = client;\n }\n\n updateClient(client: InternalCDPSession): void {\n this.#client = client;\n }\n\n async down(\n key: KeyInput,\n options: Readonly<KeyDownOptions> = {\n text: undefined,\n commands: [],\n },\n ): Promise<void> {\n const description = this.#keyDescriptionForString(key);\n\n const autoRepeat = this.#pressedKeys.has(description.code);\n this.#pressedKeys.add(description.code);\n this._modifiers |= this.#modifierBit(description.key);\n\n const text = options.text === undefined ? description.text : options.text;\n await this.#client.send('Input.dispatchKeyEvent', {\n type: text ? 'keyDown' : 'rawKeyDown',\n modifiers: this._modifiers,\n windowsVirtualKeyCode: description.keyCode,\n code: description.code,\n key: description.key,\n text: text,\n unmodifiedText: text,\n autoRepeat,\n location: description.location,\n isKeypad: description.location === 3,\n commands: options.commands,\n });\n }\n\n #modifierBit(key: string): number {\n if (key === 'Alt') {\n return 1;\n }\n if (key === 'Control') {\n return 2;\n }\n if (key === 'Meta') {\n return 4;\n }\n if (key === 'Shift') {\n return 8;\n }\n return 0;\n }\n\n #keyDescriptionForString(keyString: KeyInput): KeyDescription {\n const shift = this._modifiers & 8;\n const description = {\n key: '',\n keyCode: 0,\n code: '',\n text: '',\n location: 0,\n };\n\n const definition = _keyDefinitions[keyString];\n\n assert(definition, `Unknown key: \"${keyString}\"`);\n\n if (definition.key) {\n description.key = definition.key;\n }\n if (shift && definition.shiftKey) {\n description.key = definition.shiftKey;\n }\n\n if (definition.keyCode) {\n description.keyCode = definition.keyCode;\n }\n if (shift && definition.shiftKeyCode) {\n description.keyCode = definition.shiftKeyCode;\n }\n\n if (definition.code) {\n description.code = definition.code;\n }\n\n if (definition.location) {\n description.location = definition.location;\n }\n\n if (description.key.length === 1) {\n description.text = description.key;\n }\n\n if (definition.text) {\n description.text = definition.text;\n }\n if (shift && definition.shiftText) {\n description.text = definition.shiftText;\n }\n\n // if any modifiers besides shift are pressed, no text should be sent\n if (this._modifiers & ~8) {\n description.text = '';\n }\n\n return description;\n }\n\n async up(key: KeyInput): Promise<void> {\n const description = this.#keyDescriptionForString(key);\n\n this._modifiers &= ~this.#modifierBit(description.key);\n this.#pressedKeys.delete(description.code);\n await this.#client.send('Input.dispatchKeyEvent', {\n type: 'keyUp',\n modifiers: this._modifiers,\n key: description.key,\n windowsVirtualKeyCode: description.keyCode,\n code: description.code,\n location: description.location,\n });\n }\n\n async sendCharacter(char: string): Promise<void> {\n await this.#client.send('Input.insertText', { text: char });\n }\n\n private charIsKey(char: string): char is KeyInput {\n return !!_keyDefinitions[char as KeyInput];\n }\n\n async type(\n text: string,\n options: Readonly<KeyboardTypeOptions> = {},\n ): Promise<void> {\n const delay = options.delay || undefined;\n for (const char of text) {\n if (this.charIsKey(char)) {\n await this.press(char, { delay });\n } else {\n if (delay) {\n await new Promise((f) => {\n return setTimeout(f, delay);\n });\n }\n await this.sendCharacter(char);\n }\n }\n }\n\n async press(\n key: KeyInput | KeyInput[],\n options: Readonly<KeyPressOptions> = {},\n ): Promise<void> {\n const { delay = null } = options;\n const keys = Array.isArray(key) ? key : [key];\n\n for (const k of keys) {\n await this.down(k, options);\n }\n\n if (delay) {\n await new Promise((f) => {\n return setTimeout(f, options.delay);\n });\n }\n\n for (const k of [...keys].reverse()) {\n await this.up(k);\n }\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","_pressedKeys","_client","modifierBit","keyDescriptionForString","CdpKeyboard","client","options","undefined","description","autoRepeat","text","char","_keyDefinitions","delay","Promise","f","setTimeout","keys","Array","k","Set","keyString","shift","assert"],"mappings":";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,MAAMd,aAAakB,mCAAAA,eAAe,CAACS,UAAU;IAE7CE,IAAAA,sBAAAA,MAAAA,AAAAA,EAAO7B,YAAY,CAAC,cAAc,EAAE2B,UAAU,CAAC,CAAC;IAEhD,IAAI3B,WAAW,GAAG,EAChBc,YAAY,GAAG,GAAGd,WAAW,GAAG;IAElC,IAAI4B,SAAS5B,WAAW,QAAQ,EAC9Bc,YAAY,GAAG,GAAGd,WAAW,QAAQ;IAGvC,IAAIA,WAAW,OAAO,EACpBc,YAAY,OAAO,GAAGd,WAAW,OAAO;IAE1C,IAAI4B,SAAS5B,WAAW,YAAY,EAClCc,YAAY,OAAO,GAAGd,WAAW,YAAY;IAG/C,IAAIA,WAAW,IAAI,EACjBc,YAAY,IAAI,GAAGd,WAAW,IAAI;IAGpC,IAAIA,WAAW,QAAQ,EACrBc,YAAY,QAAQ,GAAGd,WAAW,QAAQ;IAG5C,IAAIc,AAA2B,MAA3BA,YAAY,GAAG,CAAC,MAAM,EACxBA,YAAY,IAAI,GAAGA,YAAY,GAAG;IAGpC,IAAId,WAAW,IAAI,EACjBc,YAAY,IAAI,GAAGd,WAAW,IAAI;IAEpC,IAAI4B,SAAS5B,WAAW,SAAS,EAC/Bc,YAAY,IAAI,GAAGd,WAAW,SAAS;IAIzC,IAAI,AAAkB,KAAlB,IAAI,CAAC,UAAU,EACjBc,YAAY,IAAI,GAAG;IAGrB,OAAOA;AACT"}
1
+ {"version":3,"file":"chrome-extension/cdpInput.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/chrome-extension/cdpInput.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};","// From https://github.com/puppeteer/puppeteer/blob/15abcc390862fd08cc3475532f2d9a11284aee6b/packages/puppeteer-core/src/cdp/Input.ts#L55\n// with some modifications to fit the session type\n/**\n * @license\n * Copyright 2017 Google Inc.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type KeyDefinition,\n type KeyInput,\n _keyDefinitions,\n} from '@midscene/shared/us-keyboard-layout';\nimport { assert } from '@midscene/shared/utils';\n\ntype KeyDescription = Required<\n Pick<KeyDefinition, 'keyCode' | 'key' | 'text' | 'code' | 'location'>\n>;\n\n/**\n * @public\n */\nexport interface KeyDownOptions {\n /**\n * @deprecated Do not use. This is automatically handled.\n */\n text?: string;\n /**\n * @deprecated Do not use. This is automatically handled.\n */\n commands?: string[];\n}\n\n/**\n * @public\n */\nexport interface KeyboardTypeOptions {\n /**\n * Time to wait between key presses in milliseconds\n * @default undefined\n */\n delay?: number;\n}\n\n/**\n * @public\n */\nexport type KeyPressOptions = KeyDownOptions & KeyboardTypeOptions;\n\ntype InternalCDPSession = {\n send: (command: string, params: any) => Promise<void>;\n};\n\n/**\n * @internal\n */\nexport class CdpKeyboard {\n #pressedKeys = new Set<string>();\n\n #client: InternalCDPSession;\n\n _modifiers = 0;\n\n constructor(client: InternalCDPSession) {\n this.#client = client;\n }\n\n updateClient(client: InternalCDPSession): void {\n this.#client = client;\n }\n\n async down(\n key: KeyInput,\n options: Readonly<KeyDownOptions> = {\n text: undefined,\n commands: [],\n },\n ): Promise<void> {\n const description = this.#keyDescriptionForString(key);\n\n const autoRepeat = this.#pressedKeys.has(description.code);\n this.#pressedKeys.add(description.code);\n this._modifiers |= this.#modifierBit(description.key);\n\n const text = options.text === undefined ? description.text : options.text;\n await this.#client.send('Input.dispatchKeyEvent', {\n type: text ? 'keyDown' : 'rawKeyDown',\n modifiers: this._modifiers,\n windowsVirtualKeyCode: description.keyCode,\n code: description.code,\n key: description.key,\n text: text,\n unmodifiedText: text,\n autoRepeat,\n location: description.location,\n isKeypad: description.location === 3,\n commands: options.commands,\n });\n }\n\n #modifierBit(key: string): number {\n if (key === 'Alt') {\n return 1;\n }\n if (key === 'Control') {\n return 2;\n }\n if (key === 'Meta') {\n return 4;\n }\n if (key === 'Shift') {\n return 8;\n }\n return 0;\n }\n\n #keyDescriptionForString(keyString: KeyInput): KeyDescription {\n const shift = this._modifiers & 8;\n const description = {\n key: '',\n keyCode: 0,\n code: '',\n text: '',\n location: 0,\n };\n\n const definition = _keyDefinitions[keyString];\n\n assert(definition, `Unknown key: \"${keyString}\"`);\n\n if (definition.key) {\n description.key = definition.key;\n }\n if (shift && definition.shiftKey) {\n description.key = definition.shiftKey;\n }\n\n if (definition.keyCode) {\n description.keyCode = definition.keyCode;\n }\n if (shift && definition.shiftKeyCode) {\n description.keyCode = definition.shiftKeyCode;\n }\n\n if (definition.code) {\n description.code = definition.code;\n }\n\n if (definition.location) {\n description.location = definition.location;\n }\n\n if (description.key.length === 1) {\n description.text = description.key;\n }\n\n if (definition.text) {\n description.text = definition.text;\n }\n if (shift && definition.shiftText) {\n description.text = definition.shiftText;\n }\n\n // if any modifiers besides shift are pressed, no text should be sent\n if (this._modifiers & ~8) {\n description.text = '';\n }\n\n return description;\n }\n\n async up(key: KeyInput): Promise<void> {\n const description = this.#keyDescriptionForString(key);\n\n this._modifiers &= ~this.#modifierBit(description.key);\n this.#pressedKeys.delete(description.code);\n await this.#client.send('Input.dispatchKeyEvent', {\n type: 'keyUp',\n modifiers: this._modifiers,\n key: description.key,\n windowsVirtualKeyCode: description.keyCode,\n code: description.code,\n location: description.location,\n });\n }\n\n async sendCharacter(char: string): Promise<void> {\n await this.#client.send('Input.insertText', { text: char });\n }\n\n private charIsKey(char: string): char is KeyInput {\n return !!_keyDefinitions[char as KeyInput];\n }\n\n async type(\n text: string,\n options: Readonly<KeyboardTypeOptions> = {},\n ): Promise<void> {\n const delay = options.delay || undefined;\n for (const char of text) {\n if (this.charIsKey(char)) {\n await this.press(char, { delay });\n } else {\n if (delay) {\n await new Promise((f) => {\n return setTimeout(f, delay);\n });\n }\n await this.sendCharacter(char);\n }\n }\n }\n\n async press(\n key: KeyInput | KeyInput[],\n options: Readonly<KeyPressOptions> = {},\n ): Promise<void> {\n const { delay = null } = options;\n const keys = Array.isArray(key) ? key : [key];\n\n for (const k of keys) {\n await this.down(k, options);\n }\n\n if (delay) {\n await new Promise((f) => {\n return setTimeout(f, options.delay);\n });\n }\n\n for (const k of [...keys].reverse()) {\n await this.up(k);\n }\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","_pressedKeys","_client","modifierBit","keyDescriptionForString","CdpKeyboard","client","options","undefined","description","autoRepeat","text","char","_keyDefinitions","delay","Promise","f","setTimeout","keys","Array","k","Set","keyString","shift","assert"],"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;;;;;;;;;ACJA;;;;CAIC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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GAAG;IAGpC,IAAId,WAAW,IAAI,EACjBc,YAAY,IAAI,GAAGd,WAAW,IAAI;IAEpC,IAAI4B,SAAS5B,WAAW,SAAS,EAC/Bc,YAAY,IAAI,GAAGd,WAAW,SAAS;IAIzC,IAAI,AAAkB,KAAlB,IAAI,CAAC,UAAU,EACjBc,YAAY,IAAI,GAAG;IAGrB,OAAOA;AACT"}
@@ -76,11 +76,11 @@ const injectStopWaterFlowAnimation = async ()=>{
76
76
  exports.getHtmlElementScript = __webpack_exports__.getHtmlElementScript;
77
77
  exports.injectStopWaterFlowAnimation = __webpack_exports__.injectStopWaterFlowAnimation;
78
78
  exports.injectWaterFlowAnimation = __webpack_exports__.injectWaterFlowAnimation;
79
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
79
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
80
80
  "getHtmlElementScript",
81
81
  "injectStopWaterFlowAnimation",
82
82
  "injectWaterFlowAnimation"
83
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
83
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
84
84
  Object.defineProperty(exports, '__esModule', {
85
85
  value: true
86
86
  });
@@ -1 +1 @@
1
- {"version":3,"file":"chrome-extension/dynamic-scripts.js","sources":["webpack://@midscene/web/webpack/runtime/compat_get_default_export","webpack://@midscene/web/webpack/runtime/define_property_getters","webpack://@midscene/web/webpack/runtime/has_own_property","webpack://@midscene/web/webpack/runtime/make_namespace_object","webpack://@midscene/web/./src/chrome-extension/dynamic-scripts.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 fs from 'node:fs';\nimport { ifInBrowser, ifInWorker } from '@midscene/shared/utils';\n\n// remember to include this file into extension's package\n// extract html element from page\nlet scriptFileContentCache: string | null = null;\nexport const getHtmlElementScript = async () => {\n const scriptFileToRetrieve = chrome.runtime.getURL('scripts/htmlElement.js');\n if (scriptFileContentCache) return scriptFileContentCache;\n if (ifInBrowser || ifInWorker) {\n const script = await fetch(scriptFileToRetrieve);\n scriptFileContentCache = await script.text();\n return scriptFileContentCache;\n }\n return fs.readFileSync(scriptFileToRetrieve, 'utf8');\n};\n\n// inject water flow animation\nlet waterFlowScriptFileContentCache: string | null = null;\nexport const injectWaterFlowAnimation = async () => {\n const waterFlowScriptFileToRetrieve = chrome.runtime.getURL(\n 'scripts/water-flow.js',\n );\n if (waterFlowScriptFileContentCache) return waterFlowScriptFileContentCache;\n if (ifInBrowser || ifInWorker) {\n const script = await fetch(waterFlowScriptFileToRetrieve);\n waterFlowScriptFileContentCache = await script.text();\n return waterFlowScriptFileContentCache;\n }\n return fs.readFileSync(waterFlowScriptFileToRetrieve, 'utf8');\n};\n\n// inject stop water flow animation\nlet stopWaterFlowScriptFileContentCache: string | null = null;\nexport const injectStopWaterFlowAnimation = async () => {\n const stopWaterFlowScriptFileToRetrieve = chrome.runtime.getURL(\n 'scripts/stop-water-flow.js',\n );\n if (stopWaterFlowScriptFileContentCache)\n return stopWaterFlowScriptFileContentCache;\n if (ifInBrowser || ifInWorker) {\n const script = await fetch(stopWaterFlowScriptFileToRetrieve);\n stopWaterFlowScriptFileContentCache = await script.text();\n return stopWaterFlowScriptFileContentCache;\n }\n return fs.readFileSync(stopWaterFlowScriptFileToRetrieve, 'utf8');\n};\n"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol","scriptFileContentCache","getHtmlElementScript","scriptFileToRetrieve","chrome","ifInBrowser","ifInWorker","script","fetch","fs","waterFlowScriptFileContentCache","injectWaterFlowAnimation","waterFlowScriptFileToRetrieve","stopWaterFlowScriptFileContentCache","injectStopWaterFlowAnimation","stopWaterFlowScriptFileToRetrieve"],"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;;;;;;;;;;;;ACDA,IAAII,yBAAwC;AACrC,MAAMC,uBAAuB;IAClC,MAAMC,uBAAuBC,OAAO,OAAO,CAAC,MAAM,CAAC;IACnD,IAAIH,wBAAwB,OAAOA;IACnC,IAAII,sBAAAA,WAAWA,IAAIC,sBAAAA,UAAUA,EAAE;QAC7B,MAAMC,SAAS,MAAMC,MAAML;QAC3BF,yBAAyB,MAAMM,OAAO,IAAI;QAC1C,OAAON;IACT;IACA,OAAOQ,2BAAAA,YAAe,CAACN,sBAAsB;AAC/C;AAGA,IAAIO,kCAAiD;AAC9C,MAAMC,2BAA2B;IACtC,MAAMC,gCAAgCR,OAAO,OAAO,CAAC,MAAM,CACzD;IAEF,IAAIM,iCAAiC,OAAOA;IAC5C,IAAIL,sBAAAA,WAAWA,IAAIC,sBAAAA,UAAUA,EAAE;QAC7B,MAAMC,SAAS,MAAMC,MAAMI;QAC3BF,kCAAkC,MAAMH,OAAO,IAAI;QACnD,OAAOG;IACT;IACA,OAAOD,2BAAAA,YAAe,CAACG,+BAA+B;AACxD;AAGA,IAAIC,sCAAqD;AAClD,MAAMC,+BAA+B;IAC1C,MAAMC,oCAAoCX,OAAO,OAAO,CAAC,MAAM,CAC7D;IAEF,IAAIS,qCACF,OAAOA;IACT,IAAIR,sBAAAA,WAAWA,IAAIC,sBAAAA,UAAUA,EAAE;QAC7B,MAAMC,SAAS,MAAMC,MAAMO;QAC3BF,sCAAsC,MAAMN,OAAO,IAAI;QACvD,OAAOM;IACT;IACA,OAAOJ,2BAAAA,YAAe,CAACM,mCAAmC;AAC5D"}
1
+ {"version":3,"file":"chrome-extension/dynamic-scripts.js","sources":["webpack/runtime/compat_get_default_export","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/chrome-extension/dynamic-scripts.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 fs from 'node:fs';\nimport { ifInBrowser, ifInWorker } from '@midscene/shared/utils';\n\n// remember to include this file into extension's package\n// extract html element from page\nlet scriptFileContentCache: string | null = null;\nexport const getHtmlElementScript = async () => {\n const scriptFileToRetrieve = chrome.runtime.getURL('scripts/htmlElement.js');\n if (scriptFileContentCache) return scriptFileContentCache;\n if (ifInBrowser || ifInWorker) {\n const script = await fetch(scriptFileToRetrieve);\n scriptFileContentCache = await script.text();\n return scriptFileContentCache;\n }\n return fs.readFileSync(scriptFileToRetrieve, 'utf8');\n};\n\n// inject water flow animation\nlet waterFlowScriptFileContentCache: string | null = null;\nexport const injectWaterFlowAnimation = async () => {\n const waterFlowScriptFileToRetrieve = chrome.runtime.getURL(\n 'scripts/water-flow.js',\n );\n if (waterFlowScriptFileContentCache) return waterFlowScriptFileContentCache;\n if (ifInBrowser || ifInWorker) {\n const script = await fetch(waterFlowScriptFileToRetrieve);\n waterFlowScriptFileContentCache = await script.text();\n return waterFlowScriptFileContentCache;\n }\n return fs.readFileSync(waterFlowScriptFileToRetrieve, 'utf8');\n};\n\n// inject stop water flow animation\nlet stopWaterFlowScriptFileContentCache: string | null = null;\nexport const injectStopWaterFlowAnimation = async () => {\n const stopWaterFlowScriptFileToRetrieve = chrome.runtime.getURL(\n 'scripts/stop-water-flow.js',\n );\n if (stopWaterFlowScriptFileContentCache)\n return stopWaterFlowScriptFileContentCache;\n if (ifInBrowser || ifInWorker) {\n const script = await fetch(stopWaterFlowScriptFileToRetrieve);\n stopWaterFlowScriptFileContentCache = await script.text();\n return stopWaterFlowScriptFileContentCache;\n }\n return fs.readFileSync(stopWaterFlowScriptFileToRetrieve, 'utf8');\n};\n"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol","scriptFileContentCache","getHtmlElementScript","scriptFileToRetrieve","chrome","ifInBrowser","ifInWorker","script","fetch","fs","waterFlowScriptFileContentCache","injectWaterFlowAnimation","waterFlowScriptFileToRetrieve","stopWaterFlowScriptFileContentCache","injectStopWaterFlowAnimation","stopWaterFlowScriptFileToRetrieve"],"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;;;;;;;;;;;;ACDA,IAAII,yBAAwC;AACrC,MAAMC,uBAAuB;IAClC,MAAMC,uBAAuBC,OAAO,OAAO,CAAC,MAAM,CAAC;IACnD,IAAIH,wBAAwB,OAAOA;IACnC,IAAII,sBAAAA,WAAWA,IAAIC,sBAAAA,UAAUA,EAAE;QAC7B,MAAMC,SAAS,MAAMC,MAAML;QAC3BF,yBAAyB,MAAMM,OAAO,IAAI;QAC1C,OAAON;IACT;IACA,OAAOQ,2BAAAA,YAAe,CAACN,sBAAsB;AAC/C;AAGA,IAAIO,kCAAiD;AAC9C,MAAMC,2BAA2B;IACtC,MAAMC,gCAAgCR,OAAO,OAAO,CAAC,MAAM,CACzD;IAEF,IAAIM,iCAAiC,OAAOA;IAC5C,IAAIL,sBAAAA,WAAWA,IAAIC,sBAAAA,UAAUA,EAAE;QAC7B,MAAMC,SAAS,MAAMC,MAAMI;QAC3BF,kCAAkC,MAAMH,OAAO,IAAI;QACnD,OAAOG;IACT;IACA,OAAOD,2BAAAA,YAAe,CAACG,+BAA+B;AACxD;AAGA,IAAIC,sCAAqD;AAClD,MAAMC,+BAA+B;IAC1C,MAAMC,oCAAoCX,OAAO,OAAO,CAAC,MAAM,CAC7D;IAEF,IAAIS,qCACF,OAAOA;IACT,IAAIR,sBAAAA,WAAWA,IAAIC,sBAAAA,UAAUA,EAAE;QAC7B,MAAMC,SAAS,MAAMC,MAAMO;QAC3BF,sCAAsC,MAAMN,OAAO,IAAI;QACvD,OAAOM;IACT;IACA,OAAOJ,2BAAAA,YAAe,CAACM,mCAAmC;AAC5D"}
@@ -34,8 +34,8 @@ var __webpack_exports__ = {};
34
34
  __webpack_require__.r(__webpack_exports__);
35
35
  __webpack_require__.d(__webpack_exports__, {
36
36
  ChromeExtensionProxyPage: ()=>external_page_js_default(),
37
- ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED: ()=>common_namespaceObject.ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED,
38
37
  overrideAIConfig: ()=>env_namespaceObject.overrideAIConfig,
38
+ ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED: ()=>common_namespaceObject.ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED,
39
39
  ChromeExtensionProxyPageAgent: ()=>external_agent_js_namespaceObject.ChromeExtensionProxyPageAgent
40
40
  });
41
41
  const common_namespaceObject = require("@midscene/shared/common");
@@ -47,12 +47,12 @@ exports.ChromeExtensionProxyPage = __webpack_exports__.ChromeExtensionProxyPage;
47
47
  exports.ChromeExtensionProxyPageAgent = __webpack_exports__.ChromeExtensionProxyPageAgent;
48
48
  exports.ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = __webpack_exports__.ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED;
49
49
  exports.overrideAIConfig = __webpack_exports__.overrideAIConfig;
50
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
50
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
51
51
  "ChromeExtensionProxyPage",
52
52
  "ChromeExtensionProxyPageAgent",
53
53
  "ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED",
54
54
  "overrideAIConfig"
55
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
55
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
56
56
  Object.defineProperty(exports, '__esModule', {
57
57
  value: true
58
58
  });
@@ -1 +1 @@
1
- {"version":3,"file":"chrome-extension/index.js","sources":["webpack://@midscene/web/webpack/runtime/compat_get_default_export","webpack://@midscene/web/webpack/runtime/define_property_getters","webpack://@midscene/web/webpack/runtime/has_own_property","webpack://@midscene/web/webpack/runtime/make_namespace_object"],"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};"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol"],"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"}
1
+ {"version":3,"file":"chrome-extension/index.js","sources":["webpack/runtime/compat_get_default_export","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object"],"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};"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol"],"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"}
@@ -76,52 +76,28 @@ class ChromeExtensionProxyPage {
76
76
  const tabId = await chrome.tabs.query({
77
77
  active: true,
78
78
  currentWindow: true
79
- }).then((tabs)=>{
80
- var _tabs_;
81
- return null == (_tabs_ = tabs[0]) ? void 0 : _tabs_.id;
82
- });
79
+ }).then((tabs)=>tabs[0]?.id);
83
80
  this.activeTabId = tabId || 0;
84
81
  return this.activeTabId;
85
82
  }
86
- async attachDebugger() {
83
+ async ensureDebuggerAttached() {
87
84
  (0, utils_namespaceObject.assert)(!this.destroyed, 'Page is destroyed');
88
- if (this.attachingDebugger) return void await this.attachingDebugger;
89
- this.attachingDebugger = (async ()=>{
90
- const url = await this.url();
91
- let error = null;
92
- if (url.startsWith('chrome://')) throw new Error('Cannot attach debugger to chrome:// pages, please use Midscene in a normal page with http://, https:// or file://');
93
- try {
94
- const currentTabId = await this.getTabIdOrConnectToCurrentTab();
95
- if (this.tabIdOfDebuggerAttached === currentTabId) return;
96
- if (this.tabIdOfDebuggerAttached && this.tabIdOfDebuggerAttached !== currentTabId) {
97
- console.log('detach the previous tab', this.tabIdOfDebuggerAttached, '->', currentTabId);
98
- try {
99
- await this.detachDebugger(this.tabIdOfDebuggerAttached);
100
- } catch (error) {
101
- console.error('Failed to detach debugger', error);
102
- }
103
- }
104
- console.log('attaching debugger', currentTabId);
105
- try {
106
- await chrome.debugger.attach({
107
- tabId: currentTabId
108
- }, '1.3');
109
- } catch (e) {
110
- if (this._continueWhenFailedToAttachDebugger) console.warn("Failed to attach debugger, but the script will continue as if the debugger is attached since the _continueWhenFailedToAttachDebugger is true", e);
111
- else throw e;
112
- }
113
- await sleep(500);
114
- this.tabIdOfDebuggerAttached = currentTabId;
115
- await this.enableWaterFlowAnimation();
116
- } catch (e) {
117
- console.error('Failed to attach debugger', e);
118
- error = e;
119
- } finally{
120
- this.attachingDebugger = null;
121
- }
122
- if (error) throw error;
123
- })();
124
- await this.attachingDebugger;
85
+ const url = await this.url();
86
+ if (url.startsWith('chrome://')) throw new Error('Cannot attach debugger to chrome:// pages, please use Midscene in a normal page with http://, https:// or file://');
87
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
88
+ try {
89
+ await chrome.debugger.attach({
90
+ tabId
91
+ }, '1.3');
92
+ console.log('Debugger attached to tab:', tabId);
93
+ } catch (error) {
94
+ const errorMsg = error?.message || '';
95
+ if (errorMsg.includes('Another debugger is already attached')) return void console.log('Debugger already attached to tab:', tabId);
96
+ if (this._continueWhenFailedToAttachDebugger) return void console.warn('Failed to attach debugger, but continuing due to _continueWhenFailedToAttachDebugger flag', error);
97
+ throw error;
98
+ }
99
+ await sleep(500);
100
+ await this.enableWaterFlowAnimation();
125
101
  }
126
102
  async showMousePointer(x, y) {
127
103
  const pointerScript = `(() => {
@@ -146,9 +122,8 @@ class ChromeExtensionProxyPage {
146
122
  });
147
123
  }
148
124
  async detachDebugger(tabId) {
149
- const tabIdToDetach = tabId || this.tabIdOfDebuggerAttached;
150
- console.log('detaching debugger', tabIdToDetach);
151
- if (!tabIdToDetach) return void console.warn('No tab id to detach');
125
+ const tabIdToDetach = tabId || await this.getTabIdOrConnectToCurrentTab();
126
+ console.log('detaching debugger from tab:', tabIdToDetach);
152
127
  try {
153
128
  await this.disableWaterFlowAnimation(tabIdToDetach);
154
129
  await sleep(200);
@@ -159,20 +134,21 @@ class ChromeExtensionProxyPage {
159
134
  await chrome.debugger.detach({
160
135
  tabId: tabIdToDetach
161
136
  });
137
+ console.log('Debugger detached successfully from tab:', tabIdToDetach);
162
138
  } catch (error) {
163
- console.warn('Failed to detach debugger', error);
139
+ console.warn('Failed to detach debugger (may already be detached):', error);
164
140
  }
165
- this.tabIdOfDebuggerAttached = null;
166
141
  }
167
142
  async enableWaterFlowAnimation() {
143
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
168
144
  if (this.forceSameTabNavigation) await chrome.debugger.sendCommand({
169
- tabId: this.tabIdOfDebuggerAttached
145
+ tabId
170
146
  }, 'Runtime.evaluate', {
171
147
  expression: external_web_element_js_namespaceObject.limitOpenNewTabScript
172
148
  });
173
149
  const script = await (0, external_dynamic_scripts_js_namespaceObject.injectWaterFlowAnimation)();
174
150
  await chrome.debugger.sendCommand({
175
- tabId: this.tabIdOfDebuggerAttached
151
+ tabId
176
152
  }, 'Runtime.evaluate', {
177
153
  expression: script
178
154
  });
@@ -185,13 +161,27 @@ class ChromeExtensionProxyPage {
185
161
  expression: script
186
162
  });
187
163
  }
188
- async sendCommandToDebugger(command, params) {
189
- await this.attachDebugger();
190
- (0, utils_namespaceObject.assert)(this.tabIdOfDebuggerAttached, 'Debugger is not attached');
191
- this.enableWaterFlowAnimation();
192
- return await chrome.debugger.sendCommand({
193
- tabId: this.tabIdOfDebuggerAttached
194
- }, command, params);
164
+ async sendCommandToDebugger(command, params, retryCount = 0) {
165
+ const MAX_RETRIES = 2;
166
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
167
+ try {
168
+ const result = await chrome.debugger.sendCommand({
169
+ tabId
170
+ }, command, params);
171
+ this.enableWaterFlowAnimation().catch((err)=>{
172
+ console.warn('Failed to enable water flow animation:', err);
173
+ });
174
+ return result;
175
+ } catch (error) {
176
+ const errorMsg = error?.message || '';
177
+ const isDetachError = errorMsg.includes('Debugger is not attached') || errorMsg.includes('Cannot access a Target') || errorMsg.includes('No target with given id');
178
+ if (isDetachError && retryCount < MAX_RETRIES) {
179
+ console.log(`Debugger not attached for command "${command}", attempting to attach (retry ${retryCount + 1}/${MAX_RETRIES})`);
180
+ await this.ensureDebuggerAttached();
181
+ return this.sendCommandToDebugger(command, params, retryCount + 1);
182
+ }
183
+ throw error;
184
+ }
195
185
  }
196
186
  async getPageContentByCDP() {
197
187
  const script = await (0, external_dynamic_scripts_js_namespaceObject.getHtmlElementScript)();
@@ -199,7 +189,6 @@ class ChromeExtensionProxyPage {
199
189
  expression: script
200
190
  });
201
191
  const expression = ()=>{
202
- window.midscene_element_inspector.setNodeHashCacheListOnWindow();
203
192
  const tree = window.midscene_element_inspector.webExtractNodeTree();
204
193
  return {
205
194
  tree,
@@ -215,8 +204,7 @@ class ChromeExtensionProxyPage {
215
204
  returnByValue: true
216
205
  });
217
206
  if (!returnValue.result.value) {
218
- var _returnValue_exceptionDetails_exception, _returnValue_exceptionDetails;
219
- const errorDescription = (null == (_returnValue_exceptionDetails = returnValue.exceptionDetails) ? void 0 : null == (_returnValue_exceptionDetails_exception = _returnValue_exceptionDetails.exception) ? void 0 : _returnValue_exceptionDetails_exception.description) || '';
207
+ const errorDescription = returnValue.exceptionDetails?.exception?.description || '';
220
208
  if (!errorDescription) console.error('returnValue from cdp', returnValue);
221
209
  throw new Error(`Failed to get page content from page, error: ${errorDescription}`);
222
210
  }
@@ -224,7 +212,8 @@ class ChromeExtensionProxyPage {
224
212
  }
225
213
  async evaluateJavaScript(script) {
226
214
  return this.sendCommandToDebugger('Runtime.evaluate', {
227
- expression: script
215
+ expression: script,
216
+ awaitPromise: true
228
217
  });
229
218
  }
230
219
  async beforeInvokeAction() {
@@ -250,18 +239,7 @@ class ChromeExtensionProxyPage {
250
239
  const tree = await this.getElementsNodeTree();
251
240
  return (0, extractor_namespaceObject.treeToList)(tree);
252
241
  }
253
- async getXpathsById(id) {
254
- const script = await (0, external_dynamic_scripts_js_namespaceObject.getHtmlElementScript)();
255
- await this.sendCommandToDebugger('Runtime.evaluate', {
256
- expression: script
257
- });
258
- const result = await this.sendCommandToDebugger('Runtime.evaluate', {
259
- expression: `window.midscene_element_inspector.getXpathsById(${JSON.stringify(id)})`,
260
- returnByValue: true
261
- });
262
- return result.result.value;
263
- }
264
- async getXpathsByPoint(point, isOrderSensitive) {
242
+ async getXpathsByPoint(point, isOrderSensitive = false) {
265
243
  const script = await (0, external_dynamic_scripts_js_namespaceObject.getHtmlElementScript)();
266
244
  await this.sendCommandToDebugger('Runtime.evaluate', {
267
245
  expression: script
@@ -286,8 +264,8 @@ class ChromeExtensionProxyPage {
286
264
  async getElementsNodeTree() {
287
265
  await this.hideMousePointer();
288
266
  const content = await this.getPageContentByCDP();
289
- if (null == content ? void 0 : content.size) this.viewportSize = content.size;
290
- return (null == content ? void 0 : content.tree) || {
267
+ if (content?.size) this.viewportSize = content.size;
268
+ return content?.tree || {
291
269
  node: null,
292
270
  children: []
293
271
  };
@@ -297,8 +275,14 @@ class ChromeExtensionProxyPage {
297
275
  }
298
276
  async size() {
299
277
  if (this.viewportSize) return this.viewportSize;
300
- const content = await this.getPageContentByCDP();
301
- return content.size;
278
+ const result = await this.sendCommandToDebugger('Runtime.evaluate', {
279
+ expression: '({width: document.documentElement.clientWidth, height: document.documentElement.clientHeight, dpr: window.devicePixelRatio})',
280
+ returnByValue: true
281
+ });
282
+ const sizeInfo = result.result.value;
283
+ console.log('sizeInfo', sizeInfo);
284
+ this.viewportSize = sizeInfo;
285
+ return sizeInfo;
302
286
  }
303
287
  async screenshotBase64() {
304
288
  await this.hideMousePointer();
@@ -314,6 +298,23 @@ class ChromeExtensionProxyPage {
314
298
  const url = await chrome.tabs.get(tabId).then((tab)=>tab.url);
315
299
  return url || '';
316
300
  }
301
+ async navigate(url) {
302
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
303
+ await chrome.tabs.update(tabId, {
304
+ url
305
+ });
306
+ await this.waitUntilNetworkIdle();
307
+ }
308
+ async reload() {
309
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
310
+ await chrome.tabs.reload(tabId);
311
+ await this.waitUntilNetworkIdle();
312
+ }
313
+ async goBack() {
314
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
315
+ await chrome.tabs.goBack(tabId);
316
+ await this.waitUntilNetworkIdle();
317
+ }
317
318
  async scrollUntilTop(startingPoint) {
318
319
  if (startingPoint) await this.mouse.move(startingPoint.left, startingPoint.top);
319
320
  return this.mouse.wheel(0, -9999999);
@@ -333,22 +334,22 @@ class ChromeExtensionProxyPage {
333
334
  async scrollUp(distance, startingPoint) {
334
335
  const { height } = await this.size();
335
336
  const scrollDistance = distance || 0.7 * height;
336
- return this.mouse.wheel(0, -scrollDistance, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
337
+ return this.mouse.wheel(0, -scrollDistance, startingPoint?.left, startingPoint?.top);
337
338
  }
338
339
  async scrollDown(distance, startingPoint) {
339
340
  const { height } = await this.size();
340
341
  const scrollDistance = distance || 0.7 * height;
341
- return this.mouse.wheel(0, scrollDistance, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
342
+ return this.mouse.wheel(0, scrollDistance, startingPoint?.left, startingPoint?.top);
342
343
  }
343
344
  async scrollLeft(distance, startingPoint) {
344
345
  const { width } = await this.size();
345
346
  const scrollDistance = distance || 0.7 * width;
346
- return this.mouse.wheel(-scrollDistance, 0, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
347
+ return this.mouse.wheel(-scrollDistance, 0, startingPoint?.left, startingPoint?.top);
347
348
  }
348
349
  async scrollRight(distance, startingPoint) {
349
350
  const { width } = await this.size();
350
351
  const scrollDistance = distance || 0.7 * width;
351
- return this.mouse.wheel(scrollDistance, 0, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
352
+ return this.mouse.wheel(scrollDistance, 0, startingPoint?.left, startingPoint?.top);
352
353
  }
353
354
  async clearInput(element) {
354
355
  if (!element) return void console.warn('No element to clear input');
@@ -371,9 +372,9 @@ class ChromeExtensionProxyPage {
371
372
  });
372
373
  }
373
374
  async destroy() {
375
+ this.destroyed = true;
374
376
  this.activeTabId = null;
375
377
  await this.detachDebugger();
376
- this.destroyed = true;
377
378
  }
378
379
  async longPress(x, y, duration) {
379
380
  duration = duration || 500;
@@ -383,14 +384,13 @@ class ChromeExtensionProxyPage {
383
384
  if (duration < MIN_PRESS_THRESHOLD) duration = MIN_PRESS_THRESHOLD;
384
385
  await this.mouse.move(x, y);
385
386
  if (null === this.isMobileEmulation) {
386
- var _result_result;
387
387
  const result = await this.sendCommandToDebugger('Runtime.evaluate', {
388
388
  expression: `(() => {
389
389
  return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
390
390
  })()`,
391
391
  returnByValue: true
392
392
  });
393
- this.isMobileEmulation = null == result ? void 0 : null == (_result_result = result.result) ? void 0 : _result_result.value;
393
+ this.isMobileEmulation = result?.result?.value;
394
394
  }
395
395
  if (this.isMobileEmulation) {
396
396
  const touchPoints = [
@@ -437,14 +437,13 @@ class ChromeExtensionProxyPage {
437
437
  if (duration < MIN_PRESS_THRESHOLD) duration = MIN_PRESS_THRESHOLD;
438
438
  if (duration > LONG_PRESS_THRESHOLD) duration = LONG_PRESS_THRESHOLD;
439
439
  if (null === this.isMobileEmulation) {
440
- var _result_result;
441
440
  const result = await this.sendCommandToDebugger('Runtime.evaluate', {
442
441
  expression: `(() => {
443
442
  return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
444
443
  })()`,
445
444
  returnByValue: true
446
445
  });
447
- this.isMobileEmulation = null == result ? void 0 : null == (_result_result = result.result) ? void 0 : _result_result.value;
446
+ this.isMobileEmulation = result?.result?.value;
448
447
  }
449
448
  const steps = 30;
450
449
  const delay = duration / steps;
@@ -510,8 +509,6 @@ class ChromeExtensionProxyPage {
510
509
  _define_property(this, "forceSameTabNavigation", void 0);
511
510
  _define_property(this, "viewportSize", void 0);
512
511
  _define_property(this, "activeTabId", null);
513
- _define_property(this, "tabIdOfDebuggerAttached", null);
514
- _define_property(this, "attachingDebugger", null);
515
512
  _define_property(this, "destroyed", false);
516
513
  _define_property(this, "isMobileEmulation", null);
517
514
  _define_property(this, "_continueWhenFailedToAttachDebugger", false);
@@ -522,14 +519,13 @@ class ChromeExtensionProxyPage {
522
519
  const { button = 'left', count = 1 } = options || {};
523
520
  await this.mouse.move(x, y);
524
521
  if (null === this.isMobileEmulation) {
525
- var _result_result;
526
522
  const result = await this.sendCommandToDebugger('Runtime.evaluate', {
527
523
  expression: `(() => {
528
524
  return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
529
525
  })()`,
530
526
  returnByValue: true
531
527
  });
532
- this.isMobileEmulation = null == result ? void 0 : null == (_result_result = result.result) ? void 0 : _result_result.value;
528
+ this.isMobileEmulation = result?.result?.value;
533
529
  }
534
530
  if (this.isMobileEmulation && 'left' === button) {
535
531
  const touchPoints = [
@@ -651,9 +647,9 @@ class ChromeExtensionProxyPage {
651
647
  }
652
648
  }
653
649
  exports["default"] = __webpack_exports__["default"];
654
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
650
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
655
651
  "default"
656
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
652
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
657
653
  Object.defineProperty(exports, '__esModule', {
658
654
  value: true
659
655
  });