@vforsh/argus-watcher 0.1.1 → 0.1.3
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.
- package/README.md +66 -14
- package/dist/.tsbuildinfo +1 -1
- package/dist/artifacts.d.ts +13 -0
- package/dist/artifacts.d.ts.map +1 -0
- package/dist/artifacts.js +27 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/buffer/LogBuffer.d.ts +8 -3
- package/dist/buffer/LogBuffer.d.ts.map +1 -1
- package/dist/buffer/LogBuffer.js +9 -1
- package/dist/buffer/LogBuffer.js.map +1 -1
- package/dist/buffer/NetBuffer.d.ts +29 -0
- package/dist/buffer/NetBuffer.d.ts.map +1 -0
- package/dist/buffer/NetBuffer.js +85 -0
- package/dist/buffer/NetBuffer.js.map +1 -0
- package/dist/cdp/accessibility.d.ts +18 -0
- package/dist/cdp/accessibility.d.ts.map +1 -0
- package/dist/cdp/accessibility.js +300 -0
- package/dist/cdp/accessibility.js.map +1 -0
- package/dist/cdp/connection.d.ts +24 -0
- package/dist/cdp/connection.d.ts.map +1 -0
- package/dist/cdp/connection.js +131 -0
- package/dist/cdp/connection.js.map +1 -0
- package/dist/cdp/dom/fill.d.ts +22 -0
- package/dist/cdp/dom/fill.d.ts.map +1 -0
- package/dist/cdp/dom/fill.js +59 -0
- package/dist/cdp/dom/fill.js.map +1 -0
- package/dist/cdp/dom/info.d.ts +14 -0
- package/dist/cdp/dom/info.d.ts.map +1 -0
- package/dist/cdp/dom/info.js +52 -0
- package/dist/cdp/dom/info.js.map +1 -0
- package/dist/cdp/dom/insert.d.ts +19 -0
- package/dist/cdp/dom/insert.d.ts.map +1 -0
- package/dist/cdp/dom/insert.js +30 -0
- package/dist/cdp/dom/insert.js.map +1 -0
- package/dist/cdp/dom/modify.d.ts +50 -0
- package/dist/cdp/dom/modify.d.ts.map +1 -0
- package/dist/cdp/dom/modify.js +100 -0
- package/dist/cdp/dom/modify.js.map +1 -0
- package/dist/cdp/dom/remove.d.ts +17 -0
- package/dist/cdp/dom/remove.d.ts.map +1 -0
- package/dist/cdp/dom/remove.js +27 -0
- package/dist/cdp/dom/remove.js.map +1 -0
- package/dist/cdp/dom/selector.d.ts +19 -0
- package/dist/cdp/dom/selector.d.ts.map +1 -0
- package/dist/cdp/dom/selector.js +64 -0
- package/dist/cdp/dom/selector.js.map +1 -0
- package/dist/cdp/dom/setFile.d.ts +21 -0
- package/dist/cdp/dom/setFile.d.ts.map +1 -0
- package/dist/cdp/dom/setFile.js +82 -0
- package/dist/cdp/dom/setFile.js.map +1 -0
- package/dist/cdp/dom/submit.d.ts +15 -0
- package/dist/cdp/dom/submit.d.ts.map +1 -0
- package/dist/cdp/dom/submit.js +130 -0
- package/dist/cdp/dom/submit.js.map +1 -0
- package/dist/cdp/dom/tree.d.ts +16 -0
- package/dist/cdp/dom/tree.d.ts.map +1 -0
- package/dist/cdp/dom/tree.js +100 -0
- package/dist/cdp/dom/tree.js.map +1 -0
- package/dist/cdp/dom/types.d.ts +16 -0
- package/dist/cdp/dom/types.d.ts.map +1 -0
- package/dist/cdp/dom/types.js +2 -0
- package/dist/cdp/dom/types.js.map +1 -0
- package/dist/cdp/dom.d.ts +17 -0
- package/dist/cdp/dom.d.ts.map +1 -0
- package/dist/cdp/dom.js +10 -0
- package/dist/cdp/dom.js.map +1 -0
- package/dist/cdp/emulation.d.ts +16 -0
- package/dist/cdp/emulation.d.ts.map +1 -0
- package/dist/cdp/emulation.js +40 -0
- package/dist/cdp/emulation.js.map +1 -0
- package/dist/cdp/eval.d.ts +10 -0
- package/dist/cdp/eval.d.ts.map +1 -0
- package/dist/cdp/eval.js +34 -0
- package/dist/cdp/eval.js.map +1 -0
- package/dist/cdp/keyboard.d.ts +38 -0
- package/dist/cdp/keyboard.d.ts.map +1 -0
- package/dist/cdp/keyboard.js +148 -0
- package/dist/cdp/keyboard.js.map +1 -0
- package/dist/cdp/mouse.d.ts +49 -0
- package/dist/cdp/mouse.d.ts.map +1 -0
- package/dist/cdp/mouse.js +199 -0
- package/dist/cdp/mouse.js.map +1 -0
- package/dist/cdp/networkCapture.d.ts +11 -0
- package/dist/cdp/networkCapture.d.ts.map +1 -0
- package/dist/cdp/networkCapture.js +99 -0
- package/dist/cdp/networkCapture.js.map +1 -0
- package/dist/cdp/pageIndicator.d.ts +41 -0
- package/dist/cdp/pageIndicator.d.ts.map +1 -0
- package/dist/cdp/pageIndicator.js +395 -0
- package/dist/cdp/pageIndicator.js.map +1 -0
- package/dist/cdp/redaction.d.ts +3 -0
- package/dist/cdp/redaction.d.ts.map +1 -0
- package/dist/cdp/redaction.js +35 -0
- package/dist/cdp/redaction.js.map +1 -0
- package/dist/cdp/remoteObject.d.ts +6 -0
- package/dist/cdp/remoteObject.d.ts.map +1 -0
- package/dist/cdp/remoteObject.js +94 -0
- package/dist/cdp/remoteObject.js.map +1 -0
- package/dist/cdp/screenshot.d.ts +10 -0
- package/dist/cdp/screenshot.d.ts.map +1 -0
- package/dist/cdp/screenshot.js +87 -0
- package/dist/cdp/screenshot.js.map +1 -0
- package/dist/cdp/storageLocal.d.ts +8 -0
- package/dist/cdp/storageLocal.d.ts.map +1 -0
- package/dist/cdp/storageLocal.js +70 -0
- package/dist/cdp/storageLocal.js.map +1 -0
- package/dist/cdp/text-filter.d.ts +19 -0
- package/dist/cdp/text-filter.d.ts.map +1 -0
- package/dist/cdp/text-filter.js +54 -0
- package/dist/cdp/text-filter.js.map +1 -0
- package/dist/cdp/throttle.d.ts +6 -0
- package/dist/cdp/throttle.d.ts.map +1 -0
- package/dist/cdp/throttle.js +9 -0
- package/dist/cdp/throttle.js.map +1 -0
- package/dist/cdp/tracing.d.ts +14 -0
- package/dist/cdp/tracing.d.ts.map +1 -0
- package/dist/cdp/tracing.js +115 -0
- package/dist/cdp/tracing.js.map +1 -0
- package/dist/cdp/watcher.d.ts +17 -2
- package/dist/cdp/watcher.d.ts.map +1 -1
- package/dist/cdp/watcher.js +125 -99
- package/dist/cdp/watcher.js.map +1 -1
- package/dist/emulation/EmulationController.d.ts +12 -0
- package/dist/emulation/EmulationController.d.ts.map +1 -0
- package/dist/emulation/EmulationController.js +83 -0
- package/dist/emulation/EmulationController.js.map +1 -0
- package/dist/events.d.ts +86 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +2 -0
- package/dist/events.js.map +1 -0
- package/dist/fileLogs/WatcherFileLogger.d.ts +5 -2
- package/dist/fileLogs/WatcherFileLogger.d.ts.map +1 -1
- package/dist/fileLogs/WatcherFileLogger.js +30 -12
- package/dist/fileLogs/WatcherFileLogger.js.map +1 -1
- package/dist/http/httpUtils.d.ts +25 -0
- package/dist/http/httpUtils.d.ts.map +1 -0
- package/dist/http/httpUtils.js +170 -0
- package/dist/http/httpUtils.js.map +1 -0
- package/dist/http/router.d.ts +5 -0
- package/dist/http/router.d.ts.map +1 -0
- package/dist/http/router.js +81 -0
- package/dist/http/router.js.map +1 -0
- package/dist/http/routes/getEmulation.d.ts +3 -0
- package/dist/http/routes/getEmulation.d.ts.map +1 -0
- package/dist/http/routes/getEmulation.js +8 -0
- package/dist/http/routes/getEmulation.js.map +1 -0
- package/dist/http/routes/getLogs.d.ts +3 -0
- package/dist/http/routes/getLogs.d.ts.map +1 -0
- package/dist/http/routes/getLogs.js +28 -0
- package/dist/http/routes/getLogs.js.map +1 -0
- package/dist/http/routes/getNet.d.ts +3 -0
- package/dist/http/routes/getNet.d.ts.map +1 -0
- package/dist/http/routes/getNet.js +17 -0
- package/dist/http/routes/getNet.js.map +1 -0
- package/dist/http/routes/getNetTail.d.ts +3 -0
- package/dist/http/routes/getNetTail.d.ts.map +1 -0
- package/dist/http/routes/getNetTail.js +18 -0
- package/dist/http/routes/getNetTail.js.map +1 -0
- package/dist/http/routes/getStatus.d.ts +3 -0
- package/dist/http/routes/getStatus.d.ts.map +1 -0
- package/dist/http/routes/getStatus.js +21 -0
- package/dist/http/routes/getStatus.js.map +1 -0
- package/dist/http/routes/getTail.d.ts +3 -0
- package/dist/http/routes/getTail.d.ts.map +1 -0
- package/dist/http/routes/getTail.js +28 -0
- package/dist/http/routes/getTail.js.map +1 -0
- package/dist/http/routes/getTargets.d.ts +3 -0
- package/dist/http/routes/getTargets.d.ts.map +1 -0
- package/dist/http/routes/getTargets.js +16 -0
- package/dist/http/routes/getTargets.js.map +1 -0
- package/dist/http/routes/getThrottle.d.ts +3 -0
- package/dist/http/routes/getThrottle.d.ts.map +1 -0
- package/dist/http/routes/getThrottle.js +8 -0
- package/dist/http/routes/getThrottle.js.map +1 -0
- package/dist/http/routes/postAttach.d.ts +3 -0
- package/dist/http/routes/postAttach.d.ts.map +1 -0
- package/dist/http/routes/postAttach.js +23 -0
- package/dist/http/routes/postAttach.js.map +1 -0
- package/dist/http/routes/postDetach.d.ts +3 -0
- package/dist/http/routes/postDetach.d.ts.map +1 -0
- package/dist/http/routes/postDetach.js +23 -0
- package/dist/http/routes/postDetach.js.map +1 -0
- package/dist/http/routes/postDomAdd.d.ts +7 -0
- package/dist/http/routes/postDomAdd.d.ts.map +1 -0
- package/dist/http/routes/postDomAdd.js +97 -0
- package/dist/http/routes/postDomAdd.js.map +1 -0
- package/dist/http/routes/postDomClick.d.ts +3 -0
- package/dist/http/routes/postDomClick.d.ts.map +1 -0
- package/dist/http/routes/postDomClick.js +85 -0
- package/dist/http/routes/postDomClick.js.map +1 -0
- package/dist/http/routes/postDomFill.d.ts +3 -0
- package/dist/http/routes/postDomFill.d.ts.map +1 -0
- package/dist/http/routes/postDomFill.js +58 -0
- package/dist/http/routes/postDomFill.js.map +1 -0
- package/dist/http/routes/postDomFocus.d.ts +3 -0
- package/dist/http/routes/postDomFocus.d.ts.map +1 -0
- package/dist/http/routes/postDomFocus.js +40 -0
- package/dist/http/routes/postDomFocus.js.map +1 -0
- package/dist/http/routes/postDomHover.d.ts +3 -0
- package/dist/http/routes/postDomHover.d.ts.map +1 -0
- package/dist/http/routes/postDomHover.js +40 -0
- package/dist/http/routes/postDomHover.js.map +1 -0
- package/dist/http/routes/postDomInfo.d.ts +3 -0
- package/dist/http/routes/postDomInfo.d.ts.map +1 -0
- package/dist/http/routes/postDomInfo.js +40 -0
- package/dist/http/routes/postDomInfo.js.map +1 -0
- package/dist/http/routes/postDomKeydown.d.ts +3 -0
- package/dist/http/routes/postDomKeydown.d.ts.map +1 -0
- package/dist/http/routes/postDomKeydown.js +36 -0
- package/dist/http/routes/postDomKeydown.js.map +1 -0
- package/dist/http/routes/postDomModify.d.ts +3 -0
- package/dist/http/routes/postDomModify.d.ts.map +1 -0
- package/dist/http/routes/postDomModify.js +45 -0
- package/dist/http/routes/postDomModify.js.map +1 -0
- package/dist/http/routes/postDomRemove.d.ts +3 -0
- package/dist/http/routes/postDomRemove.d.ts.map +1 -0
- package/dist/http/routes/postDomRemove.js +39 -0
- package/dist/http/routes/postDomRemove.js.map +1 -0
- package/dist/http/routes/postDomScroll.d.ts +3 -0
- package/dist/http/routes/postDomScroll.d.ts.map +1 -0
- package/dist/http/routes/postDomScroll.js +75 -0
- package/dist/http/routes/postDomScroll.js.map +1 -0
- package/dist/http/routes/postDomScrollTo.d.ts +3 -0
- package/dist/http/routes/postDomScrollTo.d.ts.map +1 -0
- package/dist/http/routes/postDomScrollTo.js +69 -0
- package/dist/http/routes/postDomScrollTo.js.map +1 -0
- package/dist/http/routes/postDomSetFile.d.ts +3 -0
- package/dist/http/routes/postDomSetFile.d.ts.map +1 -0
- package/dist/http/routes/postDomSetFile.js +67 -0
- package/dist/http/routes/postDomSetFile.js.map +1 -0
- package/dist/http/routes/postDomSubmit.d.ts +3 -0
- package/dist/http/routes/postDomSubmit.d.ts.map +1 -0
- package/dist/http/routes/postDomSubmit.js +49 -0
- package/dist/http/routes/postDomSubmit.js.map +1 -0
- package/dist/http/routes/postDomTree.d.ts +3 -0
- package/dist/http/routes/postDomTree.d.ts.map +1 -0
- package/dist/http/routes/postDomTree.js +41 -0
- package/dist/http/routes/postDomTree.js.map +1 -0
- package/dist/http/routes/postEmulation.d.ts +3 -0
- package/dist/http/routes/postEmulation.d.ts.map +1 -0
- package/dist/http/routes/postEmulation.js +70 -0
- package/dist/http/routes/postEmulation.js.map +1 -0
- package/dist/http/routes/postEval.d.ts +3 -0
- package/dist/http/routes/postEval.d.ts.map +1 -0
- package/dist/http/routes/postEval.js +26 -0
- package/dist/http/routes/postEval.js.map +1 -0
- package/dist/http/routes/postReload.d.ts +3 -0
- package/dist/http/routes/postReload.d.ts.map +1 -0
- package/dist/http/routes/postReload.js +20 -0
- package/dist/http/routes/postReload.js.map +1 -0
- package/dist/http/routes/postScreenshot.d.ts +3 -0
- package/dist/http/routes/postScreenshot.d.ts.map +1 -0
- package/dist/http/routes/postScreenshot.js +17 -0
- package/dist/http/routes/postScreenshot.js.map +1 -0
- package/dist/http/routes/postShutdown.d.ts +3 -0
- package/dist/http/routes/postShutdown.d.ts.map +1 -0
- package/dist/http/routes/postShutdown.js +13 -0
- package/dist/http/routes/postShutdown.js.map +1 -0
- package/dist/http/routes/postSnapshot.d.ts +3 -0
- package/dist/http/routes/postSnapshot.d.ts.map +1 -0
- package/dist/http/routes/postSnapshot.js +28 -0
- package/dist/http/routes/postSnapshot.js.map +1 -0
- package/dist/http/routes/postStorageLocal.d.ts +3 -0
- package/dist/http/routes/postStorageLocal.d.ts.map +1 -0
- package/dist/http/routes/postStorageLocal.js +31 -0
- package/dist/http/routes/postStorageLocal.js.map +1 -0
- package/dist/http/routes/postThrottle.d.ts +3 -0
- package/dist/http/routes/postThrottle.d.ts.map +1 -0
- package/dist/http/routes/postThrottle.js +38 -0
- package/dist/http/routes/postThrottle.js.map +1 -0
- package/dist/http/routes/postTraceStart.d.ts +3 -0
- package/dist/http/routes/postTraceStart.d.ts.map +1 -0
- package/dist/http/routes/postTraceStart.js +17 -0
- package/dist/http/routes/postTraceStart.js.map +1 -0
- package/dist/http/routes/postTraceStop.d.ts +3 -0
- package/dist/http/routes/postTraceStop.d.ts.map +1 -0
- package/dist/http/routes/postTraceStop.js +17 -0
- package/dist/http/routes/postTraceStop.js.map +1 -0
- package/dist/http/routes/types.d.ts +9 -0
- package/dist/http/routes/types.d.ts.map +1 -0
- package/dist/http/routes/types.js +10 -0
- package/dist/http/routes/types.js.map +1 -0
- package/dist/http/server.d.ts +40 -1
- package/dist/http/server.d.ts.map +1 -1
- package/dist/http/server.js +3 -82
- package/dist/http/server.js.map +1 -1
- package/dist/index.d.ts +117 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +331 -44
- package/dist/index.js.map +1 -1
- package/dist/native-messaging/messaging.d.ts +18 -0
- package/dist/native-messaging/messaging.d.ts.map +1 -0
- package/dist/native-messaging/messaging.js +94 -0
- package/dist/native-messaging/messaging.js.map +1 -0
- package/dist/native-messaging/session-manager.d.ts +105 -0
- package/dist/native-messaging/session-manager.d.ts.map +1 -0
- package/dist/native-messaging/session-manager.js +259 -0
- package/dist/native-messaging/session-manager.js.map +1 -0
- package/dist/native-messaging/types.d.ts +79 -0
- package/dist/native-messaging/types.d.ts.map +1 -0
- package/dist/native-messaging/types.js +6 -0
- package/dist/native-messaging/types.js.map +1 -0
- package/dist/registry/registry.d.ts +9 -2
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +53 -9
- package/dist/registry/registry.js.map +1 -1
- package/dist/scripts/install-host.d.ts +10 -0
- package/dist/scripts/install-host.d.ts.map +1 -0
- package/dist/scripts/install-host.js +189 -0
- package/dist/scripts/install-host.js.map +1 -0
- package/dist/sources/cdp-source.d.ts +24 -0
- package/dist/sources/cdp-source.d.ts.map +1 -0
- package/dist/sources/cdp-source.js +48 -0
- package/dist/sources/cdp-source.js.map +1 -0
- package/dist/sources/extension-source.d.ts +15 -0
- package/dist/sources/extension-source.d.ts.map +1 -0
- package/dist/sources/extension-source.js +256 -0
- package/dist/sources/extension-source.js.map +1 -0
- package/dist/sources/types.d.ts +92 -0
- package/dist/sources/types.d.ts.map +1 -0
- package/dist/sources/types.js +7 -0
- package/dist/sources/types.js.map +1 -0
- package/dist/throttle/ThrottleController.d.ts +12 -0
- package/dist/throttle/ThrottleController.d.ts.map +1 -0
- package/dist/throttle/ThrottleController.js +67 -0
- package/dist/throttle/ThrottleController.js.map +1 -0
- package/package.json +8 -2
package/dist/http/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/http/server.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/http/server.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAU5B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAiFtC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,OAA0B,EAA6B,EAAE;IAC9F,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC7C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,EAAE,UAAU,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;QACjF,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;IAEF,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAC5B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAA;IAC3D,CAAC,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAA;IAChC,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAA;IAEjF,OAAO;QACN,IAAI;QACJ,KAAK,EAAE,GAAG,EAAE,CACX,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC/B,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACtB,IAAI,KAAK,EAAE,CAAC;oBACX,MAAM,CAAC,KAAK,CAAC,CAAA;oBACb,OAAM;gBACP,CAAC;gBACD,OAAO,EAAE,CAAA;YACV,CAAC,CAAC,CAAA;QACH,CAAC,CAAC;KACH,CAAA;AACF,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,84 @@
|
|
|
1
1
|
import type { WatcherMatch, WatcherChrome, WatcherRecord, LogEvent } from '@vforsh/argus-core';
|
|
2
|
+
import Emittery from 'emittery';
|
|
3
|
+
import { type PageIndicatorOptions } from './cdp/pageIndicator.js';
|
|
4
|
+
import type { ArgusWatcherEventMap } from './events.js';
|
|
5
|
+
/** Context for the optional log filename builder callback. */
|
|
6
|
+
export type BuildFilenameContext = {
|
|
7
|
+
/** Unique watcher identifier. */
|
|
8
|
+
watcherId: string;
|
|
9
|
+
/** Watcher start time as milliseconds since Unix epoch. */
|
|
10
|
+
startedAt: number;
|
|
11
|
+
/** Watcher start time formatted for use in a filename (ISO but with ":" replaced by "-"). */
|
|
12
|
+
startedAtSafe: string;
|
|
13
|
+
/** Sequence number of the log file within the current watcher session (starts at 1). */
|
|
14
|
+
fileIndex: number;
|
|
15
|
+
};
|
|
16
|
+
/** Configuration for artifacts storage (logs, traces, screenshots). */
|
|
17
|
+
export type ArtifactsOptions = {
|
|
18
|
+
/**
|
|
19
|
+
* Base directory for all artifacts.
|
|
20
|
+
* Defaults to `$TMPDIR/argus/<watcherId>`.
|
|
21
|
+
*/
|
|
22
|
+
base?: string;
|
|
23
|
+
/** Optional file log persistence settings. Disabled by default. */
|
|
24
|
+
logs?: {
|
|
25
|
+
/** Enable file logging. Defaults to `false`. */
|
|
26
|
+
enabled?: boolean;
|
|
27
|
+
/** Whether to include ISO timestamps in log records. Defaults to `false`. */
|
|
28
|
+
includeTimestamps?: boolean;
|
|
29
|
+
/** Max number of log files to keep for this watcher. Defaults to `5`. */
|
|
30
|
+
maxFiles?: number;
|
|
31
|
+
/** Optional callback to customize the log filename. Return null/undefined to use default. */
|
|
32
|
+
buildFilename?: (context: BuildFilenameContext) => string | undefined | null;
|
|
33
|
+
};
|
|
34
|
+
/** Trace recording settings. Enabled by default. */
|
|
35
|
+
traces?: {
|
|
36
|
+
/** Enable trace recording. Defaults to `true`. */
|
|
37
|
+
enabled?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/** Screenshot capture settings. Enabled by default. */
|
|
40
|
+
screenshots?: {
|
|
41
|
+
/** Enable screenshot capture. Defaults to `true`. */
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/** Configuration for network request capture. */
|
|
46
|
+
export type NetOptions = {
|
|
47
|
+
/** Enable network request capture. Defaults to `false`. */
|
|
48
|
+
enabled?: boolean;
|
|
49
|
+
};
|
|
50
|
+
/** Page console logging level for watcher lifecycle and request logs. */
|
|
51
|
+
export type PageConsoleLogging = 'none' | 'minimal' | 'full';
|
|
52
|
+
/** Source mode for CDP connection. */
|
|
53
|
+
export type WatcherSourceMode = 'cdp' | 'extension';
|
|
2
54
|
/** Options to start a watcher server. */
|
|
3
55
|
export type StartWatcherOptions = {
|
|
4
56
|
/** Unique watcher identifier (used for registry presence and removal on shutdown). */
|
|
5
57
|
id: string;
|
|
58
|
+
/**
|
|
59
|
+
* Source mode for CDP connection.
|
|
60
|
+
* - `cdp` (default): Connect directly to Chrome via WebSocket.
|
|
61
|
+
* - `extension`: Connect via Chrome extension Native Messaging.
|
|
62
|
+
*/
|
|
63
|
+
source?: WatcherSourceMode;
|
|
6
64
|
/** Host/interface to bind the watcher HTTP server to. Defaults to `127.0.0.1`. */
|
|
7
65
|
host?: string;
|
|
8
66
|
/** Port to bind the watcher HTTP server to. Defaults to `0` (ephemeral). */
|
|
9
67
|
port?: number;
|
|
10
|
-
/** Criteria for which Chrome target(s) to attach to. */
|
|
68
|
+
/** Criteria for which Chrome target(s) to attach to. Only used in CDP mode. */
|
|
11
69
|
match?: WatcherMatch;
|
|
12
|
-
/** Chrome DevTools Protocol (CDP) connection settings. Defaults to `127.0.0.1:9222`. */
|
|
70
|
+
/** Chrome DevTools Protocol (CDP) connection settings. Defaults to `127.0.0.1:9222`. Only used in CDP mode. */
|
|
13
71
|
chrome?: WatcherChrome;
|
|
14
72
|
/** Max buffered log events before older entries are dropped. Defaults to `50_000`. */
|
|
15
73
|
bufferSize?: number;
|
|
16
74
|
/** How often (in ms) to refresh the watcher record in the registry. Defaults to `15_000`. */
|
|
17
75
|
heartbeatMs?: number;
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
76
|
+
/**
|
|
77
|
+
* Artifacts storage configuration for logs, traces, and screenshots.
|
|
78
|
+
* All artifacts are stored under `artifacts.base` (default: `$TMPDIR/argus`).
|
|
79
|
+
* Subdirectories: `logs/`, `traces/`, `screenshots/`.
|
|
80
|
+
*/
|
|
81
|
+
artifacts?: ArtifactsOptions;
|
|
25
82
|
/** Optional ignore list filtering when selecting log/exception locations. */
|
|
26
83
|
ignoreList?: {
|
|
27
84
|
/** Enable ignore list filtering for log/exception locations. */
|
|
@@ -29,8 +86,6 @@ export type StartWatcherOptions = {
|
|
|
29
86
|
/** Regex patterns (as strings) to ignore when selecting a stack frame. */
|
|
30
87
|
rules?: string[];
|
|
31
88
|
};
|
|
32
|
-
/** Whether to include ISO timestamps in log records. Defaults to `false`. */
|
|
33
|
-
includeTimestamps?: boolean;
|
|
34
89
|
location?: {
|
|
35
90
|
/**
|
|
36
91
|
* Strip these literal prefixes from event.file for display/logging.
|
|
@@ -38,18 +93,66 @@ export type StartWatcherOptions = {
|
|
|
38
93
|
*/
|
|
39
94
|
stripUrlPrefixes?: string[];
|
|
40
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* Optional in-page indicator showing that the watcher is attached.
|
|
98
|
+
* When enabled, a small badge is injected into the page. Clicking it shows watcher info.
|
|
99
|
+
* The indicator auto-removes via TTL if the watcher dies without cleanup.
|
|
100
|
+
* Only supported in CDP mode.
|
|
101
|
+
*/
|
|
102
|
+
pageIndicator?: PageIndicatorOptions;
|
|
103
|
+
/**
|
|
104
|
+
* Network request capture configuration.
|
|
105
|
+
* When enabled, captures HTTP requests and exposes them via `/net` and `/net/tail` endpoints.
|
|
106
|
+
* Disabled by default. Only supported in CDP mode.
|
|
107
|
+
*/
|
|
108
|
+
net?: NetOptions;
|
|
109
|
+
/**
|
|
110
|
+
* Write watcher lifecycle and request logs into the attached page's DevTools console.
|
|
111
|
+
* - `none`: Do not write anything.
|
|
112
|
+
* - `minimal` (default): Write attach/detach lifecycle messages.
|
|
113
|
+
* - `full`: Same as minimal, plus log every HTTP request to the watcher API.
|
|
114
|
+
*/
|
|
115
|
+
pageConsoleLogging?: PageConsoleLogging;
|
|
116
|
+
/**
|
|
117
|
+
* Optional JavaScript to inject on attach and document start.
|
|
118
|
+
* The script is provided as raw text to keep watcher package filesystem-agnostic.
|
|
119
|
+
*/
|
|
120
|
+
inject?: {
|
|
121
|
+
script: string;
|
|
122
|
+
exposeArgus?: boolean;
|
|
123
|
+
};
|
|
41
124
|
};
|
|
42
125
|
/** Handle returned by startWatcher. */
|
|
43
126
|
export type WatcherHandle = {
|
|
44
|
-
|
|
127
|
+
/**
|
|
128
|
+
* The current watcher record (including id/bind address/port and CDP match settings).
|
|
129
|
+
*
|
|
130
|
+
* This is the shape announced in the local registry and the same metadata served via the HTTP API.
|
|
131
|
+
*/
|
|
45
132
|
watcher: WatcherRecord;
|
|
133
|
+
/**
|
|
134
|
+
* Event emitter for watcher lifecycle and request events.
|
|
135
|
+
* Subscribe to 'cdpAttached', 'cdpDetached', and 'httpRequested'.
|
|
136
|
+
*/
|
|
137
|
+
events: Emittery<ArgusWatcherEventMap>;
|
|
138
|
+
/**
|
|
139
|
+
* Stop the watcher and release resources.
|
|
140
|
+
*
|
|
141
|
+
* Shuts down CDP attachment, stops the HTTP server, closes any artifact writers (file logs),
|
|
142
|
+
* clears event listeners, and removes the watcher from the local registry.
|
|
143
|
+
*
|
|
144
|
+
* Safe to call multiple times.
|
|
145
|
+
*/
|
|
146
|
+
close: () => Promise<void>;
|
|
46
147
|
};
|
|
47
148
|
/**
|
|
48
|
-
* Start a watcher that connects to Chrome CDP, buffers console logs, and exposes the HTTP API.
|
|
49
|
-
* @param options - Configuration for binding,
|
|
149
|
+
* Start a watcher that connects to Chrome (via CDP or extension), buffers console logs, and exposes the HTTP API.
|
|
150
|
+
* @param options - Configuration for binding, source mode, and buffering.
|
|
50
151
|
* @returns A handle that can be closed to stop the watcher and clean up registry state.
|
|
51
152
|
*/
|
|
52
153
|
export declare const startWatcher: (options: StartWatcherOptions) => Promise<WatcherHandle>;
|
|
53
154
|
/** Log event shape emitted by watchers. */
|
|
54
155
|
export type { LogEvent };
|
|
156
|
+
export type { ArgusWatcherEventMap, CdpAttachedEvent, CdpDetachedEvent, HttpRequestEvent, LogRequestQuery, NetRequestQuery } from './events.js';
|
|
157
|
+
export type { PageIndicatorOptions, PageIndicatorPosition } from './cdp/pageIndicator.js';
|
|
55
158
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -1,107 +1,394 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
1
2
|
import path from 'node:path';
|
|
2
|
-
import
|
|
3
|
+
import Emittery from 'emittery';
|
|
3
4
|
import { LogBuffer } from './buffer/LogBuffer.js';
|
|
5
|
+
import { NetBuffer } from './buffer/NetBuffer.js';
|
|
4
6
|
import { startHttpServer } from './http/server.js';
|
|
5
|
-
import { announceWatcher, removeWatcher, startRegistryHeartbeat } from './registry/registry.js';
|
|
7
|
+
import { announceWatcher, removeWatcher, startRegistryHeartbeat, resolveUniqueWatcherId } from './registry/registry.js';
|
|
6
8
|
import { WatcherFileLogger } from './fileLogs/WatcherFileLogger.js';
|
|
7
9
|
import { buildIgnoreMatcher } from './cdp/ignoreList.js';
|
|
10
|
+
import { createNetworkCapture } from './cdp/networkCapture.js';
|
|
11
|
+
import { createTraceRecorder } from './cdp/tracing.js';
|
|
12
|
+
import { createScreenshotter } from './cdp/screenshot.js';
|
|
13
|
+
import { createCdpSessionHandle } from './cdp/connection.js';
|
|
14
|
+
import { createPageIndicatorController, validatePageIndicatorOptions, } from './cdp/pageIndicator.js';
|
|
15
|
+
import { createEmulationController } from './emulation/EmulationController.js';
|
|
16
|
+
import { createThrottleController } from './throttle/ThrottleController.js';
|
|
17
|
+
import { createCdpSource } from './sources/cdp-source.js';
|
|
18
|
+
import { createExtensionSource } from './sources/extension-source.js';
|
|
8
19
|
/**
|
|
9
|
-
* Start a watcher that connects to Chrome CDP, buffers console logs, and exposes the HTTP API.
|
|
10
|
-
* @param options - Configuration for binding,
|
|
20
|
+
* Start a watcher that connects to Chrome (via CDP or extension), buffers console logs, and exposes the HTTP API.
|
|
21
|
+
* @param options - Configuration for binding, source mode, and buffering.
|
|
11
22
|
* @returns A handle that can be closed to stop the watcher and clean up registry state.
|
|
12
23
|
*/
|
|
13
24
|
export const startWatcher = async (options) => {
|
|
14
25
|
if (!options.id) {
|
|
15
26
|
throw new Error('Watcher id is required');
|
|
16
27
|
}
|
|
28
|
+
const watcherId = await resolveUniqueWatcherId(options.id);
|
|
29
|
+
const sourceMode = options.source ?? 'cdp';
|
|
17
30
|
const host = options.host ?? '127.0.0.1';
|
|
18
31
|
const port = options.port ?? 0;
|
|
19
32
|
const chrome = options.chrome ?? { host: '127.0.0.1', port: 9222 };
|
|
20
33
|
const bufferSize = options.bufferSize ?? 50_000;
|
|
34
|
+
const netBufferSize = options.bufferSize ?? 50_000;
|
|
21
35
|
const startedAt = Date.now();
|
|
22
|
-
const includeTimestamps = options.includeTimestamps ?? false;
|
|
23
36
|
const ignoreMatcher = buildIgnoreMatcher(options.ignoreList);
|
|
24
37
|
const stripUrlPrefixes = options.location?.stripUrlPrefixes;
|
|
38
|
+
// Resolve artifacts configuration
|
|
39
|
+
const artifactsBaseDir = resolveArtifactsBaseDir(options.artifacts?.base, watcherId);
|
|
40
|
+
const logsEnabled = options.artifacts?.logs?.enabled === true;
|
|
41
|
+
const logsDir = path.join(artifactsBaseDir, 'logs');
|
|
42
|
+
const includeTimestamps = options.artifacts?.logs?.includeTimestamps ?? false;
|
|
43
|
+
const maxFiles = resolveMaxFiles(options.artifacts?.logs?.maxFiles);
|
|
44
|
+
// Network capture is opt-in (disabled by default) and only in CDP mode
|
|
45
|
+
const netEnabled = sourceMode === 'cdp' && options.net?.enabled === true;
|
|
46
|
+
// Page console logging (default: minimal)
|
|
47
|
+
const pageConsoleLogging = options.pageConsoleLogging ?? 'minimal';
|
|
48
|
+
const events = new Emittery();
|
|
25
49
|
const buffer = new LogBuffer(bufferSize);
|
|
50
|
+
const netBuffer = netEnabled ? new NetBuffer(netBufferSize) : null;
|
|
51
|
+
let closing = false;
|
|
52
|
+
let readyForShutdown = false;
|
|
53
|
+
let shutdownRequested = false;
|
|
54
|
+
let closeOnce = null;
|
|
26
55
|
let cdpStatus = { attached: false, target: null };
|
|
27
|
-
const
|
|
28
|
-
const logsDir = fileLogs ? resolveLogsDir(fileLogs.logsDir) : null;
|
|
29
|
-
const maxFiles = fileLogs ? resolveMaxFiles(fileLogs.maxFiles) : null;
|
|
30
|
-
const fileLogger = logsDir
|
|
56
|
+
const fileLogger = logsEnabled
|
|
31
57
|
? new WatcherFileLogger({
|
|
32
|
-
watcherId
|
|
58
|
+
watcherId,
|
|
33
59
|
startedAt,
|
|
34
60
|
logsDir,
|
|
35
|
-
chrome,
|
|
61
|
+
chrome: sourceMode === 'cdp' ? chrome : undefined,
|
|
36
62
|
match: options.match,
|
|
37
|
-
maxFiles
|
|
63
|
+
maxFiles,
|
|
38
64
|
includeTimestamps,
|
|
65
|
+
buildFilename: options.artifacts?.logs?.buildFilename,
|
|
39
66
|
})
|
|
40
67
|
: null;
|
|
41
68
|
const record = {
|
|
42
|
-
id:
|
|
69
|
+
id: watcherId,
|
|
43
70
|
host,
|
|
44
71
|
port,
|
|
45
72
|
pid: process.pid,
|
|
73
|
+
cwd: process.cwd(),
|
|
46
74
|
startedAt,
|
|
47
75
|
updatedAt: Date.now(),
|
|
48
|
-
match: options.match,
|
|
49
|
-
chrome,
|
|
76
|
+
match: sourceMode === 'cdp' ? options.match : undefined,
|
|
77
|
+
chrome: sourceMode === 'cdp' ? chrome : undefined,
|
|
50
78
|
includeTimestamps,
|
|
79
|
+
source: sourceMode,
|
|
80
|
+
};
|
|
81
|
+
// Create session handle for CDP mode (used by network capture, tracing, etc.)
|
|
82
|
+
const sessionHandle = createCdpSessionHandle();
|
|
83
|
+
// Emulation controller (shared across CDP and extension modes)
|
|
84
|
+
const emulationController = createEmulationController();
|
|
85
|
+
// Throttle controller (CPU, network, cache — shared across CDP and extension modes)
|
|
86
|
+
const throttleController = createThrottleController();
|
|
87
|
+
const logToPageConsole = (message) => {
|
|
88
|
+
if (pageConsoleLogging === 'none') {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!sourceHandle?.session.isAttached()) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const fullMessage = `[ARGUS] ${watcherId} :: ${message}`;
|
|
95
|
+
queueMicrotask(() => {
|
|
96
|
+
sourceHandle?.session
|
|
97
|
+
.sendAndWait('Runtime.evaluate', {
|
|
98
|
+
expression: `console.log(${JSON.stringify(fullMessage)})`,
|
|
99
|
+
silent: true,
|
|
100
|
+
})
|
|
101
|
+
.catch(() => { });
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
// Page indicator only supported in CDP mode
|
|
105
|
+
validatePageIndicatorOptions(options.pageIndicator);
|
|
106
|
+
const indicatorEnabled = sourceMode === 'cdp' && options.pageIndicator?.enabled === true;
|
|
107
|
+
let indicatorController = null;
|
|
108
|
+
let indicatorAttachedAt = null;
|
|
109
|
+
if (indicatorEnabled) {
|
|
110
|
+
indicatorController = createPageIndicatorController(options.pageIndicator);
|
|
111
|
+
}
|
|
112
|
+
const buildIndicatorInfo = (target) => ({
|
|
113
|
+
watcherId,
|
|
114
|
+
watcherHost: host,
|
|
115
|
+
watcherPort: record.port,
|
|
116
|
+
watcherPid: process.pid,
|
|
117
|
+
targetTitle: target?.title ?? null,
|
|
118
|
+
targetUrl: target?.url ?? null,
|
|
119
|
+
attachedAt: indicatorAttachedAt ?? Date.now(),
|
|
120
|
+
});
|
|
121
|
+
const maybeInjectOnAttach = async (session, target) => {
|
|
122
|
+
if (!options.inject?.script) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!session.isAttached()) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const trimmedScript = options.inject.script.trim();
|
|
129
|
+
if (trimmedScript === '') {
|
|
130
|
+
console.warn(`[Watcher] Inject script is empty for watcher ${record.id}. Skipping.`);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const attachedAt = Date.now();
|
|
134
|
+
const exposeArgus = options.inject.exposeArgus ?? true;
|
|
135
|
+
const argusPayload = exposeArgus
|
|
136
|
+
? {
|
|
137
|
+
watcherId: record.id,
|
|
138
|
+
watcherHost: record.host,
|
|
139
|
+
watcherPort: record.port,
|
|
140
|
+
watcherPid: record.pid,
|
|
141
|
+
attachedAt,
|
|
142
|
+
target: {
|
|
143
|
+
title: target.title ?? null,
|
|
144
|
+
url: target.url ?? null,
|
|
145
|
+
type: target.type ?? 'page',
|
|
146
|
+
parentId: target.parentId ?? null,
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
: null;
|
|
150
|
+
const expression = buildInjectExpression(trimmedScript, argusPayload);
|
|
151
|
+
try {
|
|
152
|
+
await session.sendAndWait('Page.addScriptToEvaluateOnNewDocument', { source: expression });
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
console.warn(`[Watcher] Failed to register inject script for watcher ${record.id}: ${formatError(error)}`);
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
await session.sendAndWait('Runtime.evaluate', { expression, silent: true });
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
console.warn(`[Watcher] Failed to run inject script for watcher ${record.id}: ${formatError(error)}`);
|
|
162
|
+
}
|
|
51
163
|
};
|
|
164
|
+
// Create the appropriate source based on mode
|
|
165
|
+
let sourceHandle;
|
|
166
|
+
let networkCapture = null;
|
|
167
|
+
let traceRecorder;
|
|
168
|
+
let screenshotter;
|
|
169
|
+
if (sourceMode === 'extension') {
|
|
170
|
+
// Extension mode
|
|
171
|
+
sourceHandle = createExtensionSource({
|
|
172
|
+
events: {
|
|
173
|
+
onLog: (event) => {
|
|
174
|
+
buffer.add(event);
|
|
175
|
+
fileLogger?.writeEvent(event);
|
|
176
|
+
},
|
|
177
|
+
onStatus: (status) => {
|
|
178
|
+
const prevAttached = cdpStatus.attached;
|
|
179
|
+
cdpStatus = status;
|
|
180
|
+
if (status.attached && !prevAttached) {
|
|
181
|
+
const url = status.target?.url ?? 'unknown';
|
|
182
|
+
logToPageConsole(`attached (url=${url})`);
|
|
183
|
+
void events.emit('cdpAttached', {
|
|
184
|
+
ts: Date.now(),
|
|
185
|
+
watcherId,
|
|
186
|
+
target: status.target,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
else if (!status.attached && prevAttached) {
|
|
190
|
+
void events.emit('cdpDetached', {
|
|
191
|
+
ts: Date.now(),
|
|
192
|
+
watcherId,
|
|
193
|
+
target: status.target,
|
|
194
|
+
reason: status.reason ?? 'unknown',
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
onPageNavigation: (info) => {
|
|
199
|
+
fileLogger?.rotate(info);
|
|
200
|
+
},
|
|
201
|
+
onPageIntl: (info) => {
|
|
202
|
+
fileLogger?.setPageIntl(info);
|
|
203
|
+
},
|
|
204
|
+
onAttach: async (session, target) => {
|
|
205
|
+
await emulationController.onAttach(session);
|
|
206
|
+
await throttleController.onAttach(session);
|
|
207
|
+
await maybeInjectOnAttach(session, target);
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
ignoreMatcher: ignoreMatcher ? (url) => ignoreMatcher.matches(url) : null,
|
|
211
|
+
stripUrlPrefixes,
|
|
212
|
+
});
|
|
213
|
+
// Create trace/screenshot with proxy session
|
|
214
|
+
traceRecorder = createTraceRecorder({ session: sourceHandle.session, artifactsDir: artifactsBaseDir });
|
|
215
|
+
screenshotter = createScreenshotter({ session: sourceHandle.session, artifactsDir: artifactsBaseDir });
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
// CDP mode
|
|
219
|
+
networkCapture = netBuffer ? createNetworkCapture({ session: sessionHandle.session, buffer: netBuffer }) : null;
|
|
220
|
+
traceRecorder = createTraceRecorder({ session: sessionHandle.session, artifactsDir: artifactsBaseDir });
|
|
221
|
+
screenshotter = createScreenshotter({ session: sessionHandle.session, artifactsDir: artifactsBaseDir });
|
|
222
|
+
sourceHandle = createCdpSource({
|
|
223
|
+
chrome,
|
|
224
|
+
match: options.match,
|
|
225
|
+
sessionHandle,
|
|
226
|
+
events: {
|
|
227
|
+
onLog: (event) => {
|
|
228
|
+
buffer.add(event);
|
|
229
|
+
fileLogger?.writeEvent(event);
|
|
230
|
+
},
|
|
231
|
+
onStatus: (status) => {
|
|
232
|
+
const prevAttached = cdpStatus.attached;
|
|
233
|
+
cdpStatus = status;
|
|
234
|
+
if (status.attached && !prevAttached) {
|
|
235
|
+
const url = status.target?.url ?? 'unknown';
|
|
236
|
+
logToPageConsole(`attached (url=${url})`);
|
|
237
|
+
void events.emit('cdpAttached', {
|
|
238
|
+
ts: Date.now(),
|
|
239
|
+
watcherId,
|
|
240
|
+
target: status.target,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
else if (!status.attached && prevAttached) {
|
|
244
|
+
void events.emit('cdpDetached', {
|
|
245
|
+
ts: Date.now(),
|
|
246
|
+
watcherId,
|
|
247
|
+
target: status.target,
|
|
248
|
+
reason: status.reason ?? 'unknown',
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
onPageNavigation: (info) => {
|
|
253
|
+
fileLogger?.rotate(info);
|
|
254
|
+
if (indicatorController) {
|
|
255
|
+
indicatorController.onNavigation(sessionHandle.session, buildIndicatorInfo({ title: null, url: info.url }));
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
onPageLoad: () => {
|
|
259
|
+
if (indicatorController) {
|
|
260
|
+
indicatorController.reinstall();
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
onPageIntl: (info) => {
|
|
264
|
+
fileLogger?.setPageIntl(info);
|
|
265
|
+
},
|
|
266
|
+
onAttach: async (session, target) => {
|
|
267
|
+
await emulationController.onAttach(session);
|
|
268
|
+
await throttleController.onAttach(session);
|
|
269
|
+
await networkCapture?.onAttached();
|
|
270
|
+
if (indicatorController) {
|
|
271
|
+
indicatorAttachedAt = Date.now();
|
|
272
|
+
indicatorController.onAttach(session, {
|
|
273
|
+
id: target.id,
|
|
274
|
+
title: target.title,
|
|
275
|
+
url: target.url,
|
|
276
|
+
type: target.type ?? 'page',
|
|
277
|
+
parentId: target.parentId ?? null,
|
|
278
|
+
webSocketDebuggerUrl: '',
|
|
279
|
+
}, buildIndicatorInfo({ title: target.title, url: target.url }));
|
|
280
|
+
}
|
|
281
|
+
await maybeInjectOnAttach(session, target);
|
|
282
|
+
},
|
|
283
|
+
onDetach: (reason) => {
|
|
284
|
+
networkCapture?.onDetached();
|
|
285
|
+
traceRecorder.onDetached(reason);
|
|
286
|
+
indicatorController?.onDetach();
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
ignoreMatcher: ignoreMatcher ? (url) => ignoreMatcher.matches(url) : null,
|
|
290
|
+
stripUrlPrefixes,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
52
293
|
const server = await startHttpServer({
|
|
53
294
|
host,
|
|
54
295
|
port,
|
|
55
296
|
buffer,
|
|
297
|
+
netBuffer,
|
|
56
298
|
getWatcher: () => record,
|
|
57
299
|
getCdpStatus: () => cdpStatus,
|
|
300
|
+
cdpSession: sourceHandle.session,
|
|
301
|
+
traceRecorder,
|
|
302
|
+
screenshotter,
|
|
303
|
+
emulationController,
|
|
304
|
+
throttleController,
|
|
305
|
+
// Extension mode endpoints
|
|
306
|
+
sourceHandle: sourceMode === 'extension' ? sourceHandle : undefined,
|
|
307
|
+
onRequest: (event) => {
|
|
308
|
+
if (pageConsoleLogging === 'full') {
|
|
309
|
+
logToPageConsole(`http ${event.endpoint}`);
|
|
310
|
+
}
|
|
311
|
+
void events.emit('httpRequested', {
|
|
312
|
+
...event,
|
|
313
|
+
watcherId,
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
onShutdown: () => {
|
|
317
|
+
if (!readyForShutdown || !closeOnce) {
|
|
318
|
+
shutdownRequested = true;
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
void closeOnce();
|
|
322
|
+
},
|
|
58
323
|
});
|
|
59
324
|
record.port = server.port;
|
|
60
325
|
await announceWatcher(record);
|
|
61
326
|
const heartbeat = startRegistryHeartbeat(() => record, options.heartbeatMs ?? 15_000);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
327
|
+
closeOnce = async () => {
|
|
328
|
+
if (closing) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
closing = true;
|
|
332
|
+
heartbeat.stop();
|
|
333
|
+
indicatorController?.stop();
|
|
334
|
+
if (cdpStatus.attached) {
|
|
335
|
+
logToPageConsole('detached (reason=watcher_stopped)');
|
|
336
|
+
}
|
|
337
|
+
await sourceHandle.stop();
|
|
338
|
+
await fileLogger?.close();
|
|
339
|
+
traceRecorder.onDetached('watcher_stopped');
|
|
340
|
+
await server.close();
|
|
341
|
+
await removeWatcher(record.id);
|
|
342
|
+
events.clearListeners();
|
|
343
|
+
};
|
|
344
|
+
readyForShutdown = true;
|
|
345
|
+
if (shutdownRequested) {
|
|
346
|
+
void closeOnce();
|
|
347
|
+
}
|
|
81
348
|
return {
|
|
82
349
|
watcher: record,
|
|
350
|
+
events,
|
|
83
351
|
close: async () => {
|
|
84
|
-
|
|
85
|
-
await cdp.stop();
|
|
86
|
-
await fileLogger?.close();
|
|
87
|
-
await server.close();
|
|
88
|
-
await removeWatcher(record.id);
|
|
352
|
+
await closeOnce?.();
|
|
89
353
|
},
|
|
90
354
|
};
|
|
91
355
|
};
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
|
|
356
|
+
const resolveArtifactsBaseDir = (base, watcherId) => {
|
|
357
|
+
if (base !== undefined && base !== null) {
|
|
358
|
+
if (typeof base !== 'string' || base.trim() === '') {
|
|
359
|
+
throw new Error('artifacts.base must be a non-empty string when provided');
|
|
360
|
+
}
|
|
361
|
+
return path.resolve(base);
|
|
95
362
|
}
|
|
96
|
-
return path.
|
|
363
|
+
return path.join(os.tmpdir(), 'argus', watcherId);
|
|
97
364
|
};
|
|
98
365
|
const resolveMaxFiles = (maxFiles) => {
|
|
99
366
|
if (maxFiles === undefined) {
|
|
100
367
|
return 5;
|
|
101
368
|
}
|
|
102
369
|
if (!Number.isInteger(maxFiles) || maxFiles < 1) {
|
|
103
|
-
throw new Error('
|
|
370
|
+
throw new Error('artifacts.logs.maxFiles must be an integer >= 1');
|
|
104
371
|
}
|
|
105
372
|
return maxFiles;
|
|
106
373
|
};
|
|
374
|
+
const buildInjectExpression = (script, argusPayload) => {
|
|
375
|
+
const lines = ['(() => {'];
|
|
376
|
+
if (argusPayload) {
|
|
377
|
+
lines.push(`window.__ARGUS__ = ${JSON.stringify(argusPayload)};`);
|
|
378
|
+
}
|
|
379
|
+
lines.push(`const __argusScript = ${JSON.stringify(script)};`);
|
|
380
|
+
lines.push('const __argusFn = new Function(__argusScript);');
|
|
381
|
+
lines.push('__argusFn();');
|
|
382
|
+
lines.push('})();');
|
|
383
|
+
return lines.join('\n');
|
|
384
|
+
};
|
|
385
|
+
const formatError = (error) => {
|
|
386
|
+
if (!error) {
|
|
387
|
+
return 'Unknown error';
|
|
388
|
+
}
|
|
389
|
+
if (error instanceof Error) {
|
|
390
|
+
return error.message;
|
|
391
|
+
}
|
|
392
|
+
return String(error);
|
|
393
|
+
};
|
|
107
394
|
//# sourceMappingURL=index.js.map
|