@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.mjs","sources":["webpack://@midscene/web/./src/chrome-extension/cdpInput.ts"],"sourcesContent":["// 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":["_pressedKeys","_client","modifierBit","keyDescriptionForString","CdpKeyboard","client","key","options","undefined","description","autoRepeat","text","char","_keyDefinitions","delay","Promise","f","setTimeout","keys","Array","k","Set","keyString","shift","definition","assert"],"mappings":";;;AAEA;;;;CAIC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAmDCA,eAAAA,WAAAA,GAAAA,IAAAA,WAEAC,UAAAA,WAAAA,GAAAA,IAAAA,WAyCAC,eAAAA,WAAAA,GAAAA,IAAAA,WAgBAC,2BAAAA,WAAAA,GAAAA,IAAAA;AA5DK,MAAMC;IAWX,aAAaC,MAA0B,EAAQ;uCACxCJ,SAAUI;IACjB;IAEA,MAAM,KACJC,GAAa,EACbC,UAAoC;QAClC,MAAMC;QACN,UAAU,EAAE;IACd,CAAC,EACc;QACf,MAAMC,cAAc,8BAAI,EAACN,0BAAAA,yBAAAA,IAAAA,CAAL,IAAI,EAA0BG;QAElD,MAAMI,aAAa,6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ACT;AAEAH,SAAAA,wBAAyBmB,SAAmB;IAC1C,MAAMC,QAAQ,AAAkB,IAAlB,IAAI,CAAC,UAAU;IAC7B,MAAMd,cAAc;QAClB,KAAK;QACL,SAAS;QACT,MAAM;QACN,MAAM;QACN,UAAU;IACZ;IAEA,MAAMe,aAAaX,eAAe,CAACS,UAAU;IAE7CG,OAAOD,YAAY,CAAC,cAAc,EAAEF,UAAU,CAAC,CAAC;IAEhD,IAAIE,WAAW,GAAG,EAChBf,YAAY,GAAG,GAAGe,WAAW,GAAG;IAElC,IAAID,SAASC,WAAW,QAAQ,EAC9Bf,YAAY,GAAG,GAAGe,WAAW,QAAQ;IAGvC,IAAIA,WAAW,OAAO,EACpBf,YAAY,OAAO,GAAGe,WAAW,OAAO;IAE1C,IAAID,SAASC,WAAW,YAAY,EAClCf,YAAY,OAAO,GAAGe,WAAW,YAAY;IAG/C,IAAIA,WAAW,IAAI,EACjBf,YAAY,IAAI,GAAGe,WAAW,IAAI;IAGpC,IAAIA,WAAW,QAAQ,EACrBf,YAAY,QAAQ,GAAGe,WAAW,QAAQ;IAG5C,IAAIf,AAA2B,MAA3BA,YAAY,GAAG,CAAC,MAAM,EACxBA,YAAY,IAAI,GAAGA,YAAY,GAAG;IAGpC,IAAIe,WAAW,IAAI,EACjBf,YAAY,IAAI,GAAGe,WAAW,IAAI;IAEpC,IAAID,SAASC,WAAW,SAAS,EAC/Bf,YAAY,IAAI,GAAGe,WAAW,SAAS;IAIzC,IAAI,AAAkB,KAAlB,IAAI,CAAC,UAAU,EACjBf,YAAY,IAAI,GAAG;IAGrB,OAAOA;AACT"}
1
+ {"version":3,"file":"chrome-extension/cdpInput.mjs","sources":["../../../src/chrome-extension/cdpInput.ts"],"sourcesContent":["// 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":["_pressedKeys","_client","modifierBit","keyDescriptionForString","CdpKeyboard","client","key","options","undefined","description","autoRepeat","text","char","_keyDefinitions","delay","Promise","f","setTimeout","keys","Array","k","Set","keyString","shift","definition","assert"],"mappings":";;;AAEA;;;;CAIC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAmDCA,eAAAA,WAAAA,GAAAA,IAAAA,WAEAC,UAAAA,WAAAA,GAAAA,IAAAA,WAyCAC,eAAAA,WAAAA,GAAAA,IAAAA,WAgBAC,2BAAAA,WAAAA,GAAAA,IAAAA;AA5DK,MAAMC;IAWX,aAAaC,MAA0B,EAAQ;uCACxCJ,SAAUI;IACjB;IAEA,MAAM,KACJC,GAAa,EACbC,UAAoC;QAClC,MAAMC;QACN,UAAU,EAAE;IACd,CAAC,EACc;QACf,MAAMC,cAAc,8BAAI,EAACN,0BAAAA,yBAAAA,IAAAA,CAAL,IAAI,EAA0BG;QAElD,MAAMI,aAAa,6BAAI,EAACV,cAAa,GAAG,CAACS,YAAY,IAAI;QACzD,6BAAI,EAACT,cAAa,GAAG,CAACS,YAAY,IAAI;QACtC,IAAI,CAAC,UAAU,IAAI,8BAAI,EAACP,cAAAA,aAAAA,IAAAA,CAAL,IAAI,EAAcO,YAAY,GAAG;QAEpD,MAAME,OAAOJ,AAAiBC,WAAjBD,QAAQ,IAAI,GAAiBE,YAAY,IAAI,GAAGF,QAAQ,IAAI;QACzE,MAAM,6BAAI,EAACN,SAAQ,IAAI,CAAC,0BAA0B;YAChD,MAAMU,OAAO,YAAY;YACzB,WAAW,IAAI,CAAC,UAAU;YAC1B,uBAAuBF,YAAY,OAAO;YAC1C,MAAMA,YAAY,IAAI;YACtB,KAAKA,YAAY,GAAG;YACpB,M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1C,IAAID,SAASC,WAAW,YAAY,EAClCf,YAAY,OAAO,GAAGe,WAAW,YAAY;IAG/C,IAAIA,WAAW,IAAI,EACjBf,YAAY,IAAI,GAAGe,WAAW,IAAI;IAGpC,IAAIA,WAAW,QAAQ,EACrBf,YAAY,QAAQ,GAAGe,WAAW,QAAQ;IAG5C,IAAIf,AAA2B,MAA3BA,YAAY,GAAG,CAAC,MAAM,EACxBA,YAAY,IAAI,GAAGA,YAAY,GAAG;IAGpC,IAAIe,WAAW,IAAI,EACjBf,YAAY,IAAI,GAAGe,WAAW,IAAI;IAEpC,IAAID,SAASC,WAAW,SAAS,EAC/Bf,YAAY,IAAI,GAAGe,WAAW,SAAS;IAIzC,IAAI,AAAkB,KAAlB,IAAI,CAAC,UAAU,EACjBf,YAAY,IAAI,GAAG;IAGrB,OAAOA;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"chrome-extension/dynamic-scripts.mjs","sources":["webpack://@midscene/web/./src/chrome-extension/dynamic-scripts.ts"],"sourcesContent":["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":["scriptFileContentCache","getHtmlElementScript","scriptFileToRetrieve","chrome","ifInBrowser","ifInWorker","script","fetch","fs","waterFlowScriptFileContentCache","injectWaterFlowAnimation","waterFlowScriptFileToRetrieve","stopWaterFlowScriptFileContentCache","injectStopWaterFlowAnimation","stopWaterFlowScriptFileToRetrieve"],"mappings":";;AAKA,IAAIA,yBAAwC;AACrC,MAAMC,uBAAuB;IAClC,MAAMC,uBAAuBC,OAAO,OAAO,CAAC,MAAM,CAAC;IACnD,IAAIH,wBAAwB,OAAOA;IACnC,IAAII,eAAeC,YAAY;QAC7B,MAAMC,SAAS,MAAMC,MAAML;QAC3BF,yBAAyB,MAAMM,OAAO,IAAI;QAC1C,OAAON;IACT;IACA,OAAOQ,QAAAA,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,eAAeC,YAAY;QAC7B,MAAMC,SAAS,MAAMC,MAAMI;QAC3BF,kCAAkC,MAAMH,OAAO,IAAI;QACnD,OAAOG;IACT;IACA,OAAOD,QAAAA,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,eAAeC,YAAY;QAC7B,MAAMC,SAAS,MAAMC,MAAMO;QAC3BF,sCAAsC,MAAMN,OAAO,IAAI;QACvD,OAAOM;IACT;IACA,OAAOJ,QAAAA,YAAe,CAACM,mCAAmC;AAC5D"}
1
+ {"version":3,"file":"chrome-extension/dynamic-scripts.mjs","sources":["../../../src/chrome-extension/dynamic-scripts.ts"],"sourcesContent":["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":["scriptFileContentCache","getHtmlElementScript","scriptFileToRetrieve","chrome","ifInBrowser","ifInWorker","script","fetch","fs","waterFlowScriptFileContentCache","injectWaterFlowAnimation","waterFlowScriptFileToRetrieve","stopWaterFlowScriptFileContentCache","injectStopWaterFlowAnimation","stopWaterFlowScriptFileToRetrieve"],"mappings":";;AAKA,IAAIA,yBAAwC;AACrC,MAAMC,uBAAuB;IAClC,MAAMC,uBAAuBC,OAAO,OAAO,CAAC,MAAM,CAAC;IACnD,IAAIH,wBAAwB,OAAOA;IACnC,IAAII,eAAeC,YAAY;QAC7B,MAAMC,SAAS,MAAMC,MAAML;QAC3BF,yBAAyB,MAAMM,OAAO,IAAI;QAC1C,OAAON;IACT;IACA,OAAOQ,QAAAA,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,eAAeC,YAAY;QAC7B,MAAMC,SAAS,MAAMC,MAAMI;QAC3BF,kCAAkC,MAAMH,OAAO,IAAI;QACnD,OAAOG;IACT;IACA,OAAOD,QAAAA,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,eAAeC,YAAY;QAC7B,MAAMC,SAAS,MAAMC,MAAMO;QAC3BF,sCAAsC,MAAMN,OAAO,IAAI;QACvD,OAAOM;IACT;IACA,OAAOJ,QAAAA,YAAe,CAACM,mCAAmC;AAC5D"}
@@ -48,52 +48,28 @@ class ChromeExtensionProxyPage {
48
48
  const tabId = await chrome.tabs.query({
49
49
  active: true,
50
50
  currentWindow: true
51
- }).then((tabs)=>{
52
- var _tabs_;
53
- return null == (_tabs_ = tabs[0]) ? void 0 : _tabs_.id;
54
- });
51
+ }).then((tabs)=>tabs[0]?.id);
55
52
  this.activeTabId = tabId || 0;
56
53
  return this.activeTabId;
57
54
  }
58
- async attachDebugger() {
55
+ async ensureDebuggerAttached() {
59
56
  assert(!this.destroyed, 'Page is destroyed');
60
- if (this.attachingDebugger) return void await this.attachingDebugger;
61
- this.attachingDebugger = (async ()=>{
62
- const url = await this.url();
63
- let error = null;
64
- 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://');
65
- try {
66
- const currentTabId = await this.getTabIdOrConnectToCurrentTab();
67
- if (this.tabIdOfDebuggerAttached === currentTabId) return;
68
- if (this.tabIdOfDebuggerAttached && this.tabIdOfDebuggerAttached !== currentTabId) {
69
- console.log('detach the previous tab', this.tabIdOfDebuggerAttached, '->', currentTabId);
70
- try {
71
- await this.detachDebugger(this.tabIdOfDebuggerAttached);
72
- } catch (error) {
73
- console.error('Failed to detach debugger', error);
74
- }
75
- }
76
- console.log('attaching debugger', currentTabId);
77
- try {
78
- await chrome.debugger.attach({
79
- tabId: currentTabId
80
- }, '1.3');
81
- } catch (e) {
82
- 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);
83
- else throw e;
84
- }
85
- await sleep(500);
86
- this.tabIdOfDebuggerAttached = currentTabId;
87
- await this.enableWaterFlowAnimation();
88
- } catch (e) {
89
- console.error('Failed to attach debugger', e);
90
- error = e;
91
- } finally{
92
- this.attachingDebugger = null;
93
- }
94
- if (error) throw error;
95
- })();
96
- await this.attachingDebugger;
57
+ const url = await this.url();
58
+ 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://');
59
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
60
+ try {
61
+ await chrome.debugger.attach({
62
+ tabId
63
+ }, '1.3');
64
+ console.log('Debugger attached to tab:', tabId);
65
+ } catch (error) {
66
+ const errorMsg = error?.message || '';
67
+ if (errorMsg.includes('Another debugger is already attached')) return void console.log('Debugger already attached to tab:', tabId);
68
+ if (this._continueWhenFailedToAttachDebugger) return void console.warn('Failed to attach debugger, but continuing due to _continueWhenFailedToAttachDebugger flag', error);
69
+ throw error;
70
+ }
71
+ await sleep(500);
72
+ await this.enableWaterFlowAnimation();
97
73
  }
98
74
  async showMousePointer(x, y) {
99
75
  const pointerScript = `(() => {
@@ -118,9 +94,8 @@ class ChromeExtensionProxyPage {
118
94
  });
119
95
  }
120
96
  async detachDebugger(tabId) {
121
- const tabIdToDetach = tabId || this.tabIdOfDebuggerAttached;
122
- console.log('detaching debugger', tabIdToDetach);
123
- if (!tabIdToDetach) return void console.warn('No tab id to detach');
97
+ const tabIdToDetach = tabId || await this.getTabIdOrConnectToCurrentTab();
98
+ console.log('detaching debugger from tab:', tabIdToDetach);
124
99
  try {
125
100
  await this.disableWaterFlowAnimation(tabIdToDetach);
126
101
  await sleep(200);
@@ -131,20 +106,21 @@ class ChromeExtensionProxyPage {
131
106
  await chrome.debugger.detach({
132
107
  tabId: tabIdToDetach
133
108
  });
109
+ console.log('Debugger detached successfully from tab:', tabIdToDetach);
134
110
  } catch (error) {
135
- console.warn('Failed to detach debugger', error);
111
+ console.warn('Failed to detach debugger (may already be detached):', error);
136
112
  }
137
- this.tabIdOfDebuggerAttached = null;
138
113
  }
139
114
  async enableWaterFlowAnimation() {
115
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
140
116
  if (this.forceSameTabNavigation) await chrome.debugger.sendCommand({
141
- tabId: this.tabIdOfDebuggerAttached
117
+ tabId
142
118
  }, 'Runtime.evaluate', {
143
119
  expression: limitOpenNewTabScript
144
120
  });
145
121
  const script = await injectWaterFlowAnimation();
146
122
  await chrome.debugger.sendCommand({
147
- tabId: this.tabIdOfDebuggerAttached
123
+ tabId
148
124
  }, 'Runtime.evaluate', {
149
125
  expression: script
150
126
  });
@@ -157,13 +133,27 @@ class ChromeExtensionProxyPage {
157
133
  expression: script
158
134
  });
159
135
  }
160
- async sendCommandToDebugger(command, params) {
161
- await this.attachDebugger();
162
- assert(this.tabIdOfDebuggerAttached, 'Debugger is not attached');
163
- this.enableWaterFlowAnimation();
164
- return await chrome.debugger.sendCommand({
165
- tabId: this.tabIdOfDebuggerAttached
166
- }, command, params);
136
+ async sendCommandToDebugger(command, params, retryCount = 0) {
137
+ const MAX_RETRIES = 2;
138
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
139
+ try {
140
+ const result = await chrome.debugger.sendCommand({
141
+ tabId
142
+ }, command, params);
143
+ this.enableWaterFlowAnimation().catch((err)=>{
144
+ console.warn('Failed to enable water flow animation:', err);
145
+ });
146
+ return result;
147
+ } catch (error) {
148
+ const errorMsg = error?.message || '';
149
+ const isDetachError = errorMsg.includes('Debugger is not attached') || errorMsg.includes('Cannot access a Target') || errorMsg.includes('No target with given id');
150
+ if (isDetachError && retryCount < MAX_RETRIES) {
151
+ console.log(`Debugger not attached for command "${command}", attempting to attach (retry ${retryCount + 1}/${MAX_RETRIES})`);
152
+ await this.ensureDebuggerAttached();
153
+ return this.sendCommandToDebugger(command, params, retryCount + 1);
154
+ }
155
+ throw error;
156
+ }
167
157
  }
168
158
  async getPageContentByCDP() {
169
159
  const script = await getHtmlElementScript();
@@ -171,7 +161,6 @@ class ChromeExtensionProxyPage {
171
161
  expression: script
172
162
  });
173
163
  const expression = ()=>{
174
- window.midscene_element_inspector.setNodeHashCacheListOnWindow();
175
164
  const tree = window.midscene_element_inspector.webExtractNodeTree();
176
165
  return {
177
166
  tree,
@@ -187,8 +176,7 @@ class ChromeExtensionProxyPage {
187
176
  returnByValue: true
188
177
  });
189
178
  if (!returnValue.result.value) {
190
- var _returnValue_exceptionDetails_exception, _returnValue_exceptionDetails;
191
- const errorDescription = (null == (_returnValue_exceptionDetails = returnValue.exceptionDetails) ? void 0 : null == (_returnValue_exceptionDetails_exception = _returnValue_exceptionDetails.exception) ? void 0 : _returnValue_exceptionDetails_exception.description) || '';
179
+ const errorDescription = returnValue.exceptionDetails?.exception?.description || '';
192
180
  if (!errorDescription) console.error('returnValue from cdp', returnValue);
193
181
  throw new Error(`Failed to get page content from page, error: ${errorDescription}`);
194
182
  }
@@ -196,7 +184,8 @@ class ChromeExtensionProxyPage {
196
184
  }
197
185
  async evaluateJavaScript(script) {
198
186
  return this.sendCommandToDebugger('Runtime.evaluate', {
199
- expression: script
187
+ expression: script,
188
+ awaitPromise: true
200
189
  });
201
190
  }
202
191
  async beforeInvokeAction() {
@@ -222,18 +211,7 @@ class ChromeExtensionProxyPage {
222
211
  const tree = await this.getElementsNodeTree();
223
212
  return treeToList(tree);
224
213
  }
225
- async getXpathsById(id) {
226
- const script = await getHtmlElementScript();
227
- await this.sendCommandToDebugger('Runtime.evaluate', {
228
- expression: script
229
- });
230
- const result = await this.sendCommandToDebugger('Runtime.evaluate', {
231
- expression: `window.midscene_element_inspector.getXpathsById(${JSON.stringify(id)})`,
232
- returnByValue: true
233
- });
234
- return result.result.value;
235
- }
236
- async getXpathsByPoint(point, isOrderSensitive) {
214
+ async getXpathsByPoint(point, isOrderSensitive = false) {
237
215
  const script = await getHtmlElementScript();
238
216
  await this.sendCommandToDebugger('Runtime.evaluate', {
239
217
  expression: script
@@ -258,8 +236,8 @@ class ChromeExtensionProxyPage {
258
236
  async getElementsNodeTree() {
259
237
  await this.hideMousePointer();
260
238
  const content = await this.getPageContentByCDP();
261
- if (null == content ? void 0 : content.size) this.viewportSize = content.size;
262
- return (null == content ? void 0 : content.tree) || {
239
+ if (content?.size) this.viewportSize = content.size;
240
+ return content?.tree || {
263
241
  node: null,
264
242
  children: []
265
243
  };
@@ -269,8 +247,14 @@ class ChromeExtensionProxyPage {
269
247
  }
270
248
  async size() {
271
249
  if (this.viewportSize) return this.viewportSize;
272
- const content = await this.getPageContentByCDP();
273
- return content.size;
250
+ const result = await this.sendCommandToDebugger('Runtime.evaluate', {
251
+ expression: '({width: document.documentElement.clientWidth, height: document.documentElement.clientHeight, dpr: window.devicePixelRatio})',
252
+ returnByValue: true
253
+ });
254
+ const sizeInfo = result.result.value;
255
+ console.log('sizeInfo', sizeInfo);
256
+ this.viewportSize = sizeInfo;
257
+ return sizeInfo;
274
258
  }
275
259
  async screenshotBase64() {
276
260
  await this.hideMousePointer();
@@ -286,6 +270,23 @@ class ChromeExtensionProxyPage {
286
270
  const url = await chrome.tabs.get(tabId).then((tab)=>tab.url);
287
271
  return url || '';
288
272
  }
273
+ async navigate(url) {
274
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
275
+ await chrome.tabs.update(tabId, {
276
+ url
277
+ });
278
+ await this.waitUntilNetworkIdle();
279
+ }
280
+ async reload() {
281
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
282
+ await chrome.tabs.reload(tabId);
283
+ await this.waitUntilNetworkIdle();
284
+ }
285
+ async goBack() {
286
+ const tabId = await this.getTabIdOrConnectToCurrentTab();
287
+ await chrome.tabs.goBack(tabId);
288
+ await this.waitUntilNetworkIdle();
289
+ }
289
290
  async scrollUntilTop(startingPoint) {
290
291
  if (startingPoint) await this.mouse.move(startingPoint.left, startingPoint.top);
291
292
  return this.mouse.wheel(0, -9999999);
@@ -305,22 +306,22 @@ class ChromeExtensionProxyPage {
305
306
  async scrollUp(distance, startingPoint) {
306
307
  const { height } = await this.size();
307
308
  const scrollDistance = distance || 0.7 * height;
308
- return this.mouse.wheel(0, -scrollDistance, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
309
+ return this.mouse.wheel(0, -scrollDistance, startingPoint?.left, startingPoint?.top);
309
310
  }
310
311
  async scrollDown(distance, startingPoint) {
311
312
  const { height } = await this.size();
312
313
  const scrollDistance = distance || 0.7 * height;
313
- return this.mouse.wheel(0, scrollDistance, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
314
+ return this.mouse.wheel(0, scrollDistance, startingPoint?.left, startingPoint?.top);
314
315
  }
315
316
  async scrollLeft(distance, startingPoint) {
316
317
  const { width } = await this.size();
317
318
  const scrollDistance = distance || 0.7 * width;
318
- return this.mouse.wheel(-scrollDistance, 0, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
319
+ return this.mouse.wheel(-scrollDistance, 0, startingPoint?.left, startingPoint?.top);
319
320
  }
320
321
  async scrollRight(distance, startingPoint) {
321
322
  const { width } = await this.size();
322
323
  const scrollDistance = distance || 0.7 * width;
323
- return this.mouse.wheel(scrollDistance, 0, null == startingPoint ? void 0 : startingPoint.left, null == startingPoint ? void 0 : startingPoint.top);
324
+ return this.mouse.wheel(scrollDistance, 0, startingPoint?.left, startingPoint?.top);
324
325
  }
325
326
  async clearInput(element) {
326
327
  if (!element) return void console.warn('No element to clear input');
@@ -343,9 +344,9 @@ class ChromeExtensionProxyPage {
343
344
  });
344
345
  }
345
346
  async destroy() {
347
+ this.destroyed = true;
346
348
  this.activeTabId = null;
347
349
  await this.detachDebugger();
348
- this.destroyed = true;
349
350
  }
350
351
  async longPress(x, y, duration) {
351
352
  duration = duration || 500;
@@ -355,14 +356,13 @@ class ChromeExtensionProxyPage {
355
356
  if (duration < MIN_PRESS_THRESHOLD) duration = MIN_PRESS_THRESHOLD;
356
357
  await this.mouse.move(x, y);
357
358
  if (null === this.isMobileEmulation) {
358
- var _result_result;
359
359
  const result = await this.sendCommandToDebugger('Runtime.evaluate', {
360
360
  expression: `(() => {
361
361
  return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
362
362
  })()`,
363
363
  returnByValue: true
364
364
  });
365
- this.isMobileEmulation = null == result ? void 0 : null == (_result_result = result.result) ? void 0 : _result_result.value;
365
+ this.isMobileEmulation = result?.result?.value;
366
366
  }
367
367
  if (this.isMobileEmulation) {
368
368
  const touchPoints = [
@@ -409,14 +409,13 @@ class ChromeExtensionProxyPage {
409
409
  if (duration < MIN_PRESS_THRESHOLD) duration = MIN_PRESS_THRESHOLD;
410
410
  if (duration > LONG_PRESS_THRESHOLD) duration = LONG_PRESS_THRESHOLD;
411
411
  if (null === this.isMobileEmulation) {
412
- var _result_result;
413
412
  const result = await this.sendCommandToDebugger('Runtime.evaluate', {
414
413
  expression: `(() => {
415
414
  return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
416
415
  })()`,
417
416
  returnByValue: true
418
417
  });
419
- this.isMobileEmulation = null == result ? void 0 : null == (_result_result = result.result) ? void 0 : _result_result.value;
418
+ this.isMobileEmulation = result?.result?.value;
420
419
  }
421
420
  const steps = 30;
422
421
  const delay = duration / steps;
@@ -482,8 +481,6 @@ class ChromeExtensionProxyPage {
482
481
  _define_property(this, "forceSameTabNavigation", void 0);
483
482
  _define_property(this, "viewportSize", void 0);
484
483
  _define_property(this, "activeTabId", null);
485
- _define_property(this, "tabIdOfDebuggerAttached", null);
486
- _define_property(this, "attachingDebugger", null);
487
484
  _define_property(this, "destroyed", false);
488
485
  _define_property(this, "isMobileEmulation", null);
489
486
  _define_property(this, "_continueWhenFailedToAttachDebugger", false);
@@ -494,14 +491,13 @@ class ChromeExtensionProxyPage {
494
491
  const { button = 'left', count = 1 } = options || {};
495
492
  await this.mouse.move(x, y);
496
493
  if (null === this.isMobileEmulation) {
497
- var _result_result;
498
494
  const result = await this.sendCommandToDebugger('Runtime.evaluate', {
499
495
  expression: `(() => {
500
496
  return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
501
497
  })()`,
502
498
  returnByValue: true
503
499
  });
504
- this.isMobileEmulation = null == result ? void 0 : null == (_result_result = result.result) ? void 0 : _result_result.value;
500
+ this.isMobileEmulation = result?.result?.value;
505
501
  }
506
502
  if (this.isMobileEmulation && 'left' === button) {
507
503
  const touchPoints = [
@@ -1 +1 @@
1
- {"version":3,"file":"chrome-extension/page.mjs","sources":["webpack://@midscene/web/./src/chrome-extension/page.ts"],"sourcesContent":["/// <reference types=\"chrome\" />\n\n/*\n It is used to interact with the page tab from the chrome extension.\n The page must be active when interacting with it.\n*/\n\nimport { limitOpenNewTabScript } from '@/web-element';\nimport type { ElementTreeNode, Point, Size, UIContext } from '@midscene/core';\nimport type { AbstractInterface, DeviceAction } from '@midscene/core/device';\nimport type { ElementInfo } from '@midscene/shared/extractor';\nimport { treeToList } from '@midscene/shared/extractor';\nimport { createImgBase64ByFormat } from '@midscene/shared/img';\nimport { assert } from '@midscene/shared/utils';\nimport type { Protocol as CDPTypes } from 'devtools-protocol';\nimport { WebPageContextParser } from '../web-element';\nimport {\n type KeyInput,\n type MouseButton,\n commonWebActionsForWebPage,\n} from '../web-page';\nimport { CdpKeyboard } from './cdpInput';\nimport {\n getHtmlElementScript,\n injectStopWaterFlowAnimation,\n injectWaterFlowAnimation,\n} from './dynamic-scripts';\n\nfunction sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport default class ChromeExtensionProxyPage implements AbstractInterface {\n interfaceType = 'chrome-extension-proxy';\n\n public forceSameTabNavigation: boolean;\n\n private viewportSize?: Size;\n\n private activeTabId: number | null = null;\n\n private tabIdOfDebuggerAttached: number | null = null;\n\n private attachingDebugger: Promise<void> | null = null;\n\n private destroyed = false;\n\n private isMobileEmulation: boolean | null = null;\n\n public _continueWhenFailedToAttachDebugger = false;\n\n constructor(forceSameTabNavigation: boolean) {\n this.forceSameTabNavigation = forceSameTabNavigation;\n }\n\n actionSpace(): DeviceAction[] {\n return commonWebActionsForWebPage(this);\n }\n\n public async setActiveTabId(tabId: number) {\n if (this.activeTabId) {\n throw new Error(\n `Active tab id is already set, which is ${this.activeTabId}, cannot set it to ${tabId}`,\n );\n }\n await chrome.tabs.update(tabId, { active: true });\n this.activeTabId = tabId;\n }\n\n public async getActiveTabId() {\n return this.activeTabId;\n }\n\n /**\n * Get a list of current tabs\n * @returns {Promise<Array<{id: number, title: string, url: string}>>}\n */\n public async getBrowserTabList(): Promise<\n { id: string; title: string; url: string; currentActiveTab: boolean }[]\n > {\n const tabs = await chrome.tabs.query({ currentWindow: true });\n return tabs\n .map((tab) => ({\n id: `${tab.id}`,\n title: tab.title,\n url: tab.url,\n currentActiveTab: tab.active,\n }))\n .filter((tab) => tab.id && tab.title && tab.url) as {\n id: string;\n title: string;\n url: string;\n currentActiveTab: boolean;\n }[];\n }\n\n public async getTabIdOrConnectToCurrentTab() {\n if (this.activeTabId) {\n // alway keep on the connected tab\n return this.activeTabId;\n }\n const tabId = await chrome.tabs\n .query({ active: true, currentWindow: true })\n .then((tabs) => tabs[0]?.id);\n this.activeTabId = tabId || 0;\n return this.activeTabId;\n }\n\n private async attachDebugger() {\n assert(!this.destroyed, 'Page is destroyed');\n\n // If already attaching, wait for it to complete\n if (this.attachingDebugger) {\n await this.attachingDebugger;\n return;\n }\n\n // Create new attaching promise\n this.attachingDebugger = (async () => {\n const url = await this.url();\n let error: Error | null = null;\n if (url.startsWith('chrome://')) {\n throw new Error(\n 'Cannot attach debugger to chrome:// pages, please use Midscene in a normal page with http://, https:// or file://',\n );\n }\n\n try {\n const currentTabId = await this.getTabIdOrConnectToCurrentTab();\n\n if (this.tabIdOfDebuggerAttached === currentTabId) {\n // already attached\n return;\n }\n if (\n this.tabIdOfDebuggerAttached &&\n this.tabIdOfDebuggerAttached !== currentTabId\n ) {\n // detach the previous tab\n console.log(\n 'detach the previous tab',\n this.tabIdOfDebuggerAttached,\n '->',\n currentTabId,\n );\n try {\n await this.detachDebugger(this.tabIdOfDebuggerAttached);\n } catch (error) {\n console.error('Failed to detach debugger', error);\n }\n }\n\n // detach any debugger attached to the tab\n console.log('attaching debugger', currentTabId);\n try {\n await chrome.debugger.attach({ tabId: currentTabId }, '1.3');\n } catch (e) {\n if (this._continueWhenFailedToAttachDebugger) {\n console.warn(\n 'Failed to attach debugger, but the script will continue as if the debugger is attached since the _continueWhenFailedToAttachDebugger is true',\n e,\n );\n } else {\n throw e;\n }\n }\n\n // wait util the debugger banner in Chrome appears\n await sleep(500);\n\n this.tabIdOfDebuggerAttached = currentTabId;\n\n await this.enableWaterFlowAnimation();\n } catch (e) {\n console.error('Failed to attach debugger', e);\n error = e as Error;\n } finally {\n this.attachingDebugger = null;\n }\n if (error) {\n throw error;\n }\n })();\n\n await this.attachingDebugger;\n }\n\n private async showMousePointer(x: number, y: number) {\n // update mouse pointer while redirecting\n const pointerScript = `(() => {\n if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {\n window.midsceneWaterFlowAnimation.enable();\n window.midsceneWaterFlowAnimation.showMousePointer(${x}, ${y});\n } else {\n console.log('midsceneWaterFlowAnimation is not defined');\n }\n })()`;\n\n await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `${pointerScript}`,\n });\n }\n\n private async hideMousePointer() {\n await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `(() => {\n if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {\n window.midsceneWaterFlowAnimation.hideMousePointer();\n }\n })()`,\n });\n }\n\n private async detachDebugger(tabId?: number) {\n const tabIdToDetach = tabId || this.tabIdOfDebuggerAttached;\n console.log('detaching debugger', tabIdToDetach);\n if (!tabIdToDetach) {\n console.warn('No tab id to detach');\n return;\n }\n\n try {\n await this.disableWaterFlowAnimation(tabIdToDetach);\n await sleep(200); // wait for the animation to stop\n } catch (error) {\n console.warn('Failed to disable water flow animation', error);\n }\n\n try {\n await chrome.debugger.detach({ tabId: tabIdToDetach });\n } catch (error) {\n // maybe tab is closed ?\n console.warn('Failed to detach debugger', error);\n }\n this.tabIdOfDebuggerAttached = null;\n }\n\n private async enableWaterFlowAnimation() {\n // limit open page in new tab\n if (this.forceSameTabNavigation) {\n await chrome.debugger.sendCommand(\n { tabId: this.tabIdOfDebuggerAttached! },\n 'Runtime.evaluate',\n {\n expression: limitOpenNewTabScript,\n },\n );\n }\n\n const script = await injectWaterFlowAnimation();\n // we will call this function in sendCommandToDebugger, so we have to use the chrome.debugger.sendCommand\n await chrome.debugger.sendCommand(\n { tabId: this.tabIdOfDebuggerAttached! },\n 'Runtime.evaluate',\n {\n expression: script,\n },\n );\n }\n\n private async disableWaterFlowAnimation(tabId: number) {\n const script = await injectStopWaterFlowAnimation();\n\n await chrome.debugger.sendCommand({ tabId }, 'Runtime.evaluate', {\n expression: script,\n });\n }\n\n private async sendCommandToDebugger<ResponseType = any, RequestType = any>(\n command: string,\n params: RequestType,\n ): Promise<ResponseType> {\n await this.attachDebugger();\n\n assert(this.tabIdOfDebuggerAttached, 'Debugger is not attached');\n\n // wo don't have to await it\n this.enableWaterFlowAnimation();\n return (await chrome.debugger.sendCommand(\n { tabId: this.tabIdOfDebuggerAttached! },\n command,\n params as any,\n )) as ResponseType;\n }\n\n private async getPageContentByCDP() {\n const script = await getHtmlElementScript();\n\n // check tab url\n await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: script,\n });\n\n const expression = () => {\n (window as any).midscene_element_inspector.setNodeHashCacheListOnWindow();\n\n const tree = (\n window as any\n ).midscene_element_inspector.webExtractNodeTree();\n\n return {\n tree,\n size: {\n width: document.documentElement.clientWidth,\n height: document.documentElement.clientHeight,\n dpr: window.devicePixelRatio,\n },\n };\n };\n const returnValue = await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: `(${expression.toString()})()`,\n returnByValue: true,\n });\n\n if (!returnValue.result.value) {\n const errorDescription =\n returnValue.exceptionDetails?.exception?.description || '';\n if (!errorDescription) {\n console.error('returnValue from cdp', returnValue);\n }\n throw new Error(\n `Failed to get page content from page, error: ${errorDescription}`,\n );\n }\n\n return returnValue.result.value as {\n tree: ElementTreeNode<ElementInfo>;\n size: Size;\n };\n }\n\n public async evaluateJavaScript(script: string) {\n return this.sendCommandToDebugger('Runtime.evaluate', {\n expression: script,\n });\n }\n\n async beforeInvokeAction(): Promise<void> {\n // current implementation is wait until domReadyState is complete\n try {\n await this.waitUntilNetworkIdle();\n } catch (error) {\n // console.warn('Failed to wait until network idle', error);\n }\n }\n\n private async waitUntilNetworkIdle() {\n const timeout = 10000;\n const startTime = Date.now();\n let lastReadyState = '';\n while (Date.now() - startTime < timeout) {\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: 'document.readyState',\n });\n lastReadyState = result.result.value;\n if (lastReadyState === 'complete') {\n await new Promise((resolve) => setTimeout(resolve, 300));\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, 300));\n }\n throw new Error(\n `Failed to wait until network idle, last readyState: ${lastReadyState}`,\n );\n }\n\n // @deprecated\n async getElementsInfo() {\n const tree = await this.getElementsNodeTree();\n return treeToList(tree);\n }\n\n async getXpathsById(id: string) {\n const script = await getHtmlElementScript();\n\n // check tab url\n await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: script,\n });\n\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `window.midscene_element_inspector.getXpathsById(${JSON.stringify(id)})`,\n returnByValue: true,\n });\n return result.result.value;\n }\n\n async getXpathsByPoint(point: Point, isOrderSensitive: boolean) {\n const script = await getHtmlElementScript();\n\n await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: script,\n });\n\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `window.midscene_element_inspector.getXpathsByPoint({left: ${point.left}, top: ${point.top}}, ${isOrderSensitive})`,\n returnByValue: true,\n });\n return result.result.value;\n }\n\n async getElementInfoByXpath(xpath: string) {\n const script = await getHtmlElementScript();\n\n // check tab url\n await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: script,\n });\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `window.midscene_element_inspector.getElementInfoByXpath(${JSON.stringify(xpath)})`,\n returnByValue: true,\n });\n return result.result.value;\n }\n\n async getElementsNodeTree() {\n await this.hideMousePointer();\n const content = await this.getPageContentByCDP();\n if (content?.size) {\n this.viewportSize = content.size;\n }\n\n return content?.tree || { node: null, children: [] };\n }\n\n async getContext(): Promise<UIContext> {\n return await WebPageContextParser(this, {});\n }\n\n async size() {\n if (this.viewportSize) return this.viewportSize;\n const content = await this.getPageContentByCDP();\n return content.size;\n }\n\n async screenshotBase64() {\n // screenshot by cdp\n await this.hideMousePointer();\n const format = 'jpeg';\n const base64 = await this.sendCommandToDebugger('Page.captureScreenshot', {\n format,\n quality: 90,\n });\n return createImgBase64ByFormat(format, base64.data);\n }\n\n async url() {\n const tabId = await this.getTabIdOrConnectToCurrentTab();\n const url = await chrome.tabs.get(tabId).then((tab) => tab.url);\n return url || '';\n }\n\n async scrollUntilTop(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(0, -9999999);\n }\n\n async scrollUntilBottom(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(0, 9999999);\n }\n\n async scrollUntilLeft(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(-9999999, 0);\n }\n\n async scrollUntilRight(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(9999999, 0);\n }\n\n async scrollUp(distance?: number, startingPoint?: Point) {\n const { height } = await this.size();\n const scrollDistance = distance || height * 0.7;\n return this.mouse.wheel(\n 0,\n -scrollDistance,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollDown(distance?: number, startingPoint?: Point) {\n const { height } = await this.size();\n const scrollDistance = distance || height * 0.7;\n return this.mouse.wheel(\n 0,\n scrollDistance,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollLeft(distance?: number, startingPoint?: Point) {\n const { width } = await this.size();\n const scrollDistance = distance || width * 0.7;\n return this.mouse.wheel(\n -scrollDistance,\n 0,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollRight(distance?: number, startingPoint?: Point) {\n const { width } = await this.size();\n const scrollDistance = distance || width * 0.7;\n return this.mouse.wheel(\n scrollDistance,\n 0,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async clearInput(element: ElementInfo) {\n if (!element) {\n console.warn('No element to clear input');\n return;\n }\n\n await this.mouse.click(element.center[0], element.center[1]);\n\n await this.sendCommandToDebugger('Input.dispatchKeyEvent', {\n type: 'keyDown',\n commands: ['selectAll'],\n });\n\n await this.sendCommandToDebugger('Input.dispatchKeyEvent', {\n type: 'keyUp',\n commands: ['selectAll'],\n });\n\n await sleep(100);\n\n await this.keyboard.press({\n key: 'Backspace',\n });\n }\n\n private latestMouseX = 100;\n private latestMouseY = 100;\n\n mouse = {\n click: async (\n x: number,\n y: number,\n options?: { button?: MouseButton; count?: number },\n ) => {\n const { button = 'left', count = 1 } = options || {};\n await this.mouse.move(x, y);\n // detect if the page is in mobile emulation mode\n if (this.isMobileEmulation === null) {\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `(() => {\n return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);\n })()`,\n returnByValue: true,\n });\n this.isMobileEmulation = result?.result?.value;\n }\n\n if (this.isMobileEmulation && button === 'left') {\n // in mobile emulation mode, directly inject click event\n const touchPoints = [{ x: Math.round(x), y: Math.round(y) }];\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchStart',\n touchPoints,\n modifiers: 0,\n });\n\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchEnd',\n touchPoints: [],\n modifiers: 0,\n });\n } else {\n // standard mousePressed + mouseReleased\n for (let i = 0; i < count; i++) {\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x,\n y,\n button,\n clickCount: 1,\n });\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x,\n y,\n button,\n clickCount: 1,\n });\n await sleep(50);\n }\n }\n },\n wheel: async (\n deltaX: number,\n deltaY: number,\n startX?: number,\n startY?: number,\n ) => {\n const finalX = startX || this.latestMouseX;\n const finalY = startY || this.latestMouseY;\n await this.showMousePointer(finalX, finalY);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseWheel',\n x: finalX,\n y: finalY,\n deltaX,\n deltaY,\n });\n this.latestMouseX = finalX;\n this.latestMouseY = finalY;\n },\n move: async (x: number, y: number) => {\n await this.showMousePointer(x, y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseMoved',\n x,\n y,\n });\n this.latestMouseX = x;\n this.latestMouseY = y;\n },\n drag: async (\n from: { x: number; y: number },\n to: { x: number; y: number },\n ) => {\n await this.mouse.move(from.x, from.y);\n\n await sleep(200);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x: from.x,\n y: from.y,\n button: 'left',\n clickCount: 1,\n });\n\n await sleep(300);\n\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseMoved',\n x: to.x,\n y: to.y,\n });\n\n await sleep(500);\n\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x: to.x,\n y: to.y,\n button: 'left',\n clickCount: 1,\n });\n\n await sleep(200);\n\n await this.mouse.move(to.x, to.y);\n },\n };\n\n keyboard = {\n type: async (text: string) => {\n const cdpKeyboard = new CdpKeyboard({\n send: this.sendCommandToDebugger.bind(this),\n });\n await cdpKeyboard.type(text, { delay: 0 });\n },\n press: async (\n action:\n | { key: KeyInput; command?: string }\n | { key: KeyInput; command?: string }[],\n ) => {\n const cdpKeyboard = new CdpKeyboard({\n send: this.sendCommandToDebugger.bind(this),\n });\n const keys = Array.isArray(action) ? action : [action];\n for (const k of keys) {\n const commands = k.command ? [k.command] : [];\n await cdpKeyboard.down(k.key, { commands });\n }\n for (const k of [...keys].reverse()) {\n await cdpKeyboard.up(k.key);\n }\n },\n };\n\n async destroy(): Promise<void> {\n this.activeTabId = null;\n await this.detachDebugger();\n this.destroyed = true;\n }\n\n async longPress(x: number, y: number, duration?: number) {\n duration = duration || 500;\n const LONG_PRESS_THRESHOLD = 600;\n const MIN_PRESS_THRESHOLD = 300;\n if (duration > LONG_PRESS_THRESHOLD) {\n duration = LONG_PRESS_THRESHOLD;\n }\n if (duration < MIN_PRESS_THRESHOLD) {\n duration = MIN_PRESS_THRESHOLD;\n }\n await this.mouse.move(x, y);\n\n if (this.isMobileEmulation === null) {\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `(() => {\n return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);\n })()`,\n returnByValue: true,\n });\n this.isMobileEmulation = result?.result?.value;\n }\n\n if (this.isMobileEmulation) {\n const touchPoints = [{ x: Math.round(x), y: Math.round(y) }];\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchStart',\n touchPoints,\n modifiers: 0,\n });\n await new Promise((res) => setTimeout(res, duration));\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchEnd',\n touchPoints: [],\n modifiers: 0,\n });\n } else {\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x,\n y,\n button: 'left',\n clickCount: 1,\n });\n await new Promise((res) => setTimeout(res, duration));\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x,\n y,\n button: 'left',\n clickCount: 1,\n });\n }\n this.latestMouseX = x;\n this.latestMouseY = y;\n }\n\n async swipe(\n from: { x: number; y: number },\n to: { x: number; y: number },\n duration?: number,\n ) {\n const LONG_PRESS_THRESHOLD = 500;\n const MIN_PRESS_THRESHOLD = 150;\n duration = duration || 300;\n if (duration < MIN_PRESS_THRESHOLD) {\n duration = MIN_PRESS_THRESHOLD;\n }\n if (duration > LONG_PRESS_THRESHOLD) {\n duration = LONG_PRESS_THRESHOLD;\n }\n\n if (this.isMobileEmulation === null) {\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `(() => {\n return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);\n })()`,\n returnByValue: true,\n });\n this.isMobileEmulation = result?.result?.value;\n }\n\n const steps = 30;\n const delay = duration / steps;\n\n if (this.isMobileEmulation) {\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchStart',\n touchPoints: [{ x: Math.round(from.x), y: Math.round(from.y) }],\n modifiers: 0,\n });\n\n for (let i = 1; i <= steps; i++) {\n const x = from.x + (to.x - from.x) * (i / steps);\n const y = from.y + (to.y - from.y) * (i / steps);\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchMove',\n touchPoints: [{ x: Math.round(x), y: Math.round(y) }],\n modifiers: 0,\n });\n await new Promise((res) => setTimeout(res, delay));\n }\n\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchEnd',\n touchPoints: [],\n modifiers: 0,\n });\n } else {\n await this.mouse.move(from.x, from.y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x: from.x,\n y: from.y,\n button: 'left',\n clickCount: 1,\n });\n\n for (let i = 1; i <= steps; i++) {\n const x = from.x + (to.x - from.x) * (i / steps);\n const y = from.y + (to.y - from.y) * (i / steps);\n await this.mouse.move(x, y);\n await new Promise((res) => setTimeout(res, delay));\n }\n\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x: to.x,\n y: to.y,\n button: 'left',\n clickCount: 1,\n });\n }\n\n this.latestMouseX = to.x;\n this.latestMouseY = to.y;\n }\n}\n"],"names":["sleep","ms","Promise","resolve","setTimeout","ChromeExtensionProxyPage","commonWebActionsForWebPage","tabId","Error","chrome","tabs","tab","_tabs_","assert","url","error","currentTabId","console","e","x","y","pointerScript","tabIdToDetach","limitOpenNewTabScript","script","injectWaterFlowAnimation","injectStopWaterFlowAnimation","command","params","getHtmlElementScript","expression","window","tree","document","returnValue","_returnValue_exceptionDetails_exception","errorDescription","timeout","startTime","Date","lastReadyState","result","treeToList","id","JSON","point","isOrderSensitive","xpath","content","WebPageContextParser","format","base64","createImgBase64ByFormat","startingPoint","distance","height","scrollDistance","width","element","duration","LONG_PRESS_THRESHOLD","MIN_PRESS_THRESHOLD","_result_result","touchPoints","Math","res","from","to","steps","delay","i","forceSameTabNavigation","options","button","count","deltaX","deltaY","startX","startY","finalX","finalY","text","cdpKeyboard","CdpKeyboard","action","keys","Array","k","commands"],"mappings":";;;;;;;AAKA;;;;;;;;;;AAuBA,SAASA,MAAMC,EAAU;IACvB,OAAO,IAAIC,QAAQ,CAACC,UAAYC,WAAWD,SAASF;AACtD;AAEe,MAAMI;IAuBnB,cAA8B;QAC5B,OAAOC,2BAA2B,IAAI;IACxC;IAEA,MAAa,eAAeC,KAAa,EAAE;QACzC,IAAI,IAAI,CAAC,WAAW,EAClB,MAAM,IAAIC,MACR,CAAC,uCAAuC,EAAE,IAAI,CAAC,WAAW,CAAC,mBAAmB,EAAED,OAAO;QAG3F,MAAME,OAAO,IAAI,CAAC,MAAM,CAACF,OAAO;YAAE,QAAQ;QAAK;QAC/C,IAAI,CAAC,WAAW,GAAGA;IACrB;IAEA,MAAa,iBAAiB;QAC5B,OAAO,IAAI,CAAC,WAAW;IACzB;IAMA,MAAa,oBAEX;QACA,MAAMG,OAAO,MAAMD,OAAO,IAAI,CAAC,KAAK,CAAC;YAAE,eAAe;QAAK;QAC3D,OAAOC,KACJ,GAAG,CAAC,CAACC,MAAS;gBACb,IAAI,GAAGA,IAAI,EAAE,EAAE;g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gBACX,MAAMC,cAAc,IAAIC,YAAY;oBAClC,MAAM,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI;gBAC5C;gBACA,MAAMD,YAAY,IAAI,CAACD,MAAM;oBAAE,OAAO;gBAAE;YAC1C;YACA,OAAO,OACLG;gBAIA,MAAMF,cAAc,IAAIC,YAAY;oBAClC,MAAM,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI;gBAC5C;gBACA,MAAME,OAAOC,MAAM,OAAO,CAACF,UAAUA,SAAS;oBAACA;iBAAO;gBACtD,KAAK,MAAMG,KAAKF,KAAM;oBACpB,MAAMG,WAAWD,EAAE,OAAO,GAAG;wBAACA,EAAE,OAAO;qBAAC,GAAG,EAAE;oBAC7C,MAAML,YAAY,IAAI,CAACK,EAAE,GAAG,EAAE;wBAAEC;oBAAS;gBAC3C;gBACA,KAAK,MAAMD,KAAK;uBAAIF;iBAAK,CAAC,OAAO,GAC/B,MAAMH,YAAY,EAAE,CAACK,EAAE,GAAG;YAE9B;QACF;QArpBE,IAAI,CAAC,sBAAsB,GAAGhB;IAChC;AAoyBF"}
1
+ {"version":3,"file":"chrome-extension/page.mjs","sources":["../../../src/chrome-extension/page.ts"],"sourcesContent":["/// <reference types=\"chrome\" />\n\n/*\n It is used to interact with the page tab from the chrome extension.\n The page must be active when interacting with it.\n*/\n\nimport { limitOpenNewTabScript } from '@/web-element';\nimport type { ElementTreeNode, Point, Size, UIContext } from '@midscene/core';\nimport type { AbstractInterface, DeviceAction } from '@midscene/core/device';\nimport type { ElementInfo } from '@midscene/shared/extractor';\nimport { treeToList } from '@midscene/shared/extractor';\nimport { createImgBase64ByFormat } from '@midscene/shared/img';\nimport { assert } from '@midscene/shared/utils';\nimport type { Protocol as CDPTypes } from 'devtools-protocol';\nimport { WebPageContextParser } from '../web-element';\nimport {\n type KeyInput,\n type MouseButton,\n commonWebActionsForWebPage,\n} from '../web-page';\nimport { CdpKeyboard } from './cdpInput';\nimport {\n getHtmlElementScript,\n injectStopWaterFlowAnimation,\n injectWaterFlowAnimation,\n} from './dynamic-scripts';\n\nfunction sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport default class ChromeExtensionProxyPage implements AbstractInterface {\n interfaceType = 'chrome-extension-proxy';\n\n public forceSameTabNavigation: boolean;\n\n private viewportSize?: Size;\n\n private activeTabId: number | null = null;\n\n private destroyed = false;\n\n private isMobileEmulation: boolean | null = null;\n\n public _continueWhenFailedToAttachDebugger = false;\n\n constructor(forceSameTabNavigation: boolean) {\n this.forceSameTabNavigation = forceSameTabNavigation;\n }\n\n actionSpace(): DeviceAction[] {\n return commonWebActionsForWebPage(this);\n }\n\n public async setActiveTabId(tabId: number) {\n if (this.activeTabId) {\n throw new Error(\n `Active tab id is already set, which is ${this.activeTabId}, cannot set it to ${tabId}`,\n );\n }\n await chrome.tabs.update(tabId, { active: true });\n this.activeTabId = tabId;\n }\n\n public async getActiveTabId() {\n return this.activeTabId;\n }\n\n /**\n * Get a list of current tabs\n * @returns {Promise<Array<{id: number, title: string, url: string}>>}\n */\n public async getBrowserTabList(): Promise<\n { id: string; title: string; url: string; currentActiveTab: boolean }[]\n > {\n const tabs = await chrome.tabs.query({ currentWindow: true });\n return tabs\n .map((tab) => ({\n id: `${tab.id}`,\n title: tab.title,\n url: tab.url,\n currentActiveTab: tab.active,\n }))\n .filter((tab) => tab.id && tab.title && tab.url) as {\n id: string;\n title: string;\n url: string;\n currentActiveTab: boolean;\n }[];\n }\n\n public async getTabIdOrConnectToCurrentTab() {\n if (this.activeTabId) {\n // alway keep on the connected tab\n return this.activeTabId;\n }\n const tabId = await chrome.tabs\n .query({ active: true, currentWindow: true })\n .then((tabs) => tabs[0]?.id);\n this.activeTabId = tabId || 0;\n return this.activeTabId;\n }\n\n /**\n * Ensure debugger is attached to the current tab.\n * Uses lazy attach pattern - only attaches when needed.\n */\n private async ensureDebuggerAttached() {\n assert(!this.destroyed, 'Page is destroyed');\n\n const url = await this.url();\n if (url.startsWith('chrome://')) {\n throw new Error(\n 'Cannot attach debugger to chrome:// pages, please use Midscene in a normal page with http://, https:// or file://',\n );\n }\n\n const tabId = await this.getTabIdOrConnectToCurrentTab();\n\n try {\n await chrome.debugger.attach({ tabId }, '1.3');\n console.log('Debugger attached to tab:', tabId);\n } catch (error) {\n const errorMsg = (error as Error)?.message || '';\n // Already attached is OK, we can continue\n if (errorMsg.includes('Another debugger is already attached')) {\n console.log('Debugger already attached to tab:', tabId);\n return;\n }\n\n if (this._continueWhenFailedToAttachDebugger) {\n console.warn(\n 'Failed to attach debugger, but continuing due to _continueWhenFailedToAttachDebugger flag',\n error,\n );\n return;\n }\n\n throw error;\n }\n\n // Wait for debugger banner in Chrome to appear\n await sleep(500);\n\n // Enable water flow animation\n await this.enableWaterFlowAnimation();\n }\n\n private async showMousePointer(x: number, y: number) {\n // update mouse pointer while redirecting\n const pointerScript = `(() => {\n if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {\n window.midsceneWaterFlowAnimation.enable();\n window.midsceneWaterFlowAnimation.showMousePointer(${x}, ${y});\n } else {\n console.log('midsceneWaterFlowAnimation is not defined');\n }\n })()`;\n\n await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `${pointerScript}`,\n });\n }\n\n private async hideMousePointer() {\n await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `(() => {\n if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {\n window.midsceneWaterFlowAnimation.hideMousePointer();\n }\n })()`,\n });\n }\n\n /**\n * Public method to detach debugger without destroying the page instance.\n * Useful for error recovery scenarios where we want to remove the debugger banner\n * without completely destroying the page.\n */\n public async detachDebugger(tabId?: number) {\n const tabIdToDetach = tabId || (await this.getTabIdOrConnectToCurrentTab());\n console.log('detaching debugger from tab:', tabIdToDetach);\n\n try {\n await this.disableWaterFlowAnimation(tabIdToDetach);\n await sleep(200); // wait for the animation to stop\n } catch (error) {\n console.warn('Failed to disable water flow animation', error);\n }\n\n try {\n await chrome.debugger.detach({ tabId: tabIdToDetach });\n console.log('Debugger detached successfully from tab:', tabIdToDetach);\n } catch (error) {\n // Tab might be closed or debugger already detached - this is OK\n console.warn(\n 'Failed to detach debugger (may already be detached):',\n error,\n );\n }\n }\n\n private async enableWaterFlowAnimation() {\n const tabId = await this.getTabIdOrConnectToCurrentTab();\n\n // limit open page in new tab\n if (this.forceSameTabNavigation) {\n await chrome.debugger.sendCommand({ tabId }, 'Runtime.evaluate', {\n expression: limitOpenNewTabScript,\n });\n }\n\n const script = await injectWaterFlowAnimation();\n // we will call this function in sendCommandToDebugger, so we have to use the chrome.debugger.sendCommand\n await chrome.debugger.sendCommand({ tabId }, 'Runtime.evaluate', {\n expression: script,\n });\n }\n\n private async disableWaterFlowAnimation(tabId: number) {\n const script = await injectStopWaterFlowAnimation();\n\n await chrome.debugger.sendCommand({ tabId }, 'Runtime.evaluate', {\n expression: script,\n });\n }\n\n /**\n * Send a command to the debugger with automatic attach and retry on detachment.\n * Uses lazy attach pattern - will automatically attach if not already attached.\n */\n private async sendCommandToDebugger<ResponseType = any, RequestType = any>(\n command: string,\n params: RequestType,\n retryCount = 0,\n ): Promise<ResponseType> {\n const MAX_RETRIES = 2;\n const tabId = await this.getTabIdOrConnectToCurrentTab();\n\n try {\n // Try to send command directly first\n const result = (await chrome.debugger.sendCommand(\n { tabId },\n command,\n params as any,\n )) as ResponseType;\n\n // Enable water flow animation after successful command (don't await)\n this.enableWaterFlowAnimation().catch((err) => {\n console.warn('Failed to enable water flow animation:', err);\n });\n\n return result;\n } catch (error) {\n // If command failed, check if it's because debugger is not attached\n const errorMsg = (error as Error)?.message || '';\n const isDetachError =\n errorMsg.includes('Debugger is not attached') ||\n errorMsg.includes('Cannot access a Target') ||\n errorMsg.includes('No target with given id');\n\n if (isDetachError && retryCount < MAX_RETRIES) {\n console.log(\n `Debugger not attached for command \"${command}\", attempting to attach (retry ${retryCount + 1}/${MAX_RETRIES})`,\n );\n\n // Try to attach and retry\n await this.ensureDebuggerAttached();\n\n return this.sendCommandToDebugger<ResponseType, RequestType>(\n command,\n params,\n retryCount + 1,\n );\n }\n\n // Not a detach error or out of retries\n throw error;\n }\n }\n\n private async getPageContentByCDP() {\n const script = await getHtmlElementScript();\n\n // check tab url\n await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: script,\n });\n\n const expression = () => {\n const tree = (\n window as any\n ).midscene_element_inspector.webExtractNodeTree();\n\n return {\n tree,\n size: {\n width: document.documentElement.clientWidth,\n height: document.documentElement.clientHeight,\n dpr: window.devicePixelRatio,\n },\n };\n };\n const returnValue = await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: `(${expression.toString()})()`,\n returnByValue: true,\n });\n\n if (!returnValue.result.value) {\n const errorDescription =\n returnValue.exceptionDetails?.exception?.description || '';\n if (!errorDescription) {\n console.error('returnValue from cdp', returnValue);\n }\n throw new Error(\n `Failed to get page content from page, error: ${errorDescription}`,\n );\n }\n\n return returnValue.result.value as {\n tree: ElementTreeNode<ElementInfo>;\n size: Size;\n };\n }\n\n public async evaluateJavaScript(script: string) {\n return this.sendCommandToDebugger('Runtime.evaluate', {\n expression: script,\n awaitPromise: true,\n });\n }\n\n async beforeInvokeAction(): Promise<void> {\n // current implementation is wait until domReadyState is complete\n try {\n await this.waitUntilNetworkIdle();\n } catch (error) {\n // console.warn('Failed to wait until network idle', error);\n }\n }\n\n private async waitUntilNetworkIdle() {\n const timeout = 10000;\n const startTime = Date.now();\n let lastReadyState = '';\n while (Date.now() - startTime < timeout) {\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: 'document.readyState',\n });\n lastReadyState = result.result.value;\n if (lastReadyState === 'complete') {\n await new Promise((resolve) => setTimeout(resolve, 300));\n return;\n }\n await new Promise((resolve) => setTimeout(resolve, 300));\n }\n throw new Error(\n `Failed to wait until network idle, last readyState: ${lastReadyState}`,\n );\n }\n\n // @deprecated\n async getElementsInfo() {\n const tree = await this.getElementsNodeTree();\n return treeToList(tree);\n }\n\n async getXpathsByPoint(point: Point, isOrderSensitive = false) {\n const script = await getHtmlElementScript();\n\n await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: script,\n });\n\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `window.midscene_element_inspector.getXpathsByPoint({left: ${point.left}, top: ${point.top}}, ${isOrderSensitive})`,\n returnByValue: true,\n });\n return result.result.value;\n }\n\n async getElementInfoByXpath(xpath: string) {\n const script = await getHtmlElementScript();\n\n // check tab url\n await this.sendCommandToDebugger<\n CDPTypes.Runtime.EvaluateResponse,\n CDPTypes.Runtime.EvaluateRequest\n >('Runtime.evaluate', {\n expression: script,\n });\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `window.midscene_element_inspector.getElementInfoByXpath(${JSON.stringify(xpath)})`,\n returnByValue: true,\n });\n return result.result.value;\n }\n\n async getElementsNodeTree() {\n await this.hideMousePointer();\n const content = await this.getPageContentByCDP();\n if (content?.size) {\n this.viewportSize = content.size;\n }\n\n return content?.tree || { node: null, children: [] };\n }\n\n async getContext(): Promise<UIContext> {\n return await WebPageContextParser(this, {});\n }\n\n async size() {\n if (this.viewportSize) return this.viewportSize;\n\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression:\n '({width: document.documentElement.clientWidth, height: document.documentElement.clientHeight, dpr: window.devicePixelRatio})',\n returnByValue: true,\n });\n\n const sizeInfo: Size = result.result.value;\n console.log('sizeInfo', sizeInfo);\n\n this.viewportSize = sizeInfo;\n return sizeInfo;\n }\n\n async screenshotBase64() {\n // screenshot by cdp\n await this.hideMousePointer();\n const format = 'jpeg';\n const base64 = await this.sendCommandToDebugger('Page.captureScreenshot', {\n format,\n quality: 90,\n });\n return createImgBase64ByFormat(format, base64.data);\n }\n\n async url() {\n const tabId = await this.getTabIdOrConnectToCurrentTab();\n const url = await chrome.tabs.get(tabId).then((tab) => tab.url);\n return url || '';\n }\n\n async navigate(url: string): Promise<void> {\n const tabId = await this.getTabIdOrConnectToCurrentTab();\n await chrome.tabs.update(tabId, { url });\n // Wait for navigation to complete\n // Note: debugger will auto-reattach on next command if detached during navigation\n await this.waitUntilNetworkIdle();\n }\n\n async reload(): Promise<void> {\n const tabId = await this.getTabIdOrConnectToCurrentTab();\n await chrome.tabs.reload(tabId);\n // Wait for reload to complete\n await this.waitUntilNetworkIdle();\n }\n\n async goBack(): Promise<void> {\n const tabId = await this.getTabIdOrConnectToCurrentTab();\n await chrome.tabs.goBack(tabId);\n // Wait for navigation to complete\n await this.waitUntilNetworkIdle();\n }\n\n async scrollUntilTop(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(0, -9999999);\n }\n\n async scrollUntilBottom(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(0, 9999999);\n }\n\n async scrollUntilLeft(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(-9999999, 0);\n }\n\n async scrollUntilRight(startingPoint?: Point) {\n if (startingPoint) {\n await this.mouse.move(startingPoint.left, startingPoint.top);\n }\n return this.mouse.wheel(9999999, 0);\n }\n\n async scrollUp(distance?: number, startingPoint?: Point) {\n const { height } = await this.size();\n const scrollDistance = distance || height * 0.7;\n return this.mouse.wheel(\n 0,\n -scrollDistance,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollDown(distance?: number, startingPoint?: Point) {\n const { height } = await this.size();\n const scrollDistance = distance || height * 0.7;\n return this.mouse.wheel(\n 0,\n scrollDistance,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollLeft(distance?: number, startingPoint?: Point) {\n const { width } = await this.size();\n const scrollDistance = distance || width * 0.7;\n return this.mouse.wheel(\n -scrollDistance,\n 0,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async scrollRight(distance?: number, startingPoint?: Point) {\n const { width } = await this.size();\n const scrollDistance = distance || width * 0.7;\n return this.mouse.wheel(\n scrollDistance,\n 0,\n startingPoint?.left,\n startingPoint?.top,\n );\n }\n\n async clearInput(element: ElementInfo) {\n if (!element) {\n console.warn('No element to clear input');\n return;\n }\n\n await this.mouse.click(element.center[0], element.center[1]);\n\n await this.sendCommandToDebugger('Input.dispatchKeyEvent', {\n type: 'keyDown',\n commands: ['selectAll'],\n });\n\n await this.sendCommandToDebugger('Input.dispatchKeyEvent', {\n type: 'keyUp',\n commands: ['selectAll'],\n });\n\n await sleep(100);\n\n await this.keyboard.press({\n key: 'Backspace',\n });\n }\n\n private latestMouseX = 100;\n private latestMouseY = 100;\n\n mouse = {\n click: async (\n x: number,\n y: number,\n options?: { button?: MouseButton; count?: number },\n ) => {\n const { button = 'left', count = 1 } = options || {};\n await this.mouse.move(x, y);\n // detect if the page is in mobile emulation mode\n if (this.isMobileEmulation === null) {\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `(() => {\n return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);\n })()`,\n returnByValue: true,\n });\n this.isMobileEmulation = result?.result?.value;\n }\n\n if (this.isMobileEmulation && button === 'left') {\n // in mobile emulation mode, directly inject click event\n const touchPoints = [{ x: Math.round(x), y: Math.round(y) }];\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchStart',\n touchPoints,\n modifiers: 0,\n });\n\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchEnd',\n touchPoints: [],\n modifiers: 0,\n });\n } else {\n // standard mousePressed + mouseReleased\n for (let i = 0; i < count; i++) {\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x,\n y,\n button,\n clickCount: 1,\n });\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x,\n y,\n button,\n clickCount: 1,\n });\n await sleep(50);\n }\n }\n },\n wheel: async (\n deltaX: number,\n deltaY: number,\n startX?: number,\n startY?: number,\n ) => {\n const finalX = startX || this.latestMouseX;\n const finalY = startY || this.latestMouseY;\n await this.showMousePointer(finalX, finalY);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseWheel',\n x: finalX,\n y: finalY,\n deltaX,\n deltaY,\n });\n this.latestMouseX = finalX;\n this.latestMouseY = finalY;\n },\n move: async (x: number, y: number) => {\n await this.showMousePointer(x, y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseMoved',\n x,\n y,\n });\n this.latestMouseX = x;\n this.latestMouseY = y;\n },\n drag: async (\n from: { x: number; y: number },\n to: { x: number; y: number },\n ) => {\n await this.mouse.move(from.x, from.y);\n\n await sleep(200);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x: from.x,\n y: from.y,\n button: 'left',\n clickCount: 1,\n });\n\n await sleep(300);\n\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseMoved',\n x: to.x,\n y: to.y,\n });\n\n await sleep(500);\n\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x: to.x,\n y: to.y,\n button: 'left',\n clickCount: 1,\n });\n\n await sleep(200);\n\n await this.mouse.move(to.x, to.y);\n },\n };\n\n keyboard = {\n type: async (text: string) => {\n const cdpKeyboard = new CdpKeyboard({\n send: this.sendCommandToDebugger.bind(this),\n });\n await cdpKeyboard.type(text, { delay: 0 });\n },\n press: async (\n action:\n | { key: KeyInput; command?: string }\n | { key: KeyInput; command?: string }[],\n ) => {\n const cdpKeyboard = new CdpKeyboard({\n send: this.sendCommandToDebugger.bind(this),\n });\n const keys = Array.isArray(action) ? action : [action];\n for (const k of keys) {\n const commands = k.command ? [k.command] : [];\n await cdpKeyboard.down(k.key, { commands });\n }\n for (const k of [...keys].reverse()) {\n await cdpKeyboard.up(k.key);\n }\n },\n };\n\n async destroy(): Promise<void> {\n this.destroyed = true;\n this.activeTabId = null;\n await this.detachDebugger();\n }\n\n async longPress(x: number, y: number, duration?: number) {\n duration = duration || 500;\n const LONG_PRESS_THRESHOLD = 600;\n const MIN_PRESS_THRESHOLD = 300;\n if (duration > LONG_PRESS_THRESHOLD) {\n duration = LONG_PRESS_THRESHOLD;\n }\n if (duration < MIN_PRESS_THRESHOLD) {\n duration = MIN_PRESS_THRESHOLD;\n }\n await this.mouse.move(x, y);\n\n if (this.isMobileEmulation === null) {\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `(() => {\n return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);\n })()`,\n returnByValue: true,\n });\n this.isMobileEmulation = result?.result?.value;\n }\n\n if (this.isMobileEmulation) {\n const touchPoints = [{ x: Math.round(x), y: Math.round(y) }];\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchStart',\n touchPoints,\n modifiers: 0,\n });\n await new Promise((res) => setTimeout(res, duration));\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchEnd',\n touchPoints: [],\n modifiers: 0,\n });\n } else {\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x,\n y,\n button: 'left',\n clickCount: 1,\n });\n await new Promise((res) => setTimeout(res, duration));\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x,\n y,\n button: 'left',\n clickCount: 1,\n });\n }\n this.latestMouseX = x;\n this.latestMouseY = y;\n }\n\n async swipe(\n from: { x: number; y: number },\n to: { x: number; y: number },\n duration?: number,\n ) {\n const LONG_PRESS_THRESHOLD = 500;\n const MIN_PRESS_THRESHOLD = 150;\n duration = duration || 300;\n if (duration < MIN_PRESS_THRESHOLD) {\n duration = MIN_PRESS_THRESHOLD;\n }\n if (duration > LONG_PRESS_THRESHOLD) {\n duration = LONG_PRESS_THRESHOLD;\n }\n\n if (this.isMobileEmulation === null) {\n const result = await this.sendCommandToDebugger('Runtime.evaluate', {\n expression: `(() => {\n return /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);\n })()`,\n returnByValue: true,\n });\n this.isMobileEmulation = result?.result?.value;\n }\n\n const steps = 30;\n const delay = duration / steps;\n\n if (this.isMobileEmulation) {\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchStart',\n touchPoints: [{ x: Math.round(from.x), y: Math.round(from.y) }],\n modifiers: 0,\n });\n\n for (let i = 1; i <= steps; i++) {\n const x = from.x + (to.x - from.x) * (i / steps);\n const y = from.y + (to.y - from.y) * (i / steps);\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchMove',\n touchPoints: [{ x: Math.round(x), y: Math.round(y) }],\n modifiers: 0,\n });\n await new Promise((res) => setTimeout(res, delay));\n }\n\n await this.sendCommandToDebugger('Input.dispatchTouchEvent', {\n type: 'touchEnd',\n touchPoints: [],\n modifiers: 0,\n });\n } else {\n await this.mouse.move(from.x, from.y);\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mousePressed',\n x: from.x,\n y: from.y,\n button: 'left',\n clickCount: 1,\n });\n\n for (let i = 1; i <= steps; i++) {\n const x = from.x + (to.x - from.x) * (i / steps);\n const y = from.y + (to.y - from.y) * (i / steps);\n await this.mouse.move(x, y);\n await new Promise((res) => setTimeout(res, delay));\n }\n\n await this.sendCommandToDebugger('Input.dispatchMouseEvent', {\n type: 'mouseReleased',\n x: to.x,\n y: to.y,\n button: 'left',\n clickCount: 1,\n });\n }\n\n this.latestMouseX = to.x;\n this.latestMouseY = to.y;\n }\n}\n"],"names":["sleep","ms","Promise","resolve","setTimeout","ChromeExtensionProxyPage","commonWebActionsForWebPage","tabId","Error","chrome","tabs","tab","assert","url","console","error","errorMsg","x","y","pointerScript","tabIdToDetach","limitOpenNewTabScript","script","injectWaterFlowAnimation","injectStopWaterFlowAnimation","command","params","retryCount","MAX_RETRIES","result","err","isDetachError","getHtmlElementScript","expression","tree","window","document","returnValue","errorDescription","timeout","startTime","Date","lastReadyState","treeToList","point","isOrderSensitive","xpath","JSON","content","WebPageContextParser","sizeInfo","format","base64","createImgBase64ByFormat","startingPoint","distance","height","scrollDistance","width","element","duration","LONG_PRESS_THRESHOLD","MIN_PRESS_THRESHOLD","touchPoints","Math","res","from","to","steps","delay","i","forceSameTabNavigation","options","button","count","deltaX","deltaY","startX","startY","finalX","finalY","text","cdpKeyboard","CdpKeyboard","action","keys","Array","k","commands"],"mappings":";;;;;;;AAKA;;;;;;;;;;AAuBA,SAASA,MAAMC,EAAU;IACvB,OAAO,IAAIC,QAAQ,CAACC,UAAYC,WAAWD,SAASF;AACtD;AAEe,MAAMI;IAmBnB,cAA8B;QAC5B,OAAOC,2BAA2B,IAAI;IACxC;IAEA,MAAa,eAAeC,KAAa,EAAE;QACzC,IAAI,IAAI,CAAC,WAAW,EAClB,MAAM,IAAIC,MACR,CAAC,uCAAuC,EAAE,IAAI,CAAC,WAAW,CAAC,mBAAmB,EAAED,OAAO;QAG3F,MAAME,OAAO,IAAI,CAAC,MAAM,CAACF,OAAO;YAAE,QAAQ;QAAK;QAC/C,IAAI,CAAC,WAAW,GAAGA;IACrB;IAEA,MAAa,iBAAiB;QAC5B,OAAO,IAAI,CAAC,WAAW;IACzB;IAMA,MAAa,oBAEX;QACA,MAAMG,OAAO,MAAMD,OAAO,IAAI,CAAC,KAAK,CAAC;YAAE,eAAe;QAAK;QAC3D,OAAOC,KACJ,GAAG,CAAC,CAACC,MAAS;gBACb,IAAI,GAAGA,IAAI,EAAE,EAAE;gBACf,OAAOA,IAAI,KAAK;gBAChB,KAAKA,IAAI,GAAG;gBACZ,kBAAkBA,IAAI,MAAM;YAC9B,IACC,MAAM,CAAC,CAACA,MAAQA,IAAI,EAAE,IAAIA,IAAI,KAAK,IAAIA,IA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