patchright-core 1.57.0 → 1.58.2

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 (148) hide show
  1. package/ThirdPartyNotices.txt +3223 -308
  2. package/browsers.json +21 -22
  3. package/lib/cli/program.js +4 -5
  4. package/lib/client/api.js +3 -0
  5. package/lib/client/browser.js +3 -5
  6. package/lib/client/browserContext.js +40 -4
  7. package/lib/client/browserType.js +4 -3
  8. package/lib/client/connection.js +4 -0
  9. package/lib/client/elementHandle.js +3 -0
  10. package/lib/client/events.js +3 -0
  11. package/lib/client/fetch.js +3 -4
  12. package/lib/client/frame.js +10 -1
  13. package/lib/client/locator.js +8 -0
  14. package/lib/client/network.js +5 -1
  15. package/lib/client/page.js +29 -1
  16. package/lib/client/pageAgent.js +64 -0
  17. package/lib/client/platform.js +3 -0
  18. package/lib/client/tracing.js +1 -1
  19. package/lib/generated/injectedScriptSource.js +1 -1
  20. package/lib/generated/pollingRecorderSource.js +1 -1
  21. package/lib/mcpBundle.js +84 -0
  22. package/lib/mcpBundleImpl/index.js +147 -0
  23. package/lib/protocol/serializers.js +5 -0
  24. package/lib/protocol/validator.js +88 -4
  25. package/lib/remote/playwrightServer.js +1 -2
  26. package/lib/server/agent/actionRunner.js +335 -0
  27. package/lib/server/agent/actions.js +128 -0
  28. package/lib/server/agent/codegen.js +111 -0
  29. package/lib/server/agent/context.js +150 -0
  30. package/lib/server/agent/expectTools.js +156 -0
  31. package/lib/server/agent/pageAgent.js +204 -0
  32. package/lib/server/agent/performTools.js +262 -0
  33. package/lib/server/agent/tool.js +109 -0
  34. package/lib/server/artifact.js +1 -1
  35. package/lib/server/bidi/bidiBrowser.js +56 -12
  36. package/lib/server/bidi/bidiChromium.js +8 -12
  37. package/lib/server/bidi/bidiConnection.js +1 -0
  38. package/lib/server/bidi/bidiDeserializer.js +116 -0
  39. package/lib/server/bidi/bidiExecutionContext.js +75 -29
  40. package/lib/server/bidi/bidiFirefox.js +6 -8
  41. package/lib/server/bidi/bidiNetworkManager.js +1 -1
  42. package/lib/server/bidi/bidiPage.js +39 -28
  43. package/lib/server/bidi/third_party/bidiProtocolCore.js +1 -0
  44. package/lib/server/browserContext.js +34 -26
  45. package/lib/server/browserType.js +12 -4
  46. package/lib/server/chromium/chromium.js +14 -20
  47. package/lib/server/chromium/chromiumSwitches.js +2 -2
  48. package/lib/server/chromium/crBrowser.js +22 -12
  49. package/lib/server/chromium/crConnection.js +0 -5
  50. package/lib/server/chromium/crCoverage.js +13 -1
  51. package/lib/server/chromium/crDevTools.js +0 -2
  52. package/lib/server/chromium/crNetworkManager.js +92 -12
  53. package/lib/server/chromium/crPage.js +62 -116
  54. package/lib/server/codegen/javascript.js +6 -29
  55. package/lib/server/deviceDescriptorsSource.json +56 -56
  56. package/lib/server/dispatchers/browserContextDispatcher.js +3 -2
  57. package/lib/server/dispatchers/dispatcher.js +6 -13
  58. package/lib/server/dispatchers/frameDispatcher.js +1 -1
  59. package/lib/server/dispatchers/jsHandleDispatcher.js +2 -2
  60. package/lib/server/dispatchers/pageAgentDispatcher.js +96 -0
  61. package/lib/server/dispatchers/pageDispatcher.js +4 -0
  62. package/lib/server/dom.js +12 -3
  63. package/lib/server/electron/electron.js +5 -2
  64. package/lib/server/firefox/ffBrowser.js +10 -20
  65. package/lib/server/firefox/ffConnection.js +0 -5
  66. package/lib/server/firefox/ffNetworkManager.js +2 -2
  67. package/lib/server/firefox/ffPage.js +15 -18
  68. package/lib/server/firefox/firefox.js +6 -8
  69. package/lib/server/frameSelectors.js +16 -4
  70. package/lib/server/frames.js +251 -86
  71. package/lib/server/instrumentation.js +3 -0
  72. package/lib/server/javascript.js +8 -4
  73. package/lib/server/launchApp.js +2 -1
  74. package/lib/server/network.js +50 -12
  75. package/lib/server/page.js +61 -91
  76. package/lib/server/progress.js +26 -6
  77. package/lib/server/recorder/recorderApp.js +79 -100
  78. package/lib/server/registry/browserFetcher.js +6 -4
  79. package/lib/server/registry/index.js +172 -149
  80. package/lib/server/registry/oopDownloadBrowserMain.js +3 -0
  81. package/lib/server/screencast.js +190 -0
  82. package/lib/server/screenshotter.js +6 -0
  83. package/lib/server/trace/recorder/snapshotter.js +17 -8
  84. package/lib/server/trace/recorder/snapshotterInjected.js +30 -72
  85. package/lib/server/trace/recorder/tracing.js +29 -21
  86. package/lib/server/trace/viewer/traceParser.js +72 -0
  87. package/lib/server/trace/viewer/traceViewer.js +21 -17
  88. package/lib/server/utils/expectUtils.js +87 -2
  89. package/lib/server/utils/hostPlatform.js +15 -0
  90. package/lib/server/utils/httpServer.js +5 -20
  91. package/lib/server/utils/network.js +37 -28
  92. package/lib/server/utils/nodePlatform.js +6 -0
  93. package/lib/server/{chromium/videoRecorder.js → videoRecorder.js} +22 -13
  94. package/lib/server/webkit/webkit.js +4 -6
  95. package/lib/server/webkit/wkBrowser.js +2 -6
  96. package/lib/server/webkit/wkConnection.js +1 -6
  97. package/lib/server/webkit/wkInterceptableRequest.js +29 -1
  98. package/lib/server/webkit/wkPage.js +75 -46
  99. package/lib/utils/isomorphic/ariaSnapshot.js +60 -2
  100. package/lib/utils/isomorphic/lruCache.js +51 -0
  101. package/lib/utils/isomorphic/protocolMetainfo.js +9 -1
  102. package/lib/utils/isomorphic/stringUtils.js +49 -0
  103. package/lib/utils/isomorphic/trace/entries.js +16 -0
  104. package/lib/utils/isomorphic/trace/snapshotRenderer.js +499 -0
  105. package/lib/utils/isomorphic/trace/snapshotServer.js +120 -0
  106. package/lib/utils/isomorphic/trace/snapshotStorage.js +89 -0
  107. package/lib/utils/isomorphic/trace/traceLoader.js +131 -0
  108. package/lib/utils/isomorphic/trace/traceModel.js +365 -0
  109. package/lib/utils/isomorphic/trace/traceModernizer.js +400 -0
  110. package/lib/utils/isomorphic/trace/versions/traceV3.js +16 -0
  111. package/lib/utils/isomorphic/trace/versions/traceV4.js +16 -0
  112. package/lib/utils/isomorphic/trace/versions/traceV5.js +16 -0
  113. package/lib/utils/isomorphic/trace/versions/traceV6.js +16 -0
  114. package/lib/utils/isomorphic/trace/versions/traceV7.js +16 -0
  115. package/lib/utils/isomorphic/trace/versions/traceV8.js +16 -0
  116. package/lib/utils/isomorphic/yaml.js +84 -0
  117. package/lib/utils.js +2 -0
  118. package/lib/utilsBundle.js +2 -5
  119. package/lib/utilsBundleImpl/index.js +165 -165
  120. package/lib/vite/htmlReport/index.html +21 -21
  121. package/lib/vite/recorder/assets/codeMirrorModule-CFUTFUO7.js +32 -0
  122. package/lib/vite/{traceViewer/codeMirrorModule.C3UTv-Ge.css → recorder/assets/codeMirrorModule-DYBRYzYX.css} +1 -1
  123. package/lib/vite/recorder/assets/{index-Ri0uHF7I.css → index-BSjZa4pk.css} +1 -1
  124. package/lib/vite/recorder/assets/index-CVkBxsGf.js +193 -0
  125. package/lib/vite/recorder/index.html +2 -2
  126. package/lib/vite/traceViewer/assets/codeMirrorModule-BVA4h_ZY.js +32 -0
  127. package/lib/vite/traceViewer/assets/defaultSettingsView-CjfmcdOz.js +266 -0
  128. package/lib/vite/{recorder/assets/codeMirrorModule-C3UTv-Ge.css → traceViewer/codeMirrorModule.DYBRYzYX.css} +1 -1
  129. package/lib/vite/traceViewer/defaultSettingsView.7ch9cixO.css +1 -0
  130. package/lib/vite/traceViewer/index.BVu7tZDe.css +1 -0
  131. package/lib/vite/traceViewer/index.BtyWtaE-.js +2 -0
  132. package/lib/vite/traceViewer/index.html +4 -4
  133. package/lib/vite/traceViewer/sw.bundle.js +5 -3
  134. package/lib/vite/traceViewer/uiMode.fyrXARf2.js +5 -0
  135. package/lib/vite/traceViewer/uiMode.html +3 -3
  136. package/package.json +2 -1
  137. package/types/protocol.d.ts +738 -159
  138. package/types/types.d.ts +25 -38
  139. package/lib/server/bidi/third_party/bidiDeserializer.js +0 -98
  140. package/lib/server/trace/test/inMemorySnapshotter.js +0 -87
  141. package/lib/vite/recorder/assets/codeMirrorModule-CBbSe-ZI.js +0 -25
  142. package/lib/vite/recorder/assets/index-CpZVd2nA.js +0 -193
  143. package/lib/vite/traceViewer/assets/codeMirrorModule-DHz0wP2C.js +0 -25
  144. package/lib/vite/traceViewer/assets/defaultSettingsView-WsZP88O6.js +0 -266
  145. package/lib/vite/traceViewer/defaultSettingsView.ConWv5KN.css +0 -1
  146. package/lib/vite/traceViewer/index.C4Y3Aw8n.css +0 -1
  147. package/lib/vite/traceViewer/index.C8xAeo93.js +0 -2
  148. package/lib/vite/traceViewer/uiMode.BltraIJB.js +0 -5
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var serializers_exports = {};
20
20
  __export(serializers_exports, {
21
21
  parseSerializedValue: () => parseSerializedValue,
22
+ serializePlainValue: () => serializePlainValue,
22
23
  serializeValue: () => serializeValue
23
24
  });
