@intuned/runtime 1.3.18-interface.7 → 1.3.19

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 (299) hide show
  1. package/.babelrc +27 -0
  2. package/.eslintignore +10 -0
  3. package/.eslintrc.js +39 -0
  4. package/CHANGELOG.md +1 -1
  5. package/InterfaceTemplate/__utils.ts +63 -0
  6. package/InterfaceTemplate/index.playwright.ts +6 -0
  7. package/dist/commands/api/run.d.ts +6 -0
  8. package/dist/commands/api/run.js +119 -0
  9. package/dist/commands/auth-sessions/load.d.ts +2 -0
  10. package/dist/commands/auth-sessions/load.js +35 -0
  11. package/dist/commands/auth-sessions/run-check.d.ts +2 -0
  12. package/dist/commands/auth-sessions/run-check.js +74 -0
  13. package/dist/commands/auth-sessions/run-create.d.ts +2 -0
  14. package/dist/commands/auth-sessions/run-create.js +78 -0
  15. package/dist/commands/browser/save-state.d.ts +2 -0
  16. package/dist/commands/browser/save-state.js +17 -0
  17. package/dist/commands/browser/start-browser.d.ts +2 -0
  18. package/dist/commands/browser/start-browser.js +14 -0
  19. package/dist/commands/build.d.ts +1 -0
  20. package/dist/commands/build.js +83 -0
  21. package/dist/commands/common/browserUtils.d.ts +14 -0
  22. package/dist/commands/common/browserUtils.js +57 -0
  23. package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
  24. package/dist/commands/common/getFirstLineNumber.js +101 -0
  25. package/dist/commands/common/getFirstLineNumber.test.js +227 -0
  26. package/dist/commands/common/projectExclusions.d.ts +2 -0
  27. package/dist/commands/common/projectExclusions.js +8 -0
  28. package/dist/commands/common/sendMessageToClient.d.ts +1 -0
  29. package/dist/commands/common/sendMessageToClient.js +10 -0
  30. package/dist/commands/common/tsNodeImport.d.ts +2 -0
  31. package/dist/commands/common/tsNodeImport.js +42 -0
  32. package/dist/commands/common/utils/fileUtils.d.ts +6 -0
  33. package/dist/commands/common/utils/fileUtils.js +32 -0
  34. package/dist/commands/common/utils/interfaceClient.d.ts +31 -0
  35. package/dist/commands/common/utils/interfaceClient.js +98 -0
  36. package/dist/commands/common/utils/settings.d.ts +2 -0
  37. package/dist/commands/common/utils/settings.js +31 -0
  38. package/dist/commands/common/utils/template.d.ts +2 -0
  39. package/dist/commands/common/utils/template.js +30 -0
  40. package/dist/commands/get-headless-user-agent.d.ts +1 -0
  41. package/dist/commands/get-headless-user-agent.js +18 -0
  42. package/dist/commands/interface/run.d.ts +1 -3
  43. package/dist/commands/interface/run.js +139 -2047
  44. package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
  45. package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
  46. package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
  47. package/dist/commands/intuned-cli/commands/attempt_api.command.js +30 -0
  48. package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
  49. package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
  50. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
  51. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +19 -0
  52. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
  53. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +24 -0
  54. package/dist/commands/intuned-cli/commands/authsession.command.d.ts +1 -0
  55. package/dist/commands/intuned-cli/commands/authsession.command.js +8 -0
  56. package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +1 -0
  57. package/dist/commands/intuned-cli/commands/authsession_record.command.js +32 -0
  58. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.d.ts +1 -0
  59. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.js +16 -0
  60. package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
  61. package/dist/commands/intuned-cli/commands/build.command.js +12 -0
  62. package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
  63. package/dist/commands/intuned-cli/commands/command.js +9 -0
  64. package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
  65. package/dist/commands/intuned-cli/commands/deploy.command.js +42 -0
  66. package/dist/commands/intuned-cli/commands/index.d.ts +18 -0
  67. package/dist/commands/intuned-cli/commands/index.js +203 -0
  68. package/dist/commands/intuned-cli/commands/provision.command.d.ts +13 -0
  69. package/dist/commands/intuned-cli/commands/provision.command.js +50 -0
  70. package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
  71. package/dist/commands/intuned-cli/commands/run.command.js +8 -0
  72. package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
  73. package/dist/commands/intuned-cli/commands/run_api.command.js +46 -0
  74. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +35 -0
  75. package/dist/commands/intuned-cli/commands/run_authsession.command.js +17 -0
  76. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
  77. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +35 -0
  78. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
  79. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +35 -0
  80. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
  81. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +33 -0
  82. package/dist/commands/intuned-cli/commands/types.d.ts +39 -0
  83. package/dist/commands/intuned-cli/commands/types.js +33 -0
  84. package/dist/commands/intuned-cli/constants/index.d.ts +17 -0
  85. package/dist/commands/intuned-cli/constants/index.js +25 -0
  86. package/dist/commands/intuned-cli/controller/__test__/api.test.js +399 -0
  87. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +1061 -0
  88. package/dist/commands/intuned-cli/controller/api.d.ts +42 -0
  89. package/dist/commands/intuned-cli/controller/api.js +194 -0
  90. package/dist/commands/intuned-cli/controller/authSession.d.ts +209 -0
  91. package/dist/commands/intuned-cli/controller/authSession.js +425 -0
  92. package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
  93. package/dist/commands/intuned-cli/controller/build.js +35 -0
  94. package/dist/commands/intuned-cli/controller/deploy.d.ts +5 -0
  95. package/dist/commands/intuned-cli/controller/deploy.js +317 -0
  96. package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
  97. package/dist/commands/intuned-cli/controller/index.js +45 -0
  98. package/dist/commands/intuned-cli/controller/provision.d.ts +21 -0
  99. package/dist/commands/intuned-cli/controller/provision.js +299 -0
  100. package/dist/commands/intuned-cli/controller/scaffold.d.ts +1 -0
  101. package/dist/commands/intuned-cli/controller/scaffold.js +77 -0
  102. package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +152 -0
  103. package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +41 -0
  104. package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
  105. package/dist/commands/intuned-cli/helpers/api.js +16 -0
  106. package/dist/commands/intuned-cli/helpers/auth.d.ts +46 -0
  107. package/dist/commands/intuned-cli/helpers/auth.js +147 -0
  108. package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
  109. package/dist/commands/intuned-cli/helpers/backend.js +35 -0
  110. package/dist/commands/intuned-cli/helpers/browser.d.ts +14 -0
  111. package/dist/commands/intuned-cli/helpers/browser.js +93 -0
  112. package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
  113. package/dist/commands/intuned-cli/helpers/context.js +33 -0
  114. package/dist/commands/intuned-cli/helpers/errors.d.ts +16 -0
  115. package/dist/commands/intuned-cli/helpers/errors.js +44 -0
  116. package/dist/commands/intuned-cli/helpers/index.d.ts +12 -0
  117. package/dist/commands/intuned-cli/helpers/index.js +137 -0
  118. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +40 -0
  119. package/dist/commands/intuned-cli/helpers/intunedJson.js +20 -0
  120. package/dist/commands/intuned-cli/helpers/prompts.d.ts +3 -0
  121. package/dist/commands/intuned-cli/helpers/prompts.js +71 -0
  122. package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
  123. package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
  124. package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
  125. package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
  126. package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
  127. package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
  128. package/dist/commands/intuned-cli/helpers/traces.d.ts +2 -0
  129. package/dist/commands/intuned-cli/helpers/traces.js +32 -0
  130. package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
  131. package/dist/commands/intuned-cli/helpers/validation.js +14 -0
  132. package/dist/commands/intuned-cli/helpers/wrapper.d.ts +2 -0
  133. package/dist/commands/intuned-cli/helpers/wrapper.js +76 -0
  134. package/dist/commands/intuned-cli/index.d.ts +1 -0
  135. package/dist/commands/intuned-cli/index.js +16 -0
  136. package/dist/commands/intuned-cli/main.d.ts +1 -0
  137. package/dist/commands/intuned-cli/main.js +35 -0
  138. package/dist/commands/intuned-cli/types.d.ts +70 -0
  139. package/dist/commands/intuned-cli/types.js +22 -0
  140. package/dist/commands/ts-check.d.ts +2 -0
  141. package/dist/commands/ts-check.js +55 -0
  142. package/dist/common/Logger/Logger/index.d.ts +12 -0
  143. package/dist/common/Logger/Logger/index.js +60 -0
  144. package/dist/common/Logger/Logger/types.d.ts +8 -0
  145. package/dist/common/Logger/Logger/types.js +5 -0
  146. package/dist/common/Logger/index.d.ts +12 -0
  147. package/dist/common/Logger/index.js +60 -0
  148. package/dist/common/Logger/types.d.ts +8 -0
  149. package/dist/common/Logger/types.js +5 -0
  150. package/dist/common/asyncLocalStorage/index.d.ts +8 -9
  151. package/dist/common/asyncLocalStorage/index.js +9 -34
  152. package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
  153. package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
  154. package/dist/common/binStartupScript.d.ts +1 -2
  155. package/dist/common/binStartupScript.js +25 -132
  156. package/dist/common/browserTabs.d.ts +72 -0
  157. package/dist/common/browserTabs.js +74 -0
  158. package/dist/common/cleanEnvironmentVariables.d.ts +1 -3
  159. package/dist/common/cleanEnvironmentVariables.js +7 -30
  160. package/dist/common/constants.d.ts +11 -13
  161. package/dist/common/constants.js +15 -58
  162. package/dist/common/contextStorageStateHelpers.d.ts +6 -8
  163. package/dist/common/contextStorageStateHelpers.js +26 -48
  164. package/dist/common/extension/extensionsHelpers.d.ts +11 -0
  165. package/dist/common/extension/extensionsHelpers.js +147 -0
  166. package/dist/common/extension/intunedExtensionServer.d.ts +24 -0
  167. package/dist/common/extension/intunedExtensionServer.js +178 -0
  168. package/dist/common/extension/types.d.ts +219 -0
  169. package/dist/common/extension/types.js +51 -0
  170. package/dist/common/formatZodError.d.ts +2 -0
  171. package/dist/{chunk-NDMVGENG.mjs → common/formatZodError.js} +9 -9
  172. package/dist/common/intunedJson.d.ts +244 -0
  173. package/dist/common/intunedJson.js +154 -0
  174. package/dist/common/jwtTokenManager.d.ts +4 -6
  175. package/dist/common/jwtTokenManager.js +40 -108
  176. package/dist/common/launchBrowser.d.ts +36 -0
  177. package/dist/common/launchBrowser.js +273 -0
  178. package/dist/common/playwrightContext.d.ts +29 -0
  179. package/dist/common/playwrightContext.js +148 -0
  180. package/dist/common/runApi/importUsingImportFunction.d.ts +7 -0
  181. package/dist/common/runApi/importUsingImportFunction.js +46 -0
  182. package/dist/common/runApi/index.d.ts +6 -9
  183. package/dist/common/runApi/index.js +73 -1782
  184. package/dist/common/settingsSchema.d.ts +6 -9
  185. package/dist/common/settingsSchema.js +18 -54
  186. package/dist/common/setupContextHook.d.ts +16 -0
  187. package/dist/common/setupContextHook.js +22 -0
  188. package/dist/common/telemetry.d.ts +3 -6
  189. package/dist/common/telemetry.js +8 -41
  190. package/dist/index.d.ts +4 -6
  191. package/dist/index.js +92 -784
  192. package/dist/runtime/RunError.d.ts +5 -0
  193. package/dist/runtime/RunError.js +19 -0
  194. package/dist/runtime/attemptStore.d.ts +2 -0
  195. package/dist/runtime/attemptStore.js +23 -0
  196. package/dist/runtime/captcha.d.ts +15 -0
  197. package/dist/runtime/captcha.js +191 -0
  198. package/dist/runtime/captcha.test.js +821 -0
  199. package/dist/runtime/downloadDirectory.d.ts +1 -0
  200. package/dist/runtime/downloadDirectory.js +19 -0
  201. package/dist/runtime/enums.d.js +5 -0
  202. package/dist/runtime/enums.d.ts +11 -0
  203. package/dist/runtime/enums.js +18 -0
  204. package/dist/runtime/executionHelpers.test.js +52 -0
  205. package/dist/runtime/export.d.js +5 -0
  206. package/dist/runtime/export.d.ts +284 -0
  207. package/dist/runtime/extendPayload.d.ts +2 -0
  208. package/dist/runtime/extendPayload.js +21 -0
  209. package/dist/runtime/extendTimeout.d.ts +1 -0
  210. package/dist/runtime/extendTimeout.js +23 -0
  211. package/dist/runtime/getAiGatewayConfig.d.ts +10 -0
  212. package/dist/runtime/getAiGatewayConfig.js +16 -0
  213. package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
  214. package/dist/runtime/getAuthSessionParameters.js +20 -0
  215. package/dist/runtime/index.d.ts +10 -168
  216. package/dist/runtime/index.js +88 -779
  217. package/dist/runtime/persistentStore.d.ts +2 -0
  218. package/dist/runtime/persistentStore.js +37 -0
  219. package/dist/runtime/persistentStore.test.js +101 -0
  220. package/dist/runtime/runInfo.d.ts +2 -0
  221. package/dist/runtime/runInfo.js +21 -0
  222. package/dist/vendor/runtime-interface.d.ts +1 -0
  223. package/dist/vendor/runtime-interface.js +491 -0
  224. package/package.json +19 -68
  225. package/template.tsconfig.json +11 -0
  226. package/tsconfig.eslint.json +5 -0
  227. package/tsconfig.json +25 -0
  228. package/tsup.config.ts +12 -0
  229. package/typedoc.json +49 -0
  230. package/dist/chunk-6ZRJOUQS.mjs +0 -16
  231. package/dist/chunk-6ZRJOUQS.mjs.map +0 -1
  232. package/dist/chunk-7YL2JUTE.mjs +0 -146
  233. package/dist/chunk-7YL2JUTE.mjs.map +0 -1
  234. package/dist/chunk-B3T6RXPC.mjs +0 -794
  235. package/dist/chunk-B3T6RXPC.mjs.map +0 -1
  236. package/dist/chunk-FGV5T6SI.mjs +0 -27
  237. package/dist/chunk-FGV5T6SI.mjs.map +0 -1
  238. package/dist/chunk-G4PO5RIV.mjs +0 -85
  239. package/dist/chunk-G4PO5RIV.mjs.map +0 -1
  240. package/dist/chunk-LZOMFHX3.mjs +0 -38
  241. package/dist/chunk-LZOMFHX3.mjs.map +0 -1
  242. package/dist/chunk-NDMVGENG.mjs.map +0 -1
  243. package/dist/chunk-W4UX6G4X.mjs +0 -17
  244. package/dist/chunk-W4UX6G4X.mjs.map +0 -1
  245. package/dist/chunk-XC75QGFG.mjs +0 -1106
  246. package/dist/chunk-XC75QGFG.mjs.map +0 -1
  247. package/dist/chunk-XOAZ2MGA.mjs +0 -59
  248. package/dist/chunk-XOAZ2MGA.mjs.map +0 -1
  249. package/dist/commands/interface/run.d.mts +0 -3
  250. package/dist/commands/interface/run.js.map +0 -1
  251. package/dist/commands/interface/run.mjs +0 -255
  252. package/dist/commands/interface/run.mjs.map +0 -1
  253. package/dist/common/asyncLocalStorage/index.d.mts +0 -17
  254. package/dist/common/asyncLocalStorage/index.js.map +0 -1
  255. package/dist/common/asyncLocalStorage/index.mjs +0 -12
  256. package/dist/common/asyncLocalStorage/index.mjs.map +0 -1
  257. package/dist/common/binStartupScript.d.mts +0 -2
  258. package/dist/common/binStartupScript.js.map +0 -1
  259. package/dist/common/binStartupScript.mjs +0 -135
  260. package/dist/common/binStartupScript.mjs.map +0 -1
  261. package/dist/common/cleanEnvironmentVariables.d.mts +0 -3
  262. package/dist/common/cleanEnvironmentVariables.js.map +0 -1
  263. package/dist/common/cleanEnvironmentVariables.mjs +0 -8
  264. package/dist/common/cleanEnvironmentVariables.mjs.map +0 -1
  265. package/dist/common/constants.d.mts +0 -13
  266. package/dist/common/constants.js.map +0 -1
  267. package/dist/common/constants.mjs +0 -28
  268. package/dist/common/constants.mjs.map +0 -1
  269. package/dist/common/contextStorageStateHelpers.d.mts +0 -24
  270. package/dist/common/contextStorageStateHelpers.js.map +0 -1
  271. package/dist/common/contextStorageStateHelpers.mjs +0 -10
  272. package/dist/common/contextStorageStateHelpers.mjs.map +0 -1
  273. package/dist/common/jwtTokenManager.d.mts +0 -19
  274. package/dist/common/jwtTokenManager.js.map +0 -1
  275. package/dist/common/jwtTokenManager.mjs +0 -11
  276. package/dist/common/jwtTokenManager.mjs.map +0 -1
  277. package/dist/common/runApi/index.d.mts +0 -11
  278. package/dist/common/runApi/index.js.map +0 -1
  279. package/dist/common/runApi/index.mjs +0 -18
  280. package/dist/common/runApi/index.mjs.map +0 -1
  281. package/dist/common/settingsSchema.d.mts +0 -540
  282. package/dist/common/settingsSchema.js.map +0 -1
  283. package/dist/common/settingsSchema.mjs +0 -10
  284. package/dist/common/settingsSchema.mjs.map +0 -1
  285. package/dist/common/telemetry.d.mts +0 -6
  286. package/dist/common/telemetry.js.map +0 -1
  287. package/dist/common/telemetry.mjs +0 -31
  288. package/dist/common/telemetry.mjs.map +0 -1
  289. package/dist/export.d-BAUMB-lG.d.mts +0 -140
  290. package/dist/export.d-BAUMB-lG.d.ts +0 -140
  291. package/dist/index.d.mts +0 -6
  292. package/dist/index.js.map +0 -1
  293. package/dist/index.mjs +0 -47
  294. package/dist/index.mjs.map +0 -1
  295. package/dist/runtime/index.d.mts +0 -168
  296. package/dist/runtime/index.js.map +0 -1
  297. package/dist/runtime/index.mjs +0 -42
  298. package/dist/runtime/index.mjs.map +0 -1
  299. /package/dist/common/assets/{assets/browser_scripts.js → browser_scripts.js} +0 -0
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getBrowserExecutablePath = getBrowserExecutablePath;
7
+ exports.getCdpWebSocketUrl = getCdpWebSocketUrl;
8
+ exports.getHeadlessUserAgent = getHeadlessUserAgent;
9
+ exports.getLocalCdpAddress = getLocalCdpAddress;
10
+ exports.launchBrowser = launchBrowser;
11
+ exports.launchChromium = launchChromium;
12
+ var playwright = _interopRequireWildcard(require("playwright"));
13
+ var _fsExtra = _interopRequireWildcard(require("fs-extra"));
14
+ var fs = _fsExtra;
15
+ var _path = require("path");
16
+ var _waitOn = _interopRequireDefault(require("wait-on"));
17
+ var _child_process = require("child_process");
18
+ var _extensionsHelpers = require("./extension/extensionsHelpers");
19
+ var _intunedExtensionServer = require("./extension/intunedExtensionServer");
20
+ var _util = require("util");
21
+ var _neverthrow = require("neverthrow");
22
+ var _zod = require("zod");
23
+ var _intunedJson = require("./intunedJson");
24
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
25
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
26
+ const execAsync = (0, _util.promisify)(_child_process.exec);
27
+ async function createUserDirWithPreferences() {
28
+ const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
29
+ const userDir = (0, _path.join)(playwrightTempDir, "userdir");
30
+ const defaultDir = (0, _path.join)(userDir, "Default");
31
+ await (0, _fsExtra.mkdir)(defaultDir, {
32
+ recursive: true
33
+ });
34
+ const preferences = {
35
+ plugins: {
36
+ always_open_pdf_externally: true
37
+ }
38
+ };
39
+ await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
40
+ return userDir;
41
+ }
42
+ async function launchChromium(options) {
43
+ if ("cdpAddress" in options) {
44
+ if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
45
+ await (0, _intunedExtensionServer.setupIntunedExtensionServer)();
46
+ }
47
+ const browser = await playwright.chromium.connectOverCDP(options.cdpAddress);
48
+ if (browser.contexts().length === 0) {
49
+ throw new Error("No browser contexts found in the connected browser");
50
+ }
51
+ const context = browser.contexts()[0];
52
+ let page = context.pages().at(0) ?? (await context.newPage());
53
+ const targetId = options.cdpTargetId;
54
+ if (targetId) {
55
+ for (const p of context.pages()) {
56
+ let cdp = null;
57
+ try {
58
+ cdp = await context.newCDPSession(p);
59
+ const result = await cdp.send("Target.getTargetInfo");
60
+ if (result.targetInfo.targetId === targetId) {
61
+ page = p;
62
+ break;
63
+ }
64
+ } catch (error) {} finally {
65
+ await cdp?.detach();
66
+ }
67
+ }
68
+ }
69
+ if (options.timeout !== undefined) {
70
+ context.setDefaultTimeout(options.timeout * 1000);
71
+ }
72
+ return {
73
+ page,
74
+ context
75
+ };
76
+ }
77
+ const {
78
+ headless,
79
+ appModeInitialUrl,
80
+ cdpPort,
81
+ proxy,
82
+ downloadsPath,
83
+ timeout
84
+ } = options;
85
+ let {
86
+ executablePath
87
+ } = options;
88
+ const defaultArgsToIgnore = ["--disable-extensions", "--disable-component-extensions-with-background-pages", "--disable-background-networking", "--disable-backgrounding-occluded-windows", "--disable-background-timer-throttling"];
89
+ const extraArgs = [];
90
+ const stealthConfig = await (0, _intunedJson.getStealthModeConfig)();
91
+ if (stealthConfig.enabled && stealthConfig.type === "intunedBrowser") {
92
+ extraArgs.push("--stealth-mode");
93
+ }
94
+ const userDataDir = await createUserDirWithPreferences();
95
+ if ((0, _extensionsHelpers.isIntunedExtensionLoaded)()) {
96
+ const extensionsList = (0, _extensionsHelpers.buildExtensionsList)();
97
+ const extensions = extensionsList.join(",");
98
+ extraArgs.push(`--disable-extensions-except=${extensions}`);
99
+ extraArgs.push(`--load-extension=${extensions}`);
100
+ }
101
+ if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
102
+ await (0, _extensionsHelpers.setupIntunedExtension)();
103
+ if (proxy) {
104
+ extraArgs.push('--proxy-bypass-list="<-loopback>"');
105
+ }
106
+ }
107
+ if (cdpPort) {
108
+ extraArgs.push(`--remote-debugging-port=${cdpPort}`);
109
+ }
110
+ if (headless) {
111
+ defaultArgsToIgnore.push("--headless=old");
112
+ extraArgs.push("--headless=new");
113
+ }
114
+ if (appModeInitialUrl) {
115
+ extraArgs.push(`--app=${appModeInitialUrl}`);
116
+ }
117
+ if (executablePath) {
118
+ executablePath = await fs.realpath(executablePath);
119
+ if (!(await fs.exists(executablePath))) {
120
+ console.log(`Warning: Executable path ${executablePath} does not exist. Falling back to default.`);
121
+ executablePath = undefined;
122
+ }
123
+ }
124
+ const viewport = null;
125
+ const userAgent = process.env.__PLAYWRIGHT_USER_AGENT_OVERRIDE ?? (await getHeadlessUserAgent({
126
+ executablePath
127
+ }));
128
+ const context = await playwright.chromium.launchPersistentContext(userDataDir, {
129
+ userAgent,
130
+ executablePath,
131
+ headless,
132
+ viewport,
133
+ proxy,
134
+ downloadsPath,
135
+ args: extraArgs,
136
+ ignoreDefaultArgs: defaultArgsToIgnore
137
+ });
138
+ if (timeout !== undefined) {
139
+ context.setDefaultTimeout(timeout * 1000);
140
+ }
141
+ context.once("close", async () => {
142
+ try {
143
+ await (0, _fsExtra.rm)(userDataDir, {
144
+ recursive: true,
145
+ force: true,
146
+ retryDelay: 1000,
147
+ maxRetries: 5
148
+ });
149
+ if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
150
+ await (0, _intunedExtensionServer.cleanIntunedExtensionServer)();
151
+ }
152
+ } catch (error) {
153
+ console.error("Failed to remove user data dir", error);
154
+ }
155
+ });
156
+ if (cdpPort) {
157
+ const createdCdpAddress = getLocalCdpAddress(cdpPort);
158
+ await waitOnCdpAddress(createdCdpAddress);
159
+ }
160
+ const page = context.pages().at(0) ?? (await context.newPage());
161
+ if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
162
+ await (0, _extensionsHelpers.getIntunedExtensionWorker)(context);
163
+ }
164
+ return {
165
+ page,
166
+ context
167
+ };
168
+ }
169
+ async function getIntunedBrowserExecutablePath() {
170
+ const intunedPath = process.env.INTUNED_BROWSER_PATH;
171
+ if (intunedPath && (await fs.exists(intunedPath))) {
172
+ return intunedPath;
173
+ }
174
+ return undefined;
175
+ }
176
+ async function getBrowserExecutablePath() {
177
+ const stealthConfig = await (0, _intunedJson.getStealthModeConfig)();
178
+ if (stealthConfig.enabled && stealthConfig.type === "intunedBrowser") {
179
+ const intunedPath = await getIntunedBrowserExecutablePath();
180
+ if (intunedPath) {
181
+ return intunedPath;
182
+ }
183
+ }
184
+ const browserType = getBrowserType();
185
+ if (browserType === "brave") {
186
+ return await getBraveExecutablePath();
187
+ }
188
+ }
189
+ async function launchBrowser(options) {
190
+ if ("cdpAddress" in options) {
191
+ return launchChromium(options);
192
+ }
193
+ return launchChromium({
194
+ ...options,
195
+ executablePath: await getBrowserExecutablePath()
196
+ });
197
+ }
198
+ function getBrowserType() {
199
+ if (process.env.BROWSER_TYPE === "brave") {
200
+ return "brave";
201
+ }
202
+ return "chromium";
203
+ }
204
+ async function getBraveExecutablePath() {
205
+ const {
206
+ stdout
207
+ } = await execAsync("which brave-browser-stable");
208
+ const bravePath = stdout.trim();
209
+ if (bravePath.length === 0) {
210
+ throw new Error("Brave browser not found");
211
+ }
212
+ return bravePath;
213
+ }
214
+ function getLocalCdpAddress(port) {
215
+ return `http://localhost:${port}`;
216
+ }
217
+ async function getCdpWebSocketUrl(cdpAddress) {
218
+ let response;
219
+ try {
220
+ response = await fetch(`${cdpAddress}/json/version`);
221
+ } catch (error) {
222
+ return (0, _neverthrow.err)(`Failed to fetch CDP version from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`);
223
+ }
224
+ if (!response.ok) {
225
+ return (0, _neverthrow.err)(`Failed to get CDP WebSocket URL from ${cdpAddress}: ${response.status} ${response.statusText}`);
226
+ }
227
+ let data;
228
+ try {
229
+ data = await response.json();
230
+ } catch (error) {
231
+ return (0, _neverthrow.err)(`Invalid CDP version response from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`);
232
+ }
233
+ const cdpJsonVersionResponseSchema = _zod.z.object({
234
+ webSocketDebuggerUrl: _zod.z.string().url()
235
+ });
236
+ const parseResult = cdpJsonVersionResponseSchema.safeParse(data);
237
+ if (!parseResult.success) {
238
+ return (0, _neverthrow.err)(`Invalid CDP version response from ${cdpAddress}: ${JSON.stringify(parseResult.error.format())}`);
239
+ }
240
+ return (0, _neverthrow.ok)(parseResult.data.webSocketDebuggerUrl);
241
+ }
242
+ async function waitOnCdpAddress(cdpAddress) {
243
+ const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
244
+ await (0, _waitOn.default)({
245
+ resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
246
+ delay: 100,
247
+ interval: 100,
248
+ timeout: 5000,
249
+ tcpTimeout: 1000,
250
+ window: 1000
251
+ });
252
+ }
253
+ async function getHeadlessUserAgent({
254
+ executablePath,
255
+ args,
256
+ ignoreDefaultArgs
257
+ }) {
258
+ const browser = await playwright.chromium.launch({
259
+ headless: true,
260
+ executablePath,
261
+ args,
262
+ ignoreDefaultArgs
263
+ });
264
+ const context = await browser.newContext();
265
+ const page = await context.newPage();
266
+ let userAgent = await page.evaluate(() => navigator.userAgent);
267
+ await browser.close();
268
+ if (!userAgent || typeof userAgent !== "string") {
269
+ return undefined;
270
+ }
271
+ userAgent = userAgent.replace("HeadlessChrome", "Chrome");
272
+ return userAgent;
273
+ }
@@ -0,0 +1,29 @@
1
+ import type * as playwright from "playwright";
2
+ import { Err, Ok } from "neverthrow";
3
+ import { type Proxy } from "./launchBrowser";
4
+ import { ImportFunction, RunAutomationError, RunApiSession } from "@intuned/runtime-interface";
5
+ type WithPlaywrightContextParameters = {
6
+ importFunction: ImportFunction;
7
+ apiName: string;
8
+ apiParameters: any;
9
+ } | {
10
+ importFunction?: undefined;
11
+ apiName?: undefined;
12
+ apiParameters?: undefined;
13
+ };
14
+ type WithPlaywrightContextWrappedFunctionReturn<R> = Ok<R, any> | Err<any, RunAutomationError>;
15
+ export type WithPlaywrightContextWrappedFunction<R> = (context: playwright.BrowserContext, page: playwright.Page) => Promise<WithPlaywrightContextWrappedFunctionReturn<R>>;
16
+ export declare function withPlaywrightContext<R>(options: {
17
+ proxy?: Proxy;
18
+ headless: boolean;
19
+ downloadsPath: string;
20
+ } & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
21
+ export declare function withPlaywrightContext<R>(options: {
22
+ cdpAddress: string;
23
+ cdpTargetId?: string;
24
+ } & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
25
+ export declare function loadSessionToContext({ context, session, }: {
26
+ context: playwright.BrowserContext;
27
+ session: RunApiSession;
28
+ }): Promise<void>;
29
+ export {};
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadSessionToContext = loadSessionToContext;
7
+ exports.withPlaywrightContext = withPlaywrightContext;
8
+ var _contextStorageStateHelpers = require("./contextStorageStateHelpers");
9
+ var fs = _interopRequireWildcard(require("fs-extra"));
10
+ var _fileUtils = require("../commands/common/utils/fileUtils");
11
+ var _neverthrow = require("neverthrow");
12
+ var _setupContextHook = require("./setupContextHook");
13
+ var _portfinder = require("portfinder");
14
+ var _launchBrowser = require("./launchBrowser");
15
+ var _runtimeInterface = require("../vendor/runtime-interface");
16
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
17
+ async function withPlaywrightContext({
18
+ cdpAddress,
19
+ cdpTargetId,
20
+ proxy,
21
+ headless = true,
22
+ downloadsPath,
23
+ importFunction,
24
+ apiName,
25
+ apiParameters
26
+ }, fn) {
27
+ let context;
28
+ let page;
29
+ try {
30
+ const setupContextHookResult = importFunction ? await (0, _setupContextHook.loadSetupContextHook)({
31
+ importFunction
32
+ }) : (0, _neverthrow.ok)(null);
33
+ if (setupContextHookResult.isErr()) {
34
+ return setupContextHookResult;
35
+ }
36
+ const setupContextHook = setupContextHookResult.value;
37
+ if (setupContextHook === null) {
38
+ if (cdpAddress !== undefined) {
39
+ ({
40
+ page,
41
+ context
42
+ } = await (0, _launchBrowser.launchBrowser)({
43
+ cdpAddress,
44
+ cdpTargetId
45
+ }));
46
+ } else {
47
+ ({
48
+ page,
49
+ context
50
+ } = await (0, _launchBrowser.launchBrowser)({
51
+ proxy,
52
+ headless,
53
+ downloadsPath
54
+ }));
55
+ }
56
+ return await fn(context, page);
57
+ }
58
+ let hookCdpUrl = null;
59
+ if (cdpAddress) {
60
+ hookCdpUrl = cdpAddress;
61
+ ({
62
+ context,
63
+ page
64
+ } = await (0, _launchBrowser.launchBrowser)({
65
+ cdpAddress,
66
+ cdpTargetId
67
+ }));
68
+ } else {
69
+ const port = await (0, _portfinder.getPort)({
70
+ port: 9222
71
+ });
72
+ ({
73
+ context,
74
+ page
75
+ } = await (0, _launchBrowser.launchBrowser)({
76
+ proxy,
77
+ headless,
78
+ downloadsPath,
79
+ cdpPort: port
80
+ }));
81
+ hookCdpUrl = (0, _launchBrowser.getLocalCdpAddress)(port);
82
+ }
83
+ let hookResult;
84
+ try {
85
+ const wsUrlResult = await (0, _launchBrowser.getCdpWebSocketUrl)(hookCdpUrl);
86
+ if (wsUrlResult.isOk()) {
87
+ hookCdpUrl = wsUrlResult.value;
88
+ } else {
89
+ throw new Error(wsUrlResult.error);
90
+ }
91
+ hookResult = await setupContextHook({
92
+ apiName: apiName,
93
+ apiParameters: apiParameters,
94
+ cdpUrl: hookCdpUrl
95
+ });
96
+ } catch (error) {
97
+ return (0, _neverthrow.err)(new _runtimeInterface.AutomationError(error));
98
+ }
99
+ if (!hookResult) {
100
+ return await fn(context, page);
101
+ }
102
+ const {
103
+ page: newPage,
104
+ context: newContext,
105
+ cleanup
106
+ } = hookResult;
107
+ let result;
108
+ try {
109
+ result = {
110
+ return: await fn(newContext, newPage ?? page)
111
+ };
112
+ } catch (e) {
113
+ result = {
114
+ throw: e
115
+ };
116
+ }
117
+ try {
118
+ await cleanup?.();
119
+ } catch (e) {
120
+ result = {
121
+ return: (0, _neverthrow.err)(new _runtimeInterface.AutomationError(e))
122
+ };
123
+ }
124
+ if ("throw" in result) {
125
+ throw result.throw;
126
+ }
127
+ return result.return;
128
+ } finally {
129
+ await context?.close();
130
+ }
131
+ }
132
+ async function loadSessionToContext({
133
+ context,
134
+ session
135
+ }) {
136
+ let sessionToLoad;
137
+ if (session.type === "state") {
138
+ const state = session.state;
139
+ if (state === undefined || state === null) {
140
+ return;
141
+ }
142
+ sessionToLoad = state;
143
+ } else {
144
+ const fullPath = (0, _fileUtils.getFullPathInProject)(session.path);
145
+ sessionToLoad = await fs.readJson(fullPath);
146
+ }
147
+ await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
148
+ }
@@ -0,0 +1,7 @@
1
+ import { Result } from "neverthrow";
2
+ import { ImportFunction, RunAutomationError } from "@intuned/runtime-interface";
3
+ export declare function importUsingImportFunction<_ReturnType = any>({ path, allowGenerators, importFunction, }: {
4
+ path: string;
5
+ importFunction: ImportFunction;
6
+ allowGenerators?: boolean;
7
+ }): Promise<Result<(..._: any) => Promise<_ReturnType>, RunAutomationError>>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.importUsingImportFunction = importUsingImportFunction;
7
+ var _neverthrow = require("neverthrow");
8
+ var _runtimeInterface = require("../../vendor/runtime-interface");
9
+ async function importUsingImportFunction({
10
+ path,
11
+ allowGenerators = true,
12
+ importFunction
13
+ }) {
14
+ try {
15
+ const importedResult = await importFunction(path);
16
+ if (importedResult.isErr()) {
17
+ if (importedResult.error.type === "not_found") {
18
+ return (0, _neverthrow.err)(new _runtimeInterface.ApiNotFoundError(path));
19
+ }
20
+ return (0, _neverthrow.err)(new _runtimeInterface.AutomationError(importedResult.error.error));
21
+ }
22
+ const imported = importedResult.value;
23
+ if (!imported || !imported.default || !imported.default.constructor) {
24
+ return (0, _neverthrow.err)(new _runtimeInterface.InvalidApiError(`${path} does not have a default export`));
25
+ }
26
+ if (imported.default.constructor.name === "AsyncGeneratorFunction") {
27
+ if (!allowGenerators) {
28
+ return (0, _neverthrow.err)(new _runtimeInterface.InvalidApiError(`${path} default export must be an async function`));
29
+ }
30
+ return (0, _neverthrow.ok)(async (...args) => {
31
+ const generator = imported.default(...args);
32
+ const result = await generator.next();
33
+ if (!result.done) {
34
+ throw new Error("Yield is not supported");
35
+ }
36
+ return result.value;
37
+ });
38
+ }
39
+ if (imported.default.constructor.name === "AsyncFunction") {
40
+ return (0, _neverthrow.ok)(imported.default);
41
+ }
42
+ return (0, _neverthrow.err)(new _runtimeInterface.InvalidApiError(`${path} default export must be an async function`));
43
+ } catch (error) {
44
+ return (0, _neverthrow.err)(new _runtimeInterface.AutomationError(error));
45
+ }
46
+ }
@@ -1,11 +1,8 @@
1
- import { Result } from 'neverthrow';
2
- import { Page, BrowserContext } from 'playwright';
3
- import { ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk, RunAutomationError } from '@intuned/runtime-interface';
4
-
5
- declare function runApi<ResultType = any>(input: ExtendedRunApiParameters & {
1
+ import { Result } from "neverthrow";
2
+ import type { Page, BrowserContext } from "playwright";
3
+ import { ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk, RunAutomationError } from "@intuned/runtime-interface";
4
+ export declare function runApi<ResultType = any>(input: ExtendedRunApiParameters & {
6
5
  retrieveSession: true;
7
6
  }): Promise<RunApiResult<ResultType, RunApiResultWithSessionOk<ResultType>>>;
8
- declare function runApi<ResultType = any>(input: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
9
- declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;
10
-
11
- export { checkAuthSessionWithRetries, runApi };
7
+ export declare function runApi<ResultType = any>(input: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
8
+ export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;