@vforsh/argus-watcher 0.1.9 → 0.1.11

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 (289) hide show
  1. package/README.md +5 -1
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/buffer/NetBuffer.d.ts +35 -11
  4. package/dist/buffer/NetBuffer.d.ts.map +1 -1
  5. package/dist/buffer/NetBuffer.js +64 -55
  6. package/dist/buffer/NetBuffer.js.map +1 -1
  7. package/dist/buffer/RealtimeNetBuffer.d.ts +31 -0
  8. package/dist/buffer/RealtimeNetBuffer.d.ts.map +1 -0
  9. package/dist/buffer/RealtimeNetBuffer.js +190 -0
  10. package/dist/buffer/RealtimeNetBuffer.js.map +1 -0
  11. package/dist/cdp/accessibility.d.ts +12 -1
  12. package/dist/cdp/accessibility.d.ts.map +1 -1
  13. package/dist/cdp/accessibility.js +88 -45
  14. package/dist/cdp/accessibility.js.map +1 -1
  15. package/dist/cdp/auth.d.ts +31 -1
  16. package/dist/cdp/auth.d.ts.map +1 -1
  17. package/dist/cdp/auth.js +299 -10
  18. package/dist/cdp/auth.js.map +1 -1
  19. package/dist/cdp/authState.d.ts +9 -0
  20. package/dist/cdp/authState.d.ts.map +1 -0
  21. package/dist/cdp/authState.js +44 -0
  22. package/dist/cdp/authState.js.map +1 -0
  23. package/dist/cdp/browserCookies.d.ts +8 -0
  24. package/dist/cdp/browserCookies.d.ts.map +1 -0
  25. package/dist/cdp/browserCookies.js +160 -0
  26. package/dist/cdp/browserCookies.js.map +1 -0
  27. package/dist/cdp/dom/fill.d.ts +2 -1
  28. package/dist/cdp/dom/fill.d.ts.map +1 -1
  29. package/dist/cdp/dom/fill.js +7 -7
  30. package/dist/cdp/dom/fill.js.map +1 -1
  31. package/dist/cdp/dom/info.d.ts +4 -2
  32. package/dist/cdp/dom/info.d.ts.map +1 -1
  33. package/dist/cdp/dom/info.js +20 -11
  34. package/dist/cdp/dom/info.js.map +1 -1
  35. package/dist/cdp/dom/selector.d.ts +35 -0
  36. package/dist/cdp/dom/selector.d.ts.map +1 -1
  37. package/dist/cdp/dom/selector.js +118 -25
  38. package/dist/cdp/dom/selector.js.map +1 -1
  39. package/dist/cdp/dom/types.d.ts +1 -0
  40. package/dist/cdp/dom/types.d.ts.map +1 -1
  41. package/dist/cdp/editor.d.ts +5 -1
  42. package/dist/cdp/editor.d.ts.map +1 -1
  43. package/dist/cdp/editor.js +99 -3
  44. package/dist/cdp/editor.js.map +1 -1
  45. package/dist/cdp/elementRefs.d.ts +15 -0
  46. package/dist/cdp/elementRefs.d.ts.map +1 -0
  47. package/dist/cdp/elementRefs.js +30 -0
  48. package/dist/cdp/elementRefs.js.map +1 -0
  49. package/dist/cdp/eval.d.ts +1 -0
  50. package/dist/cdp/eval.d.ts.map +1 -1
  51. package/dist/cdp/eval.js +77 -29
  52. package/dist/cdp/eval.js.map +1 -1
  53. package/dist/cdp/locate.d.ts +7 -0
  54. package/dist/cdp/locate.d.ts.map +1 -0
  55. package/dist/cdp/locate.js +68 -0
  56. package/dist/cdp/locate.js.map +1 -0
  57. package/dist/cdp/mouse.d.ts +9 -8
  58. package/dist/cdp/mouse.d.ts.map +1 -1
  59. package/dist/cdp/mouse.js +41 -39
  60. package/dist/cdp/mouse.js.map +1 -1
  61. package/dist/cdp/networkBody.d.ts +19 -0
  62. package/dist/cdp/networkBody.d.ts.map +1 -0
  63. package/dist/cdp/networkBody.js +70 -0
  64. package/dist/cdp/networkBody.js.map +1 -0
  65. package/dist/cdp/networkCapture.d.ts +6 -0
  66. package/dist/cdp/networkCapture.d.ts.map +1 -1
  67. package/dist/cdp/networkCapture.js +315 -35
  68. package/dist/cdp/networkCapture.js.map +1 -1
  69. package/dist/cdp/networkRealtimeCapture.d.ts +23 -0
  70. package/dist/cdp/networkRealtimeCapture.d.ts.map +1 -0
  71. package/dist/cdp/networkRealtimeCapture.js +161 -0
  72. package/dist/cdp/networkRealtimeCapture.js.map +1 -0
  73. package/dist/cdp/redaction.d.ts +4 -0
  74. package/dist/cdp/redaction.d.ts.map +1 -1
  75. package/dist/cdp/redaction.js +37 -1
  76. package/dist/cdp/redaction.js.map +1 -1
  77. package/dist/cdp/screenshot.d.ts +1 -0
  78. package/dist/cdp/screenshot.d.ts.map +1 -1
  79. package/dist/cdp/screenshot.js +121 -22
  80. package/dist/cdp/screenshot.js.map +1 -1
  81. package/dist/cdp/storage.d.ts +8 -0
  82. package/dist/cdp/storage.d.ts.map +1 -0
  83. package/dist/cdp/storage.js +70 -0
  84. package/dist/cdp/storage.js.map +1 -0
  85. package/dist/cdp/watcher.d.ts +1 -0
  86. package/dist/cdp/watcher.d.ts.map +1 -1
  87. package/dist/cdp/watcher.js +5 -1
  88. package/dist/cdp/watcher.js.map +1 -1
  89. package/dist/dialogs/DialogTracker.d.ts +13 -0
  90. package/dist/dialogs/DialogTracker.d.ts.map +1 -0
  91. package/dist/dialogs/DialogTracker.js +22 -0
  92. package/dist/dialogs/DialogTracker.js.map +1 -0
  93. package/dist/events.d.ts +23 -3
  94. package/dist/events.d.ts.map +1 -1
  95. package/dist/http/routes/authCookies.d.ts +11 -0
  96. package/dist/http/routes/authCookies.d.ts.map +1 -0
  97. package/dist/http/routes/authCookies.js +142 -0
  98. package/dist/http/routes/authCookies.js.map +1 -0
  99. package/dist/http/routes/defineDomTargetRoute.d.ts +50 -0
  100. package/dist/http/routes/defineDomTargetRoute.d.ts.map +1 -0
  101. package/dist/http/routes/defineDomTargetRoute.js +45 -0
  102. package/dist/http/routes/defineDomTargetRoute.js.map +1 -0
  103. package/dist/http/routes/defineRoute.d.ts +30 -0
  104. package/dist/http/routes/defineRoute.d.ts.map +1 -0
  105. package/dist/http/routes/defineRoute.js +41 -0
  106. package/dist/http/routes/defineRoute.js.map +1 -0
  107. package/dist/http/routes/domSelectorRoute.d.ts +8 -0
  108. package/dist/http/routes/domSelectorRoute.d.ts.map +1 -1
  109. package/dist/http/routes/domSelectorRoute.js +28 -3
  110. package/dist/http/routes/domSelectorRoute.js.map +1 -1
  111. package/dist/http/routes/getAuthState.d.ts +3 -0
  112. package/dist/http/routes/getAuthState.d.ts.map +1 -0
  113. package/dist/http/routes/getAuthState.js +24 -0
  114. package/dist/http/routes/getAuthState.js.map +1 -0
  115. package/dist/http/routes/getDialog.d.ts +3 -0
  116. package/dist/http/routes/getDialog.d.ts.map +1 -0
  117. package/dist/http/routes/getDialog.js +11 -0
  118. package/dist/http/routes/getDialog.js.map +1 -0
  119. package/dist/http/routes/getExtensionTabs.d.ts +3 -0
  120. package/dist/http/routes/getExtensionTabs.d.ts.map +1 -0
  121. package/dist/http/routes/getExtensionTabs.js +22 -0
  122. package/dist/http/routes/getExtensionTabs.js.map +1 -0
  123. package/dist/http/routes/getNet.d.ts.map +1 -1
  124. package/dist/http/routes/getNet.js +14 -8
  125. package/dist/http/routes/getNet.js.map +1 -1
  126. package/dist/http/routes/getNetRequest.d.ts +3 -0
  127. package/dist/http/routes/getNetRequest.d.ts.map +1 -0
  128. package/dist/http/routes/getNetRequest.js +23 -0
  129. package/dist/http/routes/getNetRequest.js.map +1 -0
  130. package/dist/http/routes/getNetRequestBody.d.ts +3 -0
  131. package/dist/http/routes/getNetRequestBody.d.ts.map +1 -0
  132. package/dist/http/routes/getNetRequestBody.js +80 -0
  133. package/dist/http/routes/getNetRequestBody.js.map +1 -0
  134. package/dist/http/routes/getNetRequests.d.ts +3 -0
  135. package/dist/http/routes/getNetRequests.d.ts.map +1 -0
  136. package/dist/http/routes/getNetRequests.js +23 -0
  137. package/dist/http/routes/getNetRequests.js.map +1 -0
  138. package/dist/http/routes/getNetSse.d.ts +3 -0
  139. package/dist/http/routes/getNetSse.d.ts.map +1 -0
  140. package/dist/http/routes/getNetSse.js +23 -0
  141. package/dist/http/routes/getNetSse.js.map +1 -0
  142. package/dist/http/routes/getNetTail.d.ts.map +1 -1
  143. package/dist/http/routes/getNetTail.js +44 -9
  144. package/dist/http/routes/getNetTail.js.map +1 -1
  145. package/dist/http/routes/getNetWebSocketConnection.d.ts +3 -0
  146. package/dist/http/routes/getNetWebSocketConnection.d.ts.map +1 -0
  147. package/dist/http/routes/getNetWebSocketConnection.js +20 -0
  148. package/dist/http/routes/getNetWebSocketConnection.js.map +1 -0
  149. package/dist/http/routes/getNetWebSockets.d.ts +3 -0
  150. package/dist/http/routes/getNetWebSockets.d.ts.map +1 -0
  151. package/dist/http/routes/getNetWebSockets.js +23 -0
  152. package/dist/http/routes/getNetWebSockets.js.map +1 -0
  153. package/dist/http/routes/getStatus.js +2 -0
  154. package/dist/http/routes/getStatus.js.map +1 -1
  155. package/dist/http/routes/index.d.ts +2 -8
  156. package/dist/http/routes/index.d.ts.map +1 -1
  157. package/dist/http/routes/index.js +45 -6
  158. package/dist/http/routes/index.js.map +1 -1
  159. package/dist/http/routes/netFilters.d.ts +29 -0
  160. package/dist/http/routes/netFilters.d.ts.map +1 -0
  161. package/dist/http/routes/netFilters.js +161 -0
  162. package/dist/http/routes/netFilters.js.map +1 -0
  163. package/dist/http/routes/netRequestLookup.d.ts +14 -0
  164. package/dist/http/routes/netRequestLookup.d.ts.map +1 -0
  165. package/dist/http/routes/netRequestLookup.js +39 -0
  166. package/dist/http/routes/netRequestLookup.js.map +1 -0
  167. package/dist/http/routes/postAuthStateLoad.d.ts +3 -0
  168. package/dist/http/routes/postAuthStateLoad.d.ts.map +1 -0
  169. package/dist/http/routes/postAuthStateLoad.js +37 -0
  170. package/dist/http/routes/postAuthStateLoad.js.map +1 -0
  171. package/dist/http/routes/postCodeEdit.d.ts +3 -0
  172. package/dist/http/routes/postCodeEdit.d.ts.map +1 -0
  173. package/dist/http/routes/postCodeEdit.js +26 -0
  174. package/dist/http/routes/postCodeEdit.js.map +1 -0
  175. package/dist/http/routes/postDialog.d.ts +3 -0
  176. package/dist/http/routes/postDialog.d.ts.map +1 -0
  177. package/dist/http/routes/postDialog.js +39 -0
  178. package/dist/http/routes/postDialog.js.map +1 -0
  179. package/dist/http/routes/postDomClick.d.ts +2 -2
  180. package/dist/http/routes/postDomClick.d.ts.map +1 -1
  181. package/dist/http/routes/postDomClick.js +47 -61
  182. package/dist/http/routes/postDomClick.js.map +1 -1
  183. package/dist/http/routes/postDomFill.d.ts.map +1 -1
  184. package/dist/http/routes/postDomFill.js +19 -9
  185. package/dist/http/routes/postDomFill.js.map +1 -1
  186. package/dist/http/routes/postDomFocus.d.ts +1 -2
  187. package/dist/http/routes/postDomFocus.d.ts.map +1 -1
  188. package/dist/http/routes/postDomFocus.js +11 -28
  189. package/dist/http/routes/postDomFocus.js.map +1 -1
  190. package/dist/http/routes/postDomHover.d.ts +1 -2
  191. package/dist/http/routes/postDomHover.d.ts.map +1 -1
  192. package/dist/http/routes/postDomHover.js +11 -28
  193. package/dist/http/routes/postDomHover.js.map +1 -1
  194. package/dist/http/routes/postDomInfo.d.ts.map +1 -1
  195. package/dist/http/routes/postDomInfo.js +7 -3
  196. package/dist/http/routes/postDomInfo.js.map +1 -1
  197. package/dist/http/routes/postDomScroll.d.ts.map +1 -1
  198. package/dist/http/routes/postDomScroll.js +1 -1
  199. package/dist/http/routes/postDomScroll.js.map +1 -1
  200. package/dist/http/routes/postDomScrollTo.d.ts.map +1 -1
  201. package/dist/http/routes/postDomScrollTo.js +1 -1
  202. package/dist/http/routes/postDomScrollTo.js.map +1 -1
  203. package/dist/http/routes/postEval.d.ts.map +1 -1
  204. package/dist/http/routes/postEval.js +13 -0
  205. package/dist/http/routes/postEval.js.map +1 -1
  206. package/dist/http/routes/postLocate.d.ts +5 -0
  207. package/dist/http/routes/postLocate.d.ts.map +1 -0
  208. package/dist/http/routes/postLocate.js +67 -0
  209. package/dist/http/routes/postLocate.js.map +1 -0
  210. package/dist/http/routes/postNetClear.d.ts +3 -0
  211. package/dist/http/routes/postNetClear.d.ts.map +1 -0
  212. package/dist/http/routes/postNetClear.js +15 -0
  213. package/dist/http/routes/postNetClear.js.map +1 -0
  214. package/dist/http/routes/postScreenshot.d.ts.map +1 -1
  215. package/dist/http/routes/postScreenshot.js +35 -1
  216. package/dist/http/routes/postScreenshot.js.map +1 -1
  217. package/dist/http/routes/postSnapshot.d.ts.map +1 -1
  218. package/dist/http/routes/postSnapshot.js +1 -1
  219. package/dist/http/routes/postSnapshot.js.map +1 -1
  220. package/dist/http/routes/postStorageLocal.d.ts +1 -2
  221. package/dist/http/routes/postStorageLocal.d.ts.map +1 -1
  222. package/dist/http/routes/postStorageLocal.js +2 -30
  223. package/dist/http/routes/postStorageLocal.js.map +1 -1
  224. package/dist/http/routes/postStorageSession.d.ts +2 -0
  225. package/dist/http/routes/postStorageSession.d.ts.map +1 -0
  226. package/dist/http/routes/postStorageSession.js +3 -0
  227. package/dist/http/routes/postStorageSession.js.map +1 -0
  228. package/dist/http/routes/postVisibility.d.ts +3 -0
  229. package/dist/http/routes/postVisibility.d.ts.map +1 -0
  230. package/dist/http/routes/postVisibility.js +29 -0
  231. package/dist/http/routes/postVisibility.js.map +1 -0
  232. package/dist/http/routes/storage.d.ts +5 -0
  233. package/dist/http/routes/storage.d.ts.map +1 -0
  234. package/dist/http/routes/storage.js +43 -0
  235. package/dist/http/routes/storage.js.map +1 -0
  236. package/dist/http/server.d.ts +36 -10
  237. package/dist/http/server.d.ts.map +1 -1
  238. package/dist/http/server.js.map +1 -1
  239. package/dist/native-messaging/session-manager.d.ts +14 -1
  240. package/dist/native-messaging/session-manager.d.ts.map +1 -1
  241. package/dist/native-messaging/session-manager.js +56 -23
  242. package/dist/native-messaging/session-manager.js.map +1 -1
  243. package/dist/native-messaging/types.d.ts +28 -2
  244. package/dist/native-messaging/types.d.ts.map +1 -1
  245. package/dist/net/filtering.d.ts +32 -0
  246. package/dist/net/filtering.d.ts.map +1 -0
  247. package/dist/net/filtering.js +144 -0
  248. package/dist/net/filtering.js.map +1 -0
  249. package/dist/runtime/watcherServices.d.ts.map +1 -1
  250. package/dist/runtime/watcherServices.js +16 -4
  251. package/dist/runtime/watcherServices.js.map +1 -1
  252. package/dist/runtime/watcherSetup.d.ts +4 -0
  253. package/dist/runtime/watcherSetup.d.ts.map +1 -1
  254. package/dist/runtime/watcherSetup.js +5 -0
  255. package/dist/runtime/watcherSetup.js.map +1 -1
  256. package/dist/sources/cdp-source.d.ts.map +1 -1
  257. package/dist/sources/cdp-source.js +13 -0
  258. package/dist/sources/cdp-source.js.map +1 -1
  259. package/dist/sources/extension-delegating-session.d.ts +15 -2
  260. package/dist/sources/extension-delegating-session.d.ts.map +1 -1
  261. package/dist/sources/extension-delegating-session.js +16 -4
  262. package/dist/sources/extension-delegating-session.js.map +1 -1
  263. package/dist/sources/extension-frame-runtime.d.ts.map +1 -1
  264. package/dist/sources/extension-frame-runtime.js +35 -6
  265. package/dist/sources/extension-frame-runtime.js.map +1 -1
  266. package/dist/sources/extension-frame-state.d.ts +21 -2
  267. package/dist/sources/extension-frame-state.d.ts.map +1 -1
  268. package/dist/sources/extension-frame-state.js +63 -8
  269. package/dist/sources/extension-frame-state.js.map +1 -1
  270. package/dist/sources/extension-session-events.d.ts.map +1 -1
  271. package/dist/sources/extension-session-events.js +4 -2
  272. package/dist/sources/extension-session-events.js.map +1 -1
  273. package/dist/sources/extension-source.d.ts.map +1 -1
  274. package/dist/sources/extension-source.js +204 -50
  275. package/dist/sources/extension-source.js.map +1 -1
  276. package/dist/sources/types.d.ts +29 -1
  277. package/dist/sources/types.d.ts.map +1 -1
  278. package/dist/startWatcherRuntime.d.ts.map +1 -1
  279. package/dist/startWatcherRuntime.js +72 -2
  280. package/dist/startWatcherRuntime.js.map +1 -1
  281. package/dist/visibility/VisibilityController.d.ts +27 -0
  282. package/dist/visibility/VisibilityController.d.ts.map +1 -0
  283. package/dist/visibility/VisibilityController.js +48 -0
  284. package/dist/visibility/VisibilityController.js.map +1 -0
  285. package/package.json +2 -2
  286. package/dist/cdp/storageLocal.d.ts +0 -8
  287. package/dist/cdp/storageLocal.d.ts.map +0 -1
  288. package/dist/cdp/storageLocal.js +0 -70
  289. package/dist/cdp/storageLocal.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authState.d.ts","sourceRoot":"","sources":["../../src/cdp/authState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,KAAK,qBAAqB,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC9I,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEvD,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB,GAAU,OAAO;IACpD,OAAO,EAAE,gBAAgB,CAAA;IACzB,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B,KAAG,OAAO,CAAC,qBAAqB,CAqD9B,CAAA"}