24
25
  module.exports = __toCommonJS(serializers_exports);
@@ -90,6 +91,9 @@ function innerParseSerializedValue(value, handles, refs, accessChain) {
90
91
  function serializeValue(value, handleSerializer) {
91
92
  return innerSerializeValue(value, handleSerializer, { lastId: 0, visited: /* @__PURE__ */ new Map() }, []);
92
93
  }
94
+ function serializePlainValue(arg) {
95
+ return serializeValue(arg, (value) => ({ fallThrough: value }));
96
+ }
93
97
  function innerSerializeValue(value, handleSerializer, visitorInfo, accessChain) {
94
98
  const handle = handleSerializer(value);
95
99
  if ("fallThrough" in handle)
@@ -188,5 +192,6 @@ const constructorToTypedArrayKind = new Map(Object.entries(typedArrayKindToConst
188
192
  // Annotate the CommonJS export names for ESM import in node:
189
193
  0 && (module.exports = {
190
194
  parseSerializedValue,
195
+ serializePlainValue,
191
196
  serializeValue
192
197
  });
@@ -512,7 +512,6 @@ import_validatorPrimitives.scheme.BrowserTypeLaunchParams = (0, import_validator
512
512
  timeout: import_validatorPrimitives.tFloat,
513
513
  env: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tArray)((0, import_validatorPrimitives.tType)("NameValue"))),
514
514
  headless: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean),
515
- devtools: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean),
516
515
  proxy: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({
517
516
  server: import_validatorPrimitives.tString,
518
517
  bypass: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
@@ -542,7 +541,6 @@ import_validatorPrimitives.scheme.BrowserTypeLaunchPersistentContextParams = (0,
542
541
  timeout: import_validatorPrimitives.tFloat,
543
542
  env: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tArray)((0, import_validatorPrimitives.tType)("NameValue"))),
544
543
  headless: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean),
545
- devtools: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean),
546
544
  proxy: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({
547
545
  server: import_validatorPrimitives.tString,
548
546
  bypass: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
@@ -610,6 +608,7 @@ import_validatorPrimitives.scheme.BrowserTypeLaunchPersistentContextParams = (0,
610
608
  serviceWorkers: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tEnum)(["allow", "block"])),
611
609
  selectorEngines: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tArray)((0, import_validatorPrimitives.tType)("SelectorEngine"))),