@@ -0,0 +1,44 @@
1
+ import { buildAuthStateStorageSeedExpression, hydrateAuthState } from '@vforsh/argus-core';
2
+ /** Apply an auth-state snapshot to the currently attached watcher target. */
3
+ export const applyAuthStateToSession = async (input) => hydrateAuthState({
4
+ driver: {
5
+ setCookies: async (cookies) => {
6
+ await input.session.sendAndWait('Network.setCookies', {
7
+ cookies: cookies.map((cookie) => ({
8
+ name: cookie.name,
9
+ value: cookie.value,
10
+ domain: cookie.domain,
11
+ path: cookie.path,
12
+ secure: cookie.secure,
13
+ httpOnly: cookie.httpOnly,
14
+ sameSite: cookie.sameSite ?? undefined,
15
+ expires: cookie.session ? undefined : (cookie.expires ?? undefined),
16
+ })),
17
+ }, { timeoutMs: 5_000 });
18
+ },
19
+ navigateAndWait: async (url) => {
20
+ await input.session.sendAndWait('Page.navigate', { url }, { timeoutMs: 5_000 });
21
+ await input.session.sendAndWait('Runtime.evaluate', {
22
+ expression: `new Promise((resolve) => {
23
+ if (document.readyState === 'complete') {
24
+ resolve(true)
25
+ return
26
+ }
27
+ addEventListener('load', () => resolve(true), { once: true })
28
+ })`,
29
+ awaitPromise: true,
30
+ returnByValue: true,
31
+ }, { timeoutMs: 10_000 });
32
+ },
33
+ seedStorage: async (originState) => {
34
+ await input.session.sendAndWait('Runtime.evaluate', {
35
+ expression: buildAuthStateStorageSeedExpression(originState),
36
+ awaitPromise: false,
37
+ returnByValue: true,
38
+ }, { timeoutMs: 5_000 });
39
+ },
40
+ },
41
+ snapshot: input.snapshot,
42
+ startupUrl: input.startupUrl ?? null,
43
+ });
44
+ //# sourceMappingURL=authState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authState.js","sourceRoot":"","sources":["../../src/cdp/authState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,gBAAgB,EAAsD,MAAM,oBAAoB,CAAA;AAG9I,6EAA6E;AAC7E,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAAE,KAI7C,EAAkC,EAAE,CACpC,gBAAgB,CAAC;IAChB,MAAM,EAAE;QACP,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YAC7B,MAAM,KAAK,CAAC,OAAO,CAAC,WAAW,CAC9B,oBAAoB,EACpB;gBACC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;oBACjC,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,KAAK,EAAE,MAAM,CAAC,KAAK;oBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,SAAS;oBACtC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,SAAS,CAAC;iBACnE,CAAC,CAAC;aACH,EACD,EAAE,SAAS,EAAE,KAAK,EAAE,CACpB,CAAA;QACF,CAAC;QACD,eAAe,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YAC9B,MAAM,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,eAAe,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAA;YAC/E,MAAM,KAAK,CAAC,OAAO,CAAC,WAAW,CAC9B,kBAAkB,EAClB;gBACC,UAAU,EAAE;;;;;;SAMT;gBACH,YAAY,EAAE,IAAI;gBAClB,aAAa,EAAE,IAAI;aACnB,EACD,EAAE,SAAS,EAAE,MAAM,EAAE,CACrB,CAAA;QACF,CAAC;QACD,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE;YAClC,MAAM,KAAK,CAAC,OAAO,CAAC,WAAW,CAC9B,kBAAkB,EAClB;gBACC,UAAU,EAAE,mCAAmC,CAAC,WAAW,CAAC;gBAC5D,YAAY,EAAE,KAAK;gBACnB,aAAa,EAAE,IAAI;aACnB,EACD,EAAE,SAAS,EAAE,KAAK,EAAE,CACpB,CAAA;QACF,CAAC;KACD;IACD,QAAQ,EAAE,KAAK,CAAC,QAAQ;IACxB,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,IAAI;CACpC,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { AuthStateCookie, WatcherChrome } from '@vforsh/argus-core';
2
+ import type { CdpSourceCookieQuery } from '../sources/types.js';
3
+ /**
4
+ * Browser-target cookies are the only reliable way to capture sibling subdomain auth in CDP mode.
5
+ * Page-target `Network.getCookies` only sees the current document's request scope.
6
+ */
7
+ export declare const createCdpBrowserCookieReader: (chrome: WatcherChrome, getTargetId: () => string | null) => (query: CdpSourceCookieQuery) => Promise<AuthStateCookie[]>;
8
+ //# sourceMappingURL=browserCookies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserCookies.d.ts","sourceRoot":"","sources":["../../src/cdp/browserCookies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAExE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAkC/D;;;GAGG;AACH,eAAO,MAAM,4BAA4B,GACvC,QAAQ,aAAa,EAAE,aAAa,MAAM,MAAM,GAAG,IAAI,MACjD,OAAO,oBAAoB,KAAG,OAAO,CAAC,eAAe,EAAE,CAc7D,CAAA"}
@@ -0,0 +1,160 @@
1
+ import { matchesCookieDomain, normalizeCookieDomainFilter } from '@vforsh/argus-core';
2
+ const TARGET_INFO_REQUEST_ID = 1;
3
+ const STORAGE_GET_COOKIES_REQUEST_ID = 2;
4
+ const STORAGE_GET_COOKIES_FALLBACK_REQUEST_ID = 3;
5
+ /**
6
+ * Browser-target cookies are the only reliable way to capture sibling subdomain auth in CDP mode.
7
+ * Page-target `Network.getCookies` only sees the current document's request scope.
8
+ */
9
+ export const createCdpBrowserCookieReader = (chrome, getTargetId) => async (query) => {
10
+ const host = chrome.host ?? '127.0.0.1';
11
+ const port = chrome.port ?? 9222;
12
+ const version = await fetchChromeVersion(host, port);
13
+ const wsUrl = version.webSocketDebuggerUrl;
14
+ if (!wsUrl) {
15
+ throw new Error(`Chrome browser websocket missing at ${host}:${port}`);
16
+ }
17
+ const browserContextId = await readTargetBrowserContextId(wsUrl, getTargetId());
18
+ const payload = await readBrowserCookiesPayload(wsUrl, browserContextId);
19
+ const normalizedDomain = normalizeCookieDomainFilter(query.domain ?? null);
20
+ return (payload.cookies ?? []).map(normalizeBrowserCookie).filter((cookie) => matchesCookieDomain(cookie.domain, normalizedDomain));
21
+ };
22
+ const fetchChromeVersion = async (host, port) => {
23
+ const response = await fetch(`http://${host}:${port}/json/version`, {
24
+ signal: AbortSignal.timeout(5_000),
25
+ });
26
+ if (!response.ok) {
27
+ throw new Error(`Chrome version endpoint failed with ${response.status}`);
28
+ }
29
+ return (await response.json());
30
+ };
31
+ const normalizeBrowserCookie = (cookie) => ({
32
+ name: cookie.name ?? '',
33
+ value: cookie.value ?? '',
34
+ domain: cookie.domain ?? '',
35
+ path: cookie.path ?? '/',
36
+ secure: cookie.secure === true,
37
+ httpOnly: cookie.httpOnly === true,
38
+ session: cookie.session === true,
39
+ expires: typeof cookie.expires === 'number' && Number.isFinite(cookie.expires) ? cookie.expires : null,
40
+ sameSite: cookie.sameSite ?? null,
41
+ });
42
+ const readTargetBrowserContextId = async (wsUrl, targetId) => {
43
+ if (!targetId) {
44
+ return null;
45
+ }
46
+ const response = await sendBrowserCommand(wsUrl, {
47
+ id: TARGET_INFO_REQUEST_ID,
48
+ method: 'Target.getTargetInfo',
49
+ params: { targetId },
50
+ });
51
+ return response.targetInfo?.browserContextId ?? null;
52
+ };
53
+ const readBrowserCookiesPayload = async (wsUrl, browserContextId) => {
54
+ try {
55
+ return await sendBrowserCommand(wsUrl, {
56
+ id: STORAGE_GET_COOKIES_REQUEST_ID,
57
+ method: 'Storage.getCookies',
58
+ params: browserContextId ? { browserContextId } : undefined,
59
+ });
60
+ }
61
+ catch (error) {
62
+ if (!browserContextId || !isMissingBrowserContextError(error)) {
63
+ throw error;
64
+ }
65
+ return await sendBrowserCommand(wsUrl, {
66
+ id: STORAGE_GET_COOKIES_FALLBACK_REQUEST_ID,
67
+ method: 'Storage.getCookies',
68
+ });
69
+ }
70
+ };
71
+ const isMissingBrowserContextError = (error) => error instanceof Error && /browser context/i.test(error.message);
72
+ const sendBrowserCommand = async (wsUrl, payload, timeoutMs = 5_000) => {
73
+ const WebSocketConstructor = getWebSocketCtor();
74
+ if (!WebSocketConstructor) {
75
+ throw new Error('WebSocket unavailable. Node 18+ required.');
76
+ }
77
+ const ws = new WebSocketConstructor(wsUrl);
78
+ return await new Promise((resolve, reject) => {
79
+ let settled = false;
80
+ const timer = setTimeout(() => finish(undefined, new Error(`CDP command timed out after ${timeoutMs}ms`)), timeoutMs);
81
+ const cleanup = () => {
82
+ clearTimeout(timer);
83
+ ws.removeEventListener?.('open', onOpen);
84
+ ws.removeEventListener?.('message', onMessage);
85
+ ws.removeEventListener?.('error', onError);
86
+ ws.removeEventListener?.('close', onClose);
87
+ };
88
+ const finish = (result, error) => {
89
+ if (settled) {
90
+ return;
91
+ }
92
+ settled = true;
93
+ cleanup();
94
+ try {
95
+ ws.close();
96
+ }
97
+ catch { }
98
+ if (error) {
99
+ reject(error);
100
+ return;
101
+ }
102
+ resolve(result);
103
+ };
104
+ const onOpen = () => {
105
+ try {
106
+ ws.send(JSON.stringify(payload));
107
+ }
108
+ catch (error) {
109
+ finish(undefined, error instanceof Error ? error : new Error(String(error)));
110
+ }
111
+ };
112
+ const onMessage = (event) => {
113
+ const text = toMessageText(event.data);
114
+ if (!text) {
115
+ return;
116
+ }
117
+ try {
118
+ const message = JSON.parse(text);
119
+ if (message.id !== payload.id) {
120
+ return;
121
+ }
122
+ if (message.error?.message) {
123
+ finish(undefined, new Error(message.error.message));
124
+ return;
125
+ }
126
+ finish(message.result);
127
+ }
128
+ catch (error) {
129
+ finish(undefined, error instanceof Error ? error : new Error(String(error)));
130
+ }
131
+ };
132
+ const onError = () => {
133
+ finish(undefined, new Error('WebSocket error'));
134
+ };
135
+ const onClose = () => {
136
+ finish(undefined, new Error('WebSocket closed before response'));
137
+ };
138
+ ws.addEventListener('open', onOpen);
139
+ ws.addEventListener('message', onMessage);
140
+ ws.addEventListener('error', onError);
141
+ ws.addEventListener('close', onClose);
142
+ });
143
+ };
144
+ const getWebSocketCtor = () => {
145
+ const ctor = globalThis.WebSocket;
146
+ return ctor ?? null;
147
+ };
148
+ const toMessageText = (data) => {
149
+ if (typeof data === 'string') {
150
+ return data;
151
+ }
152
+ if (data instanceof ArrayBuffer) {
153
+ return Buffer.from(data).toString('utf8');
154
+ }
155
+ if (Buffer.isBuffer(data)) {
156
+ return data.toString('utf8');
157
+ }
158
+ return null;
159
+ };
160
+ //# sourceMappingURL=browserCookies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserCookies.js","sourceRoot":"","sources":["../../src/cdp/browserCookies.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AA+BrF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AC,CAAA;QACzC,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACrC,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;AACH,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG,GAAyB,EAAE;IACnD,MAAM,IAAI,GAAI,UAA4C,CAAC,SAAS,CAAA;IACpE,OAAO,IAAI,IAAI,IAAI,CAAA;AACpB,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,CAAC,IAAa,EAAiB,EAAE;IACtD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAA;IACZ,CAAC;IACD,IAAI,IAAI,YAAY,WAAW,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC1C,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC7B,CAAC;IACD,OAAO,IAAI,CAAA;AACZ,CAAC,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import type { CdpSessionHandle } from '../connection.js';
2
+ import { type DomNodeHandle } from './selector.js';
2
3
  /** Options for filling input/textarea/contenteditable elements. */
3
4
  export type FillElementsOptions = {
4
5
  selector: string;
@@ -12,7 +13,7 @@ export type FillElementsResult = {
12
13
  filledCount: number;
13
14
  };
14
15
  /** Fill pre-resolved node IDs with a value. Skips selector resolution. */
15
- export declare const fillResolvedNodes: (session: CdpSessionHandle, nodeIds: number[], value: string) => Promise<number>;
16
+ export declare const fillResolvedNodes: (session: CdpSessionHandle, handles: DomNodeHandle[], value: string) => Promise<number>;
16
17
  /**
17
18
  * Fill input/textarea/contenteditable element(s) with a value.
18
19
  * Uses the native setter trick to bypass framework property wrappers,
@@ -1 +1 @@
1
- {"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../../../src/cdp/dom/fill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAGxD,mEAAmE;AACnE,MAAM,MAAM,mBAAmB,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED,wCAAwC;AACxC,MAAM,MAAM,kBAAkB,GAAG;IAChC,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;CACnB,CAAA;AA6BD,0EAA0E;AAC1E,eAAO,MAAM,iBAAiB,GAAU,SAAS,gBAAgB,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,MAAM,CAkBnH,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAU,SAAS,gBAAgB,EAAE,SAAS,mBAAmB,KAAG,OAAO,CAAC,kBAAkB,CAQtH,CAAA"}
1
+ {"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../../../src/cdp/dom/fill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAA6D,KAAK,aAAa,EAAE,MAAM,eAAe,CAAA;AAE7G,mEAAmE;AACnE,MAAM,MAAM,mBAAmB,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED,wCAAwC;AACxC,MAAM,MAAM,kBAAkB,GAAG;IAChC,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;CACnB,CAAA;AA6BD,0EAA0E;AAC1E,eAAO,MAAM,iBAAiB,GAAU,SAAS,gBAAgB,EAAE,SAAS,aAAa,EAAE,EAAE,OAAO,MAAM,KAAG,OAAO,CAAC,MAAM,CAkB1H,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAU,SAAS,gBAAgB,EAAE,SAAS,mBAAmB,KAAG,OAAO,CAAC,kBAAkB,CAYtH,CAAA"}
@@ -1,4 +1,4 @@
1
- import { getDomRootId, resolveSelectorMatches } from './selector.js';
1
+ import { getDomRootId, resolveSelectorMatches, toDomNodeDescriptor } from './selector.js';
2
2
  /**
3
3
  * Browser-context function that sets the element value using the native
4
4
  * prototype setter (to bypass React/Vue/Angular property wrappers) and
@@ -26,11 +26,11 @@ const FILL_FUNCTION = `function(value) {
26
26
  el.dispatchEvent(new Event('change', { bubbles: true }));
27
27
  }`;
28
28
  /** Fill pre-resolved node IDs with a value. Skips selector resolution. */
29
- export const fillResolvedNodes = async (session, nodeIds, value) => {
30
- if (nodeIds.length === 0)
29
+ export const fillResolvedNodes = async (session, handles, value) => {
30
+ if (handles.length === 0)
31
31
  return 0;
32
- for (const nodeId of nodeIds) {
33
- const resolved = (await session.sendAndWait('DOM.resolveNode', { nodeId }));
32
+ for (const handle of handles) {
33
+ const resolved = (await session.sendAndWait('DOM.resolveNode', toDomNodeDescriptor(handle)));
34
34
  const objectId = resolved.object?.objectId;
35
35
  if (!objectId)
36
36
  continue;
@@ -42,7 +42,7 @@ export const fillResolvedNodes = async (session, nodeIds, value) => {
42
42
  returnByValue: true,
43
43
  });
44
44
  }
45
- return nodeIds.length;
45
+ return handles.length;
46
46
  };
47
47
  /**
48
48
  * Fill input/textarea/contenteditable element(s) with a value.
@@ -53,7 +53,7 @@ export const fillElements = async (session, options) => {
53
53
  await session.sendAndWait('DOM.enable');
54
54
  const rootId = await getDomRootId(session);
55
55
  const { allNodeIds, nodeIds } = await resolveSelectorMatches(session, rootId, options.selector, options.all ?? false, options.text);
56
- const filledCount = await fillResolvedNodes(session, nodeIds, options.value);
56
+ const filledCount = await fillResolvedNodes(session, nodeIds.map((nodeId) => ({ nodeId })), options.value);
57
57
  return { allNodeIds, filledCount };
58
58
  };
59
59
  //# sourceMappingURL=fill.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fill.js","sourceRoot":"","sources":["../../../src/cdp/dom/fill.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAgBpE;;;;GAIG;AACH,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;EAoBpB,CAAA;AAEF,0EAA0E;AAC1E,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,OAAyB,EAAE,OAAiB,EAAE,KAAa,EAAmB,EAAE;IACvH,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAA;IAElC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAG,CAAC,MAAM,OAAO,CAAC,WAAW,CAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAuC,CAAA;QACjH,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAA;QAC1C,IAAI,CAAC,QAAQ;YAAE,SAAQ;QAEvB,MAAM,OAAO,CAAC,WAAW,CAAC,wBAAwB,EAAE;YACnD,QAAQ;YACR,mBAAmB,EAAE,aAAa;YAClC,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;YACtB,YAAY,EAAE,KAAK;YACnB,aAAa,EAAE,IAAI;SACnB,CAAC,CAAA;IACH,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAA;AACtB,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,OAAyB,EAAE,OAA4B,EAA+B,EAAE;IAC1H,MAAM,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC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,EAAE,CAAC;YACtB,YAAY,EAAE,KAAK;YACnB,aAAa,EAAE,IAAI;SACnB,CAAC,CAAA;IACH,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAA;AACtB,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,OAAyB,EAAE,OAA4B,EAA+B,EAAE;IAC1H,MAAM,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAAA;IAEvC,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,CAAA;IAC1C,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,IAAI,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAEnI,MAAM,WAAW,GAAG,MAAM,iBAAiB,CAC1C,OAAO,EACP,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EACrC,OAAO,CAAC,KAAK,CACb,CAAA;IACD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAA;AACnC,CAAC,CAAA"}
@@ -1,8 +1,10 @@
1
1
  import type { DomInfoResponse } from '@vforsh/argus-core';
2
2
  import type { CdpSessionHandle } from '../connection.js';
3
+ import type { ElementRefRegistry } from '../elementRefs.js';
3
4
  /** Options for fetching DOM element info by selector. */
4
5
  export type FetchDomInfoOptions = {
5
- selector: string;
6
+ selector?: string;
7
+ ref?: string;
6
8
  all?: boolean;
7
9
  outerHtmlMaxChars?: number;
8
10
  text?: string;
@@ -10,5 +12,5 @@ export type FetchDomInfoOptions = {
10
12
  /**
11
13
  * Fetch detailed info for element(s) matching a CSS selector.
12
14
  */
13
- export declare const fetchDomInfoBySelector: (session: CdpSessionHandle, options: FetchDomInfoOptions) => Promise<DomInfoResponse>;
15
+ export declare const fetchDomInfoBySelector: (session: CdpSessionHandle, elementRefs: ElementRefRegistry, options: FetchDomInfoOptions) => Promise<DomInfoResponse>;
14
16
  //# sourceMappingURL=info.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../../src/cdp/dom/info.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAWxD,yDAAyD;AACzD,MAAM,MAAM,mBAAmB,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAU,SAAS,gBAAgB,EAAE,SAAS,mBAAmB,KAAG,OAAO,CAAC,eAAe,CAuD7H,CAAA"}
1
+ {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../../src/cdp/dom/info.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAW3D,yDAAyD;AACzD,MAAM,MAAM,mBAAmB,GAAG;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAClC,SAAS,gBAAgB,EACzB,aAAa,kBAAkB,EAC/B,SAAS,mBAAmB,KAC1B,OAAO,CAAC,eAAe,CA+DzB,CAAA"}
@@ -1,22 +1,30 @@
1
- import { getDomRootId, resolveSelectorMatches, toAttributesRecord, countElementChildren, clamp } from './selector.js';
1
+ import { clamp, countElementChildren, resolveElementTargets, toAttributesRecord, toDomNodeDescriptor } from './selector.js';
2
2
  const DEFAULT_OUTER_HTML_MAX_CHARS = 50_000;
3
3
  const MAX_OUTER_HTML_CHARS = 500_000;
4
4
  /**
5
5
  * Fetch detailed info for element(s) matching a CSS selector.
6
6
  */
7
- export const fetchDomInfoBySelector = async (session, options) => {
7
+ export const fetchDomInfoBySelector = async (session, elementRefs, options) => {
8
8
  const all = options.all ?? false;
9
9
  const maxChars = clamp(options.outerHtmlMaxChars ?? DEFAULT_OUTER_HTML_MAX_CHARS, 0, MAX_OUTER_HTML_CHARS);
10
- await session.sendAndWait('DOM.enable');
11
- const rootId = await getDomRootId(session);
12
- const { allNodeIds, nodeIds } = await resolveSelectorMatches(session, rootId, options.selector, all, options.text);
13
- if (allNodeIds.length === 0) {
10
+ const resolved = await resolveElementTargets(session, elementRefs, {
11
+ selector: options.selector,
12
+ ref: options.ref,
13
+ all,
14
+ text: options.text,
15
+ });
16
+ if (resolved.missingRef && options.ref) {
17
+ throw Object.assign(new Error(`Unknown or stale element ref: ${options.ref}`), { code: 'invalid_ref' });
18
+ }
19
+ const { allHandles, handles } = resolved;
20
+ if (allHandles.length === 0) {
14
21
  return { ok: true, matches: 0, elements: [] };
15
22
  }
16
23
  const elements = [];
17
- for (const nodeId of nodeIds) {
24
+ for (const handle of handles) {
25
+ const descriptor = toDomNodeDescriptor(handle);
18
26
  const describeResult = (await session.sendAndWait('DOM.describeNode', {
19
- nodeId,
27
+ ...descriptor,
20
28
  depth: 1, // Just enough to get child count
21
29
  }));
22
30
  if (!describeResult.node) {
@@ -28,7 +36,7 @@ export const fetchDomInfoBySelector = async (session, options) => {
28
36
  let outerHTML = null;
29
37
  let outerHTMLTruncated = false;
30
38
  try {
31
- const htmlResult = (await session.sendAndWait('DOM.getOuterHTML', { nodeId }));
39
+ const htmlResult = (await session.sendAndWait('DOM.getOuterHTML', descriptor));
32
40
  outerHTML = htmlResult.outerHTML ?? null;
33
41
  if (outerHTML && outerHTML.length > maxChars) {
34
42
  outerHTML = outerHTML.slice(0, maxChars);
@@ -39,7 +47,8 @@ export const fetchDomInfoBySelector = async (session, options) => {
39
47
  // getOuterHTML can fail for certain nodes; leave as null
40
48
  }
41
49
  elements.push({
42
- nodeId,
50
+ ref: node.backendNodeId != null ? elementRefs.getOrCreate(node.backendNodeId) : undefined,
51
+ nodeId: node.nodeId,
43
52
  tag: (node.localName ?? node.nodeName).toLowerCase(),
44
53
  attributes,
45
54
  childElementCount,
@@ -47,6 +56,6 @@ export const fetchDomInfoBySelector = async (session, options) => {
47
56
  outerHTMLTruncated,
48
57
  });
49
58
  }
50
- return { ok: true, matches: allNodeIds.length, elements };
59
+ return { ok: true, matches: allHandles.length, elements };
51
60
  };
52
61
  //# sourceMappingURL=info.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"info.js","sourceRoot":"","sources":["../../../src/cdp/dom/info.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAErH,MAAM,4BAA4B,GAAG,MAAM,CAAA;AAC3C,MAAM,oBAAoB,GAAG,OAAO,CAAA;AAcpC;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,OAAyB,EAAE,OAA4B,EAA4B,EAAE;IACjI,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,KAAK,CAAA;IAChC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,iBAAiB,IAAI,4BAA4B,EAAE,CAAC,EAAE,oBAAoB,CAAC,CAAA;IAE1G,MAAM,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAAA;IAEvC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AAC,SAAS,IAAI,IAAI,CAAA;YAExC,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,QAAQ,EAAE,CAAC;gBAC9C,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;gBACxC,kBAAkB,GAAG,IAAI,CAAA;YAC1B,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,yDAAyD;QAC1D,CAAC;QAED,QAAQ,CAAC,IAAI,CAAC;YACb,GAAG,EAAE,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS;YACzF,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE;YACpD,UAAU;YACV,iBAAiB;YACjB,SAAS;YACT,kBAAkB;SAClB,CAAC,CAAA;IACH,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAA;AAC1D,CAAC,CAAA"}
@@ -1,5 +1,6 @@
1
1
  import type { CdpNode } from './types.js';
2
2
  import type { CdpSessionHandle } from '../connection.js';
3
+ import type { ElementRefRegistry } from '../elementRefs.js';
3
4
  export type SelectorMatchResult = {
4
5
  /** All matched node IDs. */
5
6
  allNodeIds: number[];
@@ -12,6 +13,29 @@ export type ResolveSelectorTargetOptions = {
12
13
  text?: string;
13
14
  waitMs?: number;
14
15
  };
16
+ export type ResolveElementTargetOptions = {
17
+ selector?: string;
18
+ ref?: string;
19
+ all: boolean;
20
+ text?: string;
21
+ waitMs?: number;
22
+ };
23
+ export type DomNodeHandle = {
24
+ nodeId?: number;
25
+ backendNodeId?: number;
26
+ };
27
+ export type ResolvedElementTarget = SelectorMatchResult & {
28
+ allHandles: DomNodeHandle[];
29
+ handles: DomNodeHandle[];
30
+ target: {
31
+ kind: 'selector';
32
+ value: string;
33
+ } | {
34
+ kind: 'ref';
35
+ value: string;
36
+ };
37
+ missingRef?: boolean;
38
+ };
15
39
  export declare const getDomRootId: (session: CdpSessionHandle) => Promise<number>;
16
40
  export declare const resolveSelectorMatches: (session: CdpSessionHandle, rootId: number, selector: string, all: boolean, text?: string) => Promise<SelectorMatchResult>;
17
41
  /**
@@ -23,6 +47,17 @@ export declare const waitForSelectorMatches: (session: CdpSessionHandle, selecto
23
47
  * Enable the DOM domain, then resolve selector matches immediately or by polling for a bounded wait.
24
48
  */
25
49
  export declare const resolveSelectorTargets: (session: CdpSessionHandle, options: ResolveSelectorTargetOptions) => Promise<SelectorMatchResult>;
50
+ export declare const resolveElementTargets: (session: CdpSessionHandle, elementRefs: ElementRefRegistry, options: ResolveElementTargetOptions) => Promise<ResolvedElementTarget>;
51
+ /** Resolve the first node id matching a selector, or null when no match exists. */
52
+ export declare const resolveFirstSelectorNodeId: (session: CdpSessionHandle, selector: string, text?: string) => Promise<number | null>;
53
+ export declare const describeNodeByBackendId: (session: CdpSessionHandle, backendNodeId: number) => Promise<CdpNode | null>;
54
+ export declare const resolveNodeIdByBackendId: (session: CdpSessionHandle, backendNodeId: number) => Promise<number | null>;
55
+ export declare const resolveNodeIdForRef: (session: CdpSessionHandle, elementRefs: ElementRefRegistry, ref: string) => Promise<number | null>;
56
+ export declare const toDomNodeDescriptor: (handle: DomNodeHandle) => {
57
+ nodeId: number;
58
+ } | {
59
+ backendNodeId: number;
60
+ };
26
61
  export declare const toAttributesRecord: (attributes?: string[]) => Record<string, string>;
27
62
  export declare const countElementChildren: (children?: CdpNode[]) => number;
28
63
  export declare const clamp: (value: number, min: number, max: number) => number;
@@ -1 +1 @@
1
- {"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../../src/cdp/dom/selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YA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EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,aAAa,EAAE,MAAM,CAAA;CAQvG,CAAA;AAiDD,eAAO,MAAM,kBAAkB,GAAI,aAAa,MAAM,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAc/E,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,WAAW,OAAO,EAAE,KAAG,MAK3D,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,MAE/D,CAAA"}
@@ -2,32 +2,9 @@ import { filterNodesByText } from '../text-filter.js';
2
2
  export const getDomRootId = async (session) => {
3
3
  const targetContext = session.getTargetContext?.();
4
4
  if (targetContext?.kind === 'frame') {
5
- // Extension mode keeps one tab-level debugger session and switches the active frame via
6
- // executionContextId. Resolving `document` in that context gives us the right DOM root.
7
- if (targetContext.executionContextId == null) {
8
- throw new Error(`Selected frame is not ready yet: ${targetContext.frameId}`);
9
- }
10
- const evaluated = (await session.sendAndWait('Runtime.evaluate', {
11
- expression: 'document',
12
- contextId: targetContext.executionContextId,
13
- returnByValue: false,
14
- }));
15
- const objectId = evaluated.result?.objectId;
16
- if (!objectId) {
17
- throw new Error(`Unable to resolve document root for frame: ${targetContext.frameId}`);
18
- }
19
- const requested = (await session.sendAndWait('DOM.requestNode', { objectId }));
20
- if (!requested.nodeId) {
21
- throw new Error(`Unable to resolve DOM root for frame: ${targetContext.frameId}`);
22
- }
23
- return requested.nodeId;
24
- }
25
- const result = (await session.sendAndWait('DOM.getDocument', { depth: 1 }));
26
- const rootId = result.root?.nodeId;
27
- if (!rootId) {
28
- throw new Error('Unable to resolve DOM root');
5
+ return getFrameDomRootId(session, targetContext);
29
6
  }
30
- return rootId;
7
+ return getDocumentRootId(session);
31
8
  };
32
9
  export const resolveSelectorMatches = async (session, rootId, selector, all, text) => {
33
10
  // Always use querySelectorAll to get the true match count
@@ -69,6 +46,122 @@ export const resolveSelectorTargets = async (session, options) => {
69
46
  const rootId = await getDomRootId(session);
70
47
  return resolveSelectorMatches(session, rootId, options.selector, options.all, options.text);
71
48
  };
49
+ export const resolveElementTargets = async (session, elementRefs, options) => {
50
+ await session.sendAndWait('DOM.enable');
51
+ if (options.ref) {
52
+ const backendNodeId = elementRefs.resolve(options.ref);
53
+ if (backendNodeId == null) {
54
+ return {
55
+ target: { kind: 'ref', value: options.ref },
56
+ allNodeIds: [],
57
+ nodeIds: [],
58
+ allHandles: [],
59
+ handles: [],
60
+ missingRef: true,
61
+ };
62
+ }
63
+ return {
64
+ target: { kind: 'ref', value: options.ref },
65
+ allNodeIds: [],
66
+ nodeIds: [],
67
+ allHandles: [{ backendNodeId }],
68
+ handles: [{ backendNodeId }],
69
+ };
70
+ }
71
+ if (!options.selector) {
72
+ throw new Error('selector or ref is required');
73
+ }
74
+ const result = (options.waitMs ?? 0) > 0
75
+ ? await waitForSelectorMatches(session, options.selector, options.all, options.text, options.waitMs ?? 0)
76
+ : await resolveSelectorMatches(session, await getDomRootId(session), options.selector, options.all, options.text);
77
+ return {
78
+ target: { kind: 'selector', value: options.selector },
79
+ allHandles: result.allNodeIds.map((nodeId) => ({ nodeId })),
80
+ handles: result.nodeIds.map((nodeId) => ({ nodeId })),
81
+ ...result,
82
+ };
83
+ };
84
+ /** Resolve the first node id matching a selector, or null when no match exists. */
85
+ export const resolveFirstSelectorNodeId = async (session, selector, text) => {
86
+ const { nodeIds } = await resolveSelectorTargets(session, {
87
+ selector,
88
+ all: false,
89
+ text,
90
+ });
91
+ return nodeIds[0] ?? null;
92
+ };
93
+ export const describeNodeByBackendId = async (session, backendNodeId) => {
94
+ const described = (await session.sendAndWait('DOM.describeNode', {
95
+ backendNodeId,
96
+ depth: 0,
97
+ }));
98
+ return described.node ?? null;
99
+ };
100
+ export const resolveNodeIdByBackendId = async (session, backendNodeId) => {
101
+ const describedNode = await describeNodeByBackendId(session, backendNodeId);
102
+ if (describedNode?.nodeId) {
103
+ return describedNode.nodeId;
104
+ }
105
+ // Prime the document tree first so CDP can map backend ids back into frontend node ids.
106
+ await getDomRootId(session);
107
+ const pushed = (await session.sendAndWait('DOM.pushNodesByBackendIdsToFrontend', {
108
+ backendNodeIds: [backendNodeId],
109
+ }));
110
+ const nodeId = pushed.nodeIds?.[0];
111
+ return typeof nodeId === 'number' && nodeId > 0 ? nodeId : null;
112
+ };
113
+ export const resolveNodeIdForRef = async (session, elementRefs, ref) => {
114
+ const backendNodeId = elementRefs.resolve(ref);
115
+ if (backendNodeId == null) {
116
+ return null;
117
+ }
118
+ return resolveNodeIdByBackendId(session, backendNodeId);
119
+ };
120
+ export const toDomNodeDescriptor = (handle) => {
121
+ if (handle.nodeId != null) {
122
+ return { nodeId: handle.nodeId };
123
+ }
124
+ if (handle.backendNodeId != null) {
125
+ return { backendNodeId: handle.backendNodeId };
126
+ }
127
+ throw new Error('DOM node handle is missing both nodeId and backendNodeId');
128
+ };
129
+ /**
130
+ * Frame-scoped DOM commands are most reliable when they stay inside the frame's child CDP session.
131
+ * Extension mode already tracks that session id on the active target context, so prefer the normal
132
+ * DOM root lookup in that routed session and only fall back to the older Runtime/DOM bridge when a
133
+ * child session is not available.
134
+ */
135
+ const getFrameDomRootId = async (session, targetContext) => {
136
+ if (targetContext.sessionId) {
137
+ return getDocumentRootId(session);
138
+ }
139
+ if (targetContext.executionContextId == null) {
140
+ throw new Error(`Selected frame is not ready yet: ${targetContext.frameId}`);
141
+ }
142
+ const evaluated = (await session.sendAndWait('Runtime.evaluate', {
143
+ expression: 'document',
144
+ contextId: targetContext.executionContextId,
145
+ returnByValue: false,
146
+ }));
147
+ const objectId = evaluated.result?.objectId;
148
+ if (!objectId) {
149
+ throw new Error(`Unable to resolve DOM root for frame: ${targetContext.frameId}`);
150
+ }
151
+ const requested = (await session.sendAndWait('DOM.requestNode', { objectId }));
152
+ if (!requested.nodeId) {
153
+ throw new Error(`Unable to resolve DOM root for frame: ${targetContext.frameId}`);
154
+ }
155
+ return requested.nodeId;
156
+ };
157
+ const getDocumentRootId = async (session) => {
158
+ const result = (await session.sendAndWait('DOM.getDocument', { depth: 1 }));
159
+ const rootId = result.root?.nodeId;
160
+ if (!rootId) {
161
+ throw new Error('Unable to resolve DOM root');
162
+ }
163
+ return rootId;
164
+ };
72
165
  // ─────────────────────────────────────────────────────────────────────────────
73
166
  // Shared helpers
74
167
  // ─────────────────────────────────────────────────────────────────────────────