612
610
  testIdAttributeName: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
611
+ focusControl: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean),
613
612
  userDataDir: import_validatorPrimitives.tString,
614
613
  slowMo: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tFloat)
615
614
  });
@@ -621,7 +620,8 @@ import_validatorPrimitives.scheme.BrowserTypeConnectOverCDPParams = (0, import_v
621
620
  endpointURL: import_validatorPrimitives.tString,
622
621
  headers: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tArray)((0, import_validatorPrimitives.tType)("NameValue"))),
623
622
  slowMo: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tFloat),
624
- timeout: import_validatorPrimitives.tFloat
623
+ timeout: import_validatorPrimitives.tFloat,
624
+ isLocal: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean)
625
625
  });
626
626
  import_validatorPrimitives.scheme.BrowserTypeConnectOverCDPResult = (0, import_validatorPrimitives.tObject)({
627
627
  browser: (0, import_validatorPrimitives.tChannel)(["Browser"]),
@@ -702,6 +702,7 @@ import_validatorPrimitives.scheme.BrowserNewContextParams = (0, import_validator
702
702
  serviceWorkers: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tEnum)(["allow", "block"])),
703
703
  selectorEngines: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tArray)((0, import_validatorPrimitives.tType)("SelectorEngine"))),
704
704
  testIdAttributeName: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
705
+ focusControl: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean),
705
706
  proxy: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({
706
707
  server: import_validatorPrimitives.tString,
707
708
  bypass: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
@@ -773,6 +774,7 @@ import_validatorPrimitives.scheme.BrowserNewContextForReuseParams = (0, import_v
773
774
  serviceWorkers: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tEnum)(["allow", "block"])),
774
775
  selectorEngines: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tArray)((0, import_validatorPrimitives.tType)("SelectorEngine"))),
775
776
  testIdAttributeName: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
777
+ focusControl: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean),
776
778
  proxy: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({
777
779
  server: import_validatorPrimitives.tString,
778
780
  bypass: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
@@ -821,6 +823,7 @@ import_validatorPrimitives.scheme.WorkerWaitForEventInfoParams = (0, import_vali
821
823
  import_validatorPrimitives.scheme.WebSocketWaitForEventInfoParams = (0, import_validatorPrimitives.tType)("EventTargetWaitForEventInfoParams");
822
824
  import_validatorPrimitives.scheme.ElectronApplicationWaitForEventInfoParams = (0, import_validatorPrimitives.tType)("EventTargetWaitForEventInfoParams");
823
825
  import_validatorPrimitives.scheme.AndroidDeviceWaitForEventInfoParams = (0, import_validatorPrimitives.tType)("EventTargetWaitForEventInfoParams");
826
+ import_validatorPrimitives.scheme.PageAgentWaitForEventInfoParams = (0, import_validatorPrimitives.tType)("EventTargetWaitForEventInfoParams");
824
827
  import_validatorPrimitives.scheme.EventTargetWaitForEventInfoResult = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
825
828
  import_validatorPrimitives.scheme.BrowserContextWaitForEventInfoResult = (0, import_validatorPrimitives.tType)("EventTargetWaitForEventInfoResult");
826
829
  import_validatorPrimitives.scheme.PageWaitForEventInfoResult = (0, import_validatorPrimitives.tType)("EventTargetWaitForEventInfoResult");
@@ -828,6 +831,7 @@ import_validatorPrimitives.scheme.WorkerWaitForEventInfoResult = (0, import_vali
828
831
  import_validatorPrimitives.scheme.WebSocketWaitForEventInfoResult = (0, import_validatorPrimitives.tType)("EventTargetWaitForEventInfoResult");
829
832
  import_validatorPrimitives.scheme.ElectronApplicationWaitForEventInfoResult = (0, import_validatorPrimitives.tType)("EventTargetWaitForEventInfoResult");
830
833
  import_validatorPrimitives.scheme.AndroidDeviceWaitForEventInfoResult = (0, import_validatorPrimitives.tType)("EventTargetWaitForEventInfoResult");
834
+ import_validatorPrimitives.scheme.PageAgentWaitForEventInfoResult = (0, import_validatorPrimitives.tType)("EventTargetWaitForEventInfoResult");
831
835
  import_validatorPrimitives.scheme.BrowserContextInitializer = (0, import_validatorPrimitives.tObject)({
832
836
  isChromium: import_validatorPrimitives.tBoolean,
833
837
  requestContext: (0, import_validatorPrimitives.tChannel)(["APIRequestContext"]),
@@ -888,7 +892,8 @@ import_validatorPrimitives.scheme.BrowserContextInitializer = (0, import_validat
888
892
  strictSelectors: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean),
889
893
  serviceWorkers: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tEnum)(["allow", "block"])),
890
894
  selectorEngines: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tArray)((0, import_validatorPrimitives.tType)("SelectorEngine"))),
891
- testIdAttributeName: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString)
895
+ testIdAttributeName: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
896
+ focusControl: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean)
892
897
  })
893
898
  });
894
899
  import_validatorPrimitives.scheme.BrowserContextBindingCallEvent = (0, import_validatorPrimitives.tObject)({
@@ -1075,6 +1080,8 @@ import_validatorPrimitives.scheme.BrowserContextEnableRecorderParams = (0, impor
1075
1080
  import_validatorPrimitives.scheme.BrowserContextEnableRecorderResult = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
1076
1081
  import_validatorPrimitives.scheme.BrowserContextDisableRecorderParams = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
1077
1082
  import_validatorPrimitives.scheme.BrowserContextDisableRecorderResult = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
1083
+ import_validatorPrimitives.scheme.BrowserContextExposeConsoleApiParams = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
1084
+ import_validatorPrimitives.scheme.BrowserContextExposeConsoleApiResult = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
1078
1085
  import_validatorPrimitives.scheme.BrowserContextNewCDPSessionParams = (0, import_validatorPrimitives.tObject)({
1079
1086
  page: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tChannel)(["Page"])),
1080
1087
  frame: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tChannel)(["Frame"]))
@@ -1490,6 +1497,25 @@ import_validatorPrimitives.scheme.PageUpdateSubscriptionParams = (0, import_vali
1490
1497
  enabled: import_validatorPrimitives.tBoolean
1491
1498
  });
1492
1499
  import_validatorPrimitives.scheme.PageUpdateSubscriptionResult = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
1500
+ import_validatorPrimitives.scheme.PageAgentParams = (0, import_validatorPrimitives.tObject)({
1501
+ api: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
1502
+ apiKey: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
1503
+ apiEndpoint: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
1504
+ apiTimeout: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
1505
+ apiCacheFile: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
1506
+ cacheFile: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
1507
+ cacheOutFile: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
1508
+ doNotRenderActive: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean),
1509
+ maxActions: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
1510
+ maxActionRetries: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
1511
+ maxTokens: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
1512
+ model: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
1513
+ secrets: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tArray)((0, import_validatorPrimitives.tType)("NameValue"))),
1514
+ systemPrompt: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString)
1515
+ });
1516
+ import_validatorPrimitives.scheme.PageAgentResult = (0, import_validatorPrimitives.tObject)({
1517
+ agent: (0, import_validatorPrimitives.tChannel)(["PageAgent"])
1518
+ });
1493
1519
  import_validatorPrimitives.scheme.FrameInitializer = (0, import_validatorPrimitives.tObject)({
1494
1520
  url: import_validatorPrimitives.tString,
1495
1521
  name: import_validatorPrimitives.tString,
@@ -2785,6 +2811,7 @@ import_validatorPrimitives.scheme.AndroidDeviceLaunchBrowserParams = (0, import_
2785
2811
  serviceWorkers: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tEnum)(["allow", "block"])),
2786
2812
  selectorEngines: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tArray)((0, import_validatorPrimitives.tType)("SelectorEngine"))),
2787
2813
  testIdAttributeName: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
2814
+ focusControl: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tBoolean),
2788
2815
  pkg: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
2789
2816
  args: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tArray)(import_validatorPrimitives.tString)),
2790
2817
  proxy: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({
@@ -2888,6 +2915,63 @@ import_validatorPrimitives.scheme.JsonPipeSendParams = (0, import_validatorPrimi
2888
2915
  import_validatorPrimitives.scheme.JsonPipeSendResult = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
2889
2916
  import_validatorPrimitives.scheme.JsonPipeCloseParams = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
2890
2917
  import_validatorPrimitives.scheme.JsonPipeCloseResult = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
2918
+ import_validatorPrimitives.scheme.PageAgentInitializer = (0, import_validatorPrimitives.tObject)({
2919
+ page: (0, import_validatorPrimitives.tChannel)(["Page"])
2920
+ });
2921
+ import_validatorPrimitives.scheme.PageAgentTurnEvent = (0, import_validatorPrimitives.tObject)({
2922
+ role: import_validatorPrimitives.tString,
2923
+ message: import_validatorPrimitives.tString,
2924
+ usage: (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({
2925
+ inputTokens: import_validatorPrimitives.tInt,
2926
+ outputTokens: import_validatorPrimitives.tInt
2927
+ }))
2928
+ });
2929
+ import_validatorPrimitives.scheme.PageAgentPerformParams = (0, import_validatorPrimitives.tObject)({
2930
+ task: import_validatorPrimitives.tString,
2931
+ maxActions: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
2932
+ maxActionRetries: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
2933
+ maxTokens: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
2934
+ cacheKey: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
2935
+ timeout: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt)
2936
+ });
2937
+ import_validatorPrimitives.scheme.PageAgentPerformResult = (0, import_validatorPrimitives.tObject)({
2938
+ usage: (0, import_validatorPrimitives.tType)("AgentUsage")
2939
+ });
2940
+ import_validatorPrimitives.scheme.PageAgentExpectParams = (0, import_validatorPrimitives.tObject)({
2941
+ expectation: import_validatorPrimitives.tString,
2942
+ maxActions: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
2943
+ maxActionRetries: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
2944
+ maxTokens: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
2945
+ cacheKey: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
2946
+ timeout: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt)
2947
+ });
2948
+ import_validatorPrimitives.scheme.PageAgentExpectResult = (0, import_validatorPrimitives.tObject)({
2949
+ usage: (0, import_validatorPrimitives.tType)("AgentUsage")
2950
+ });
2951
+ import_validatorPrimitives.scheme.PageAgentExtractParams = (0, import_validatorPrimitives.tObject)({
2952
+ query: import_validatorPrimitives.tString,
2953
+ schema: import_validatorPrimitives.tAny,
2954
+ maxActions: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
2955
+ maxActionRetries: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
2956
+ maxTokens: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt),
2957
+ cacheKey: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tString),
2958
+ timeout: (0, import_validatorPrimitives.tOptional)(import_validatorPrimitives.tInt)
2959
+ });
2960
+ import_validatorPrimitives.scheme.PageAgentExtractResult = (0, import_validatorPrimitives.tObject)({
2961
+ result: import_validatorPrimitives.tAny,
2962
+ usage: (0, import_validatorPrimitives.tType)("AgentUsage")
2963
+ });
2964
+ import_validatorPrimitives.scheme.PageAgentDisposeParams = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
2965
+ import_validatorPrimitives.scheme.PageAgentDisposeResult = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
2966
+ import_validatorPrimitives.scheme.PageAgentUsageParams = (0, import_validatorPrimitives.tOptional)((0, import_validatorPrimitives.tObject)({}));
2967
+ import_validatorPrimitives.scheme.PageAgentUsageResult = (0, import_validatorPrimitives.tObject)({
2968
+ usage: (0, import_validatorPrimitives.tType)("AgentUsage")
2969
+ });
2970
+ import_validatorPrimitives.scheme.AgentUsage = (0, import_validatorPrimitives.tObject)({
2971
+ turns: import_validatorPrimitives.tInt,
2972
+ inputTokens: import_validatorPrimitives.tInt,
2973
+ outputTokens: import_validatorPrimitives.tInt
2974
+ });
2891
2975
  // Annotate the CommonJS export names for ESM import in node:
2892
2976
  0 && (module.exports = {
2893
2977
  ValidationError,
@@ -321,8 +321,7 @@ const defaultLaunchOptions = {
321
321
  handleSIGINT: false,
322
322
  handleSIGTERM: false,
323
323
  handleSIGHUP: false,
324
- headless: true,
325
- devtools: false
324
+ headless: true
326
325
  };
327
326
  const optionsThatAllowBrowserReuse = [
328
327
  "headless",
@@ -0,0 +1,335 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var actionRunner_exports = {};
20
+ __export(actionRunner_exports, {
21
+ runAction: () => runAction,
22
+ traceParamsForAction: () => traceParamsForAction
23
+ });
24
+ module.exports = __toCommonJS(actionRunner_exports);
25
+ var import_expectUtils = require("../utils/expectUtils");
26
+ var import_urlMatch = require("../../utils/isomorphic/urlMatch");
27
+ var import_stringUtils = require("../../utils/isomorphic/stringUtils");
28
+ var import_time = require("../../utils/isomorphic/time");
29
+ var import_crypto = require("../utils/crypto");
30
+ var import_ariaSnapshot = require("../../utils/isomorphic/ariaSnapshot");
31
+ var import_locatorGenerators = require("../../utils/isomorphic/locatorGenerators");
32
+ var import_utilsBundle = require("../../utilsBundle");
33
+ var import_errors = require("../errors");
34
+ async function runAction(progress, mode, page, action, secrets) {
35
+ const parentMetadata = progress.metadata;
36
+ const frame = page.mainFrame();
37
+ const callMetadata = callMetadataForAction(progress, frame, action, mode);
38
+ callMetadata.log = parentMetadata.log;
39
+ progress.metadata = callMetadata;
40
+ await frame.instrumentation.onBeforeCall(frame, callMetadata, parentMetadata.id);
41
+ let error;
42
+ const result = await innerRunAction(progress, mode, page, action, secrets).catch((e) => error = e);
43
+ callMetadata.endTime = (0, import_time.monotonicTime)();
44
+ callMetadata.error = error ? (0, import_errors.serializeError)(error) : void 0;
45
+ callMetadata.result = error ? void 0 : result;
46
+ await frame.instrumentation.onAfterCall(frame, callMetadata);
47
+ if (error)
48
+ throw error;
49
+ return result;
50
+ }
51
+ async function innerRunAction(progress, mode, page, action, secrets) {
52
+ const frame = page.mainFrame();
53
+ const commonOptions = { strict: true, noAutoWaiting: mode === "generate" };
54
+ switch (action.method) {
55
+ case "navigate":
56
+ await frame.goto(progress, action.url);
57
+ break;
58
+ case "click":
59
+ await frame.click(progress, action.selector, {
60
+ button: action.button,
61
+ clickCount: action.clickCount,
62
+ modifiers: action.modifiers,
63
+ ...commonOptions
64
+ });
65
+ break;
66
+ case "drag":
67
+ await frame.dragAndDrop(progress, action.sourceSelector, action.targetSelector, { ...commonOptions });
68
+ break;
69
+ case "hover":
70
+ await frame.hover(progress, action.selector, {
71
+ modifiers: action.modifiers,
72
+ ...commonOptions
73
+ });
74
+ break;
75
+ case "selectOption":
76
+ await frame.selectOption(progress, action.selector, [], action.labels.map((a) => ({ label: a })), { ...commonOptions });
77
+ break;
78
+ case "pressKey":
79
+ await page.keyboard.press(progress, action.key);
80
+ break;
81
+ case "pressSequentially": {
82
+ const secret = secrets?.find((s) => s.name === action.text)?.value ?? action.text;
83
+ await frame.type(progress, action.selector, secret, { ...commonOptions });
84
+ if (action.submit)
85
+ await page.keyboard.press(progress, "Enter");
86
+ break;
87
+ }
88
+ case "fill": {
89
+ const secret = secrets?.find((s) => s.name === action.text)?.value ?? action.text;
90
+ await frame.fill(progress, action.selector, secret, { ...commonOptions });
91
+ if (action.submit)
92
+ await page.keyboard.press(progress, "Enter");
93
+ break;
94
+ }
95
+ case "setChecked":
96
+ if (action.checked)
97
+ await frame.check(progress, action.selector, { ...commonOptions });
98
+ else
99
+ await frame.uncheck(progress, action.selector, { ...commonOptions });
100
+ break;
101
+ case "expectVisible": {
102
+ await runExpect(frame, progress, mode, action.selector, { expression: "to.be.visible", isNot: !!action.isNot }, "visible", "toBeVisible", "");
103
+ break;
104
+ }
105
+ case "expectValue": {
106
+ if (action.type === "textbox" || action.type === "combobox" || action.type === "slider") {
107
+ const expectedText = (0, import_expectUtils.serializeExpectedTextValues)([action.value]);
108
+ await runExpect(frame, progress, mode, action.selector, { expression: "to.have.value", expectedText, isNot: !!action.isNot }, action.value, "toHaveValue", "expected");
109
+ } else if (action.type === "checkbox" || action.type === "radio") {
110
+ const expectedValue = { checked: action.value === "true" };
111
+ await runExpect(frame, progress, mode, action.selector, { selector: action.selector, expression: "to.be.checked", expectedValue, isNot: !!action.isNot }, action.value ? "checked" : "unchecked", "toBeChecked", "");
112
+ } else {
113
+ throw new Error(`Unsupported element type: ${action.type}`);
114
+ }
115
+ break;
116
+ }
117
+ case "expectAria": {
118
+ const expectedValue = (0, import_ariaSnapshot.parseAriaSnapshotUnsafe)(import_utilsBundle.yaml, action.template);
119
+ await runExpect(frame, progress, mode, "body", { expression: "to.match.aria", expectedValue, isNot: !!action.isNot }, "\n" + action.template, "toMatchAriaSnapshot", "expected");
120
+ break;
121
+ }
122
+ case "expectURL": {
123
+ if (!action.regex && !action.value)
124
+ throw new Error("Either url or regex must be provided");
125
+ if (action.regex && action.value)
126
+ throw new Error("Only one of url or regex can be provided");
127
+ const expected = action.regex ? (0, import_stringUtils.parseRegex)(action.regex) : (0, import_urlMatch.constructURLBasedOnBaseURL)(page.browserContext._options.baseURL, action.value);
128
+ const expectedText = (0, import_expectUtils.serializeExpectedTextValues)([expected]);
129
+ await runExpect(frame, progress, mode, void 0, { expression: "to.have.url", expectedText, isNot: !!action.isNot }, expected, "toHaveURL", "expected");
130
+ break;
131
+ }
132
+ case "expectTitle": {
133
+ const expectedText = (0, import_expectUtils.serializeExpectedTextValues)([action.value], { normalizeWhiteSpace: true });
134
+ await runExpect(frame, progress, mode, void 0, { expression: "to.have.title", expectedText, isNot: !!action.isNot }, action.value, "toHaveTitle", "expected");
135
+ break;
136
+ }
137
+ }
138
+ }
139
+ async function runExpect(frame, progress, mode, selector, options, expected, matcherName, expectation) {
140
+ const result = await frame.expect(progress, selector, {
141
+ ...options,
142
+ // When generating, we want the expect to pass or fail immediately and give feedback to the model.
143
+ noAutoWaiting: mode === "generate",
144
+ timeoutForLogs: mode === "generate" ? void 0 : progress.timeout
145
+ });
146
+ if (!result.matches === !options.isNot) {
147
+ const received = matcherName === "toMatchAriaSnapshot" ? "\n" + result.received.raw : result.received;
148
+ const expectedSuffix = typeof expected === "string" ? "" : " pattern";
149
+ const expectedDisplay = typeof expected === "string" ? expected : expected.toString();
150
+ throw new Error((0, import_expectUtils.formatMatcherMessage)(import_expectUtils.simpleMatcherUtils, {
151
+ isNot: options.isNot,
152
+ matcherName,
153
+ expectation,
154
+ locator: selector ? (0, import_locatorGenerators.asLocatorDescription)("javascript", selector) : void 0,
155
+ timedOut: result.timedOut,
156
+ timeout: mode === "generate" ? void 0 : progress.timeout,
157
+ printedExpected: options.isNot ? `Expected${expectedSuffix}: not ${expectedDisplay}` : `Expected${expectedSuffix}: ${expectedDisplay}`,
158
+ printedReceived: result.errorMessage ? "" : `Received: ${received}`,
159
+ errorMessage: result.errorMessage
160
+ // Note: we are not passing call log, because it will be automatically appended on the client side,
161
+ // as a part of the agent.{perform,expect} call.
162
+ }));
163
+ }
164
+ }
165
+ function traceParamsForAction(progress, action, mode) {
166
+ const timeout = progress.timeout;
167
+ switch (action.method) {
168
+ case "navigate": {
169
+ const params = {
170
+ url: action.url,
171
+ timeout
172
+ };
173
+ return { type: "Frame", method: "goto", params };
174
+ }
175
+ case "click": {
176
+ const params = {
177
+ selector: action.selector,
178
+ strict: true,
179
+ modifiers: action.modifiers,
180
+ button: action.button,
181
+ clickCount: action.clickCount,
182
+ timeout
183
+ };
184
+ return { type: "Frame", method: "click", params };
185
+ }
186
+ case "drag": {
187
+ const params = {
188
+ source: action.sourceSelector,
189
+ target: action.targetSelector,
190
+ timeout
191
+ };
192
+ return { type: "Frame", method: "dragAndDrop", params };
193
+ }
194
+ case "hover": {
195
+ const params = {
196
+ selector: action.selector,
197
+ modifiers: action.modifiers,
198
+ timeout
199
+ };
200
+ return { type: "Frame", method: "hover", params };
201
+ }
202
+ case "pressKey": {
203
+ const params = {
204
+ key: action.key
205
+ };
206
+ return { type: "Page", method: "keyboardPress", params };
207
+ }
208
+ case "pressSequentially": {
209
+ const params = {
210
+ selector: action.selector,
211
+ text: action.text,
212
+ timeout
213
+ };
214
+ return { type: "Frame", method: "type", params };
215
+ }
216
+ case "fill": {
217
+ const params = {
218
+ selector: action.selector,
219
+ strict: true,
220
+ value: action.text,
221
+ timeout
222
+ };
223
+ return { type: "Frame", method: "fill", params };
224
+ }
225
+ case "setChecked": {
226
+ if (action.checked) {
227
+ const params = {
228
+ selector: action.selector,
229
+ strict: true,
230
+ timeout
231
+ };
232
+ return { type: "Frame", method: "check", params };
233
+ } else {
234
+ const params = {
235
+ selector: action.selector,
236
+ strict: true,
237
+ timeout
238
+ };
239
+ return { type: "Frame", method: "uncheck", params };
240
+ }
241
+ }
242
+ case "selectOption": {
243
+ const params = {
244
+ selector: action.selector,
245
+ strict: true,
246
+ options: action.labels.map((label) => ({ label })),
247
+ timeout
248
+ };
249
+ return { type: "Frame", method: "selectOption", params };
250
+ }
251
+ case "expectValue": {
252
+ if (action.type === "textbox" || action.type === "combobox" || action.type === "slider") {
253
+ const expectedText = (0, import_expectUtils.serializeExpectedTextValues)([action.value]);
254
+ const params = {
255
+ selector: action.selector,
256
+ expression: "to.have.value",
257
+ expectedText,
258
+ isNot: !!action.isNot,
259
+ timeout
260
+ };
261
+ return { type: "Frame", method: "expect", title: "Expect Value", params };
262
+ } else if (action.type === "checkbox" || action.type === "radio") {
263
+ const params = {
264
+ selector: action.selector,
265
+ expression: "to.be.checked",
266
+ isNot: !!action.isNot,
267
+ timeout
268
+ };
269
+ return { type: "Frame", method: "expect", title: "Expect Checked", params };
270
+ } else {
271
+ throw new Error(`Unsupported element type: ${action.type}`);
272
+ }
273
+ }
274
+ case "expectVisible": {
275
+ const params = {
276
+ selector: action.selector,
277
+ expression: "to.be.visible",
278
+ isNot: !!action.isNot,
279
+ timeout
280
+ };
281
+ return { type: "Frame", method: "expect", title: "Expect Visible", params };
282
+ }
283
+ case "expectAria": {
284
+ const params = {
285
+ selector: "body",
286
+ expression: "to.match.snapshot",
287
+ expectedText: [],
288
+ isNot: !!action.isNot,
289
+ timeout
290
+ };
291
+ return { type: "Frame", method: "expect", title: "Expect Aria Snapshot", params };
292
+ }
293
+ case "expectURL": {
294
+ const expected = action.regex ? (0, import_stringUtils.parseRegex)(action.regex) : action.value;
295
+ const expectedText = (0, import_expectUtils.serializeExpectedTextValues)([expected]);
296
+ const params = {
297
+ selector: void 0,
298
+ expression: "to.have.url",
299
+ expectedText,
300
+ isNot: !!action.isNot,
301
+ timeout
302
+ };
303
+ return { type: "Frame", method: "expect", title: "Expect URL", params };
304
+ }
305
+ case "expectTitle": {
306
+ const expectedText = (0, import_expectUtils.serializeExpectedTextValues)([action.value], { normalizeWhiteSpace: true });
307
+ const params = {
308
+ selector: void 0,
309
+ expression: "to.have.title",
310
+ expectedText,
311
+ isNot: !!action.isNot,
312
+ timeout
313
+ };
314
+ return { type: "Frame", method: "expect", title: "Expect Title", params };
315
+ }
316
+ }
317
+ }
318
+ function callMetadataForAction(progress, frame, action, mode) {
319
+ const callMetadata = {
320
+ id: `call@${(0, import_crypto.createGuid)()}`,
321
+ objectId: frame.guid,
322
+ pageId: frame._page.guid,
323
+ frameId: frame.guid,
324
+ startTime: (0, import_time.monotonicTime)(),
325
+ endTime: 0,
326
+ log: [],
327
+ ...traceParamsForAction(progress, action, mode)
328
+ };
329
+ return callMetadata;
330
+ }
331
+ // Annotate the CommonJS export names for ESM import in node:
332
+ 0 && (module.exports = {
333
+ runAction,
334
+ traceParamsForAction
335
+ });