@intuned/runtime 1.3.3 → 1.3.6

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 (71) hide show
  1. package/dist/commands/api/run.js +1 -2
  2. package/dist/commands/auth-sessions/load.js +12 -9
  3. package/dist/commands/auth-sessions/run-check.js +0 -1
  4. package/dist/commands/auth-sessions/run-create.js +0 -1
  5. package/dist/commands/common/projectExclusions.js +1 -1
  6. package/dist/commands/common/tsNodeImport.js +1 -1
  7. package/dist/commands/common/utils/settings.js +6 -6
  8. package/dist/commands/intuned-cli/commands/attempt_api.command.js +10 -20
  9. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +2 -7
  10. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +5 -17
  11. package/dist/commands/intuned-cli/commands/authsession.command.d.ts +1 -0
  12. package/dist/commands/intuned-cli/commands/authsession.command.js +8 -0
  13. package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +1 -0
  14. package/dist/commands/intuned-cli/commands/authsession_record.command.js +31 -0
  15. package/dist/commands/intuned-cli/commands/build.command.js +1 -1
  16. package/dist/commands/intuned-cli/commands/deploy.command.js +2 -7
  17. package/dist/commands/intuned-cli/commands/index.d.ts +2 -0
  18. package/dist/commands/intuned-cli/commands/index.js +22 -0
  19. package/dist/commands/intuned-cli/commands/init.command.js +1 -1
  20. package/dist/commands/intuned-cli/commands/run_api.command.js +13 -21
  21. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +10 -3
  22. package/dist/commands/intuned-cli/commands/run_authsession.command.js +5 -1
  23. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -1
  24. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +16 -20
  25. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -1
  26. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +16 -20
  27. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -1
  28. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +16 -20
  29. package/dist/commands/intuned-cli/commands/save.command.d.ts +3 -2
  30. package/dist/commands/intuned-cli/commands/save.command.js +6 -10
  31. package/dist/commands/intuned-cli/commands/types.d.ts +11 -1
  32. package/dist/commands/intuned-cli/commands/types.js +11 -3
  33. package/dist/commands/intuned-cli/controller/__test__/api.test.js +128 -10
  34. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +428 -45
  35. package/dist/commands/intuned-cli/controller/api.d.ts +5 -7
  36. package/dist/commands/intuned-cli/controller/api.js +16 -7
  37. package/dist/commands/intuned-cli/controller/authSession.d.ts +18 -7
  38. package/dist/commands/intuned-cli/controller/authSession.js +153 -24
  39. package/dist/commands/intuned-cli/controller/save.js +10 -29
  40. package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +103 -0
  41. package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +40 -0
  42. package/dist/commands/intuned-cli/helpers/auth.d.ts +7 -2
  43. package/dist/commands/intuned-cli/helpers/auth.js +38 -23
  44. package/dist/commands/intuned-cli/helpers/backend.d.ts +1 -1
  45. package/dist/commands/intuned-cli/helpers/backend.js +2 -2
  46. package/dist/commands/intuned-cli/helpers/browser.d.ts +14 -0
  47. package/dist/commands/intuned-cli/helpers/browser.js +57 -0
  48. package/dist/commands/intuned-cli/helpers/errors.d.ts +0 -1
  49. package/dist/commands/intuned-cli/helpers/errors.js +0 -22
  50. package/dist/commands/intuned-cli/helpers/index.d.ts +2 -0
  51. package/dist/commands/intuned-cli/helpers/index.js +22 -0
  52. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +69 -1
  53. package/dist/commands/intuned-cli/helpers/intunedJson.js +59 -7
  54. package/dist/commands/intuned-cli/helpers/traces.d.ts +2 -0
  55. package/dist/commands/intuned-cli/helpers/traces.js +32 -0
  56. package/dist/commands/intuned-cli/helpers/validation.js +5 -3
  57. package/dist/commands/intuned-cli/helpers/wrapper.d.ts +2 -0
  58. package/dist/commands/intuned-cli/helpers/wrapper.js +60 -0
  59. package/dist/common/constants.d.ts +1 -0
  60. package/dist/common/constants.js +2 -1
  61. package/dist/common/extensionsHelpers.d.ts +15 -0
  62. package/dist/common/extensionsHelpers.js +81 -0
  63. package/dist/common/launchBrowser.d.ts +25 -0
  64. package/dist/common/launchBrowser.js +172 -0
  65. package/dist/common/playwrightContext.d.ts +1 -24
  66. package/dist/common/playwrightContext.js +9 -122
  67. package/dist/common/runApi/types.d.ts +2 -7
  68. package/dist/common/runApi/types.js +1 -2
  69. package/dist/common/settingsSchema.d.ts +513 -0
  70. package/dist/common/settingsSchema.js +40 -2
  71. package/package.json +4 -1
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.buildExtensionsList = buildExtensionsList;
7
+ exports.getIntunedExtensionPath = getIntunedExtensionPath;
8
+ exports.getIntunedExtensionSettings = getIntunedExtensionSettings;
9
+ exports.getIntunedExtensionWorker = getIntunedExtensionWorker;
10
+ exports.isIntunedExtensionEnabled = isIntunedExtensionEnabled;
11
+ exports.setupIntunedExtension = setupIntunedExtension;
12
+ var _settings = require("../commands/common/utils/settings");
13
+ var _settingsSchema = require("./settingsSchema");
14
+ var _constants = require("./constants");
15
+ var _jwtTokenManager = require("./jwtTokenManager");
16
+ var _path = _interopRequireDefault(require("path"));
17
+ var _promises = require("fs/promises");
18
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
+ const INTUNED_WORKER = "intunedWorker.js";
20
+ const INTUNED_EXTENSION_SETTINGS_FILE_NAME = "intunedSettings.json";
21
+ function buildExtensionsList() {
22
+ const extensionsList = [];
23
+ if (isIntunedExtensionEnabled()) {
24
+ const intunedExtensionPath = getIntunedExtensionPath();
25
+ extensionsList.push(intunedExtensionPath);
26
+ }
27
+ return extensionsList;
28
+ }
29
+ function getIntunedExtensionPath() {
30
+ return process.env.INTUNED_EXTENSION_PATH;
31
+ }
32
+ function isIntunedExtensionEnabled() {
33
+ return !!getIntunedExtensionPath();
34
+ }
35
+ async function getIntunedExtensionWorker(context) {
36
+ if (!isIntunedExtensionEnabled()) {
37
+ return null;
38
+ }
39
+ let attemptCount = 0;
40
+ while (attemptCount < 4) {
41
+ const intunedServiceWorker = context.serviceWorkers().find(serviceWorker => serviceWorker.url().includes(INTUNED_WORKER));
42
+ if (intunedServiceWorker) {
43
+ return intunedServiceWorker;
44
+ }
45
+ try {
46
+ await context.waitForEvent("serviceworker", {
47
+ timeout: 3000
48
+ });
49
+ } catch (err) {
50
+ console.log(`Error accessing service workers (attempt ${attemptCount})`);
51
+ }
52
+ attemptCount++;
53
+ }
54
+ console.error("Failed to get intuned worker after 5 attmepts");
55
+ return null;
56
+ }
57
+ async function getIntunedExtensionSettings() {
58
+ const settings = await (0, _settings.getSettings)();
59
+ const captchaSolverSettings = settings.captchaSolver ?? _settingsSchema.captchaSolverSettingsSchema.parse({});
60
+ const [domain, workspaceId, projectId] = [process.env.FUNCTIONS_DOMAIN, process.env[_constants.WORKSPACE_ID_ENV_VAR_KEY], process.env.INTUNED_INTEGRATION_ID ?? process.env[_constants.PROJECT_ID_ENV_VAR_KEY]];
61
+ if (!domain || !workspaceId || !projectId) {
62
+ const missingEnvVars = [domain && "FUNCTIONS_DOMAIN", workspaceId && _constants.WORKSPACE_ID_ENV_VAR_KEY, projectId && `INTUNED_INTEGRATION_ID OR ${_constants.PROJECT_ID_ENV_VAR_KEY}`];
63
+ throw new Error(`Missing required environment variables: ${missingEnvVars}`);
64
+ }
65
+ return {
66
+ ...captchaSolverSettings,
67
+ baseUrl: domain,
68
+ token: _jwtTokenManager.backendFunctionsTokenManager.token,
69
+ workspaceId,
70
+ projectId
71
+ };
72
+ }
73
+ async function setupIntunedExtension() {
74
+ if (!isIntunedExtensionEnabled()) {
75
+ return;
76
+ }
77
+ const intunedExtensionPath = getIntunedExtensionPath();
78
+ const intunedExtensionSettingsPath = _path.default.join(intunedExtensionPath, INTUNED_EXTENSION_SETTINGS_FILE_NAME);
79
+ const settings = await getIntunedExtensionSettings();
80
+ await (0, _promises.writeFile)(intunedExtensionSettingsPath, JSON.stringify(settings));
81
+ }
@@ -0,0 +1,25 @@
1
+ import * as playwright from "playwright";
2
+ export interface Proxy {
3
+ server: string;
4
+ username: string;
5
+ password: string;
6
+ }
7
+ export type LaunchBrowserResult = {
8
+ page: playwright.Page;
9
+ context: playwright.BrowserContext;
10
+ };
11
+ export type LaunchChromiumStandaloneOptions = {
12
+ proxy?: Proxy;
13
+ headless: boolean;
14
+ downloadsPath?: string;
15
+ cdpPort?: number;
16
+ appModeInitialUrl?: string;
17
+ executablePath?: string;
18
+ };
19
+ export type LaunchChromiumCdpOptions = {
20
+ cdpAddress: string;
21
+ };
22
+ export declare function launchChromium(options: LaunchChromiumStandaloneOptions): Promise<LaunchBrowserResult>;
23
+ export declare function launchChromium(options: LaunchChromiumCdpOptions): Promise<LaunchBrowserResult>;
24
+ export declare function launchBrowser(options: Omit<LaunchChromiumStandaloneOptions, "executablePath"> | LaunchChromiumCdpOptions): Promise<LaunchBrowserResult>;
25
+ export declare function getLocalCdpAddress(port: number): string;
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getLocalCdpAddress = getLocalCdpAddress;
7
+ exports.launchBrowser = launchBrowser;
8
+ exports.launchChromium = launchChromium;
9
+ var playwright = _interopRequireWildcard(require("playwright"));
10
+ var _fsExtra = _interopRequireWildcard(require("fs-extra"));
11
+ var fs = _fsExtra;
12
+ var _path = require("path");
13
+ var _waitOn = _interopRequireDefault(require("wait-on"));
14
+ var _child_process = require("child_process");
15
+ var _extensionsHelpers = require("./extensionsHelpers");
16
+ var _util = require("util");
17
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
19
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
20
+ const execAsync = (0, _util.promisify)(_child_process.exec);
21
+ async function createUserDirWithPreferences() {
22
+ const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
23
+ const userDir = (0, _path.join)(playwrightTempDir, "userdir");
24
+ const defaultDir = (0, _path.join)(userDir, "Default");
25
+ await (0, _fsExtra.mkdir)(defaultDir, {
26
+ recursive: true
27
+ });
28
+ const preferences = {
29
+ plugins: {
30
+ always_open_pdf_externally: true
31
+ }
32
+ };
33
+ await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
34
+ return userDir;
35
+ }
36
+ async function launchChromium(options) {
37
+ if ("cdpAddress" in options) {
38
+ const browser = await playwright.chromium.connectOverCDP(options.cdpAddress);
39
+ if (browser.contexts().length === 0) {
40
+ throw new Error("No browser contexts found in the connected browser");
41
+ }
42
+ const context = browser.contexts()[0];
43
+ let page = context.pages().at(0);
44
+ if (!page) {
45
+ page = await context.newPage();
46
+ }
47
+ return {
48
+ page,
49
+ context
50
+ };
51
+ }
52
+ const {
53
+ headless,
54
+ appModeInitialUrl,
55
+ cdpPort,
56
+ proxy,
57
+ downloadsPath
58
+ } = options;
59
+ let {
60
+ executablePath
61
+ } = options;
62
+ const defaultArgsToIgnore = ["--disable-extensions", "--disable-component-extensions-with-background-pages", "--disable-background-networking", "--disable-backgrounding-occluded-windows", "--disable-background-timer-throttling"];
63
+ const extraArgs = [];
64
+ const userDataDir = await createUserDirWithPreferences();
65
+ if ((0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
66
+ const extensionsList = (0, _extensionsHelpers.buildExtensionsList)();
67
+ const extensions = extensionsList.join(",");
68
+ extraArgs.push(`--disable-extensions-except=${extensions}`);
69
+ extraArgs.push(`--load-extension=${extensions}`);
70
+ await (0, _extensionsHelpers.setupIntunedExtension)();
71
+ }
72
+ if (cdpPort) {
73
+ extraArgs.push(`--remote-debugging-port=${cdpPort}`);
74
+ }
75
+ if (headless) {
76
+ defaultArgsToIgnore.push("--headless=old");
77
+ extraArgs.push("--headless=new");
78
+ }
79
+ if (appModeInitialUrl) {
80
+ extraArgs.push(`--app=${appModeInitialUrl}`);
81
+ }
82
+ if (executablePath) {
83
+ executablePath = await fs.realpath(executablePath);
84
+ if (!(await fs.exists(executablePath))) {
85
+ console.log(`Warning: Executable path ${executablePath} does not exist. Falling back to default.`);
86
+ executablePath = undefined;
87
+ }
88
+ }
89
+ const context = await playwright.chromium.launchPersistentContext(userDataDir, {
90
+ executablePath,
91
+ headless,
92
+ viewport: null,
93
+ proxy,
94
+ downloadsPath,
95
+ args: extraArgs,
96
+ ignoreDefaultArgs: defaultArgsToIgnore
97
+ });
98
+ context.once("close", async () => {
99
+ try {
100
+ await (0, _fsExtra.rm)(userDataDir, {
101
+ recursive: true,
102
+ force: true,
103
+ retryDelay: 1000,
104
+ maxRetries: 5
105
+ });
106
+ } catch (error) {
107
+ console.error("Failed to remove user data dir", error);
108
+ }
109
+ });
110
+ if (cdpPort) {
111
+ const createdCdpAddress = getLocalCdpAddress(cdpPort);
112
+ await waitOnCdpAddress(createdCdpAddress);
113
+ }
114
+ const page = context.pages().at(0) ?? (await context.newPage());
115
+ if ((0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
116
+ await (0, _extensionsHelpers.getIntunedExtensionWorker)(context);
117
+ }
118
+ return {
119
+ page,
120
+ context
121
+ };
122
+ }
123
+ async function launchBrowser(options) {
124
+ if ("cdpAddress" in options) {
125
+ return launchChromium(options);
126
+ }
127
+ const browserType = getBrowserType();
128
+ switch (browserType) {
129
+ case "chromium":
130
+ {
131
+ return launchChromium(options);
132
+ }
133
+ case "brave":
134
+ {
135
+ const braveExecutablePath = await getBraveExecutablePath();
136
+ return launchChromium({
137
+ ...options,
138
+ executablePath: braveExecutablePath
139
+ });
140
+ }
141
+ }
142
+ }
143
+ function getBrowserType() {
144
+ if (process.env.BROWSER_TYPE === "brave") {
145
+ return "brave";
146
+ }
147
+ return "chromium";
148
+ }
149
+ async function getBraveExecutablePath() {
150
+ const {
151
+ stdout
152
+ } = await execAsync("which brave-browser-stable");
153
+ const bravePath = stdout.trim();
154
+ if (bravePath.length === 0) {
155
+ throw new Error("Brave browser not found");
156
+ }
157
+ return bravePath;
158
+ }
159
+ function getLocalCdpAddress(port) {
160
+ return `http://localhost:${port}`;
161
+ }
162
+ async function waitOnCdpAddress(cdpAddress) {
163
+ const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
164
+ await (0, _waitOn.default)({
165
+ resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
166
+ delay: 100,
167
+ interval: 100,
168
+ timeout: 5000,
169
+ tcpTimeout: 1000,
170
+ window: 1000
171
+ });
172
+ }
@@ -3,26 +3,7 @@ import { RunAutomationError } from "./runApi/errors";
3
3
  import type { RunApiSession } from "./runApi/types";
4
4
  import { Err, Ok } from "neverthrow";
5
5
  import { type ImportFunction } from "./runApi/importUsingImportFunction";
6
- export interface Proxy {
7
- server: string;
8
- username: string;
9
- password: string;
10
- }
11
- export declare function launchChromium(options: {
12
- proxy?: Proxy;
13
- headless: boolean;
14
- downloadsPath?: string;
15
- cdpPort?: number;
16
- }): Promise<{
17
- page: playwright.Page;
18
- context: playwright.BrowserContext;
19
- }>;
20
- export declare function launchChromium(options: {
21
- cdpAddress: string;
22
- }): Promise<{
23
- page: playwright.Page;
24
- context: playwright.BrowserContext;
25
- }>;
6
+ import { type Proxy } from "./launchBrowser";
26
7
  export declare const browserScriptsFile: string;
27
8
  type WithPlaywrightContextParameters = {
28
9
  importFunction: ImportFunction;
@@ -47,8 +28,4 @@ export declare function loadSessionToContext({ context, session, }: {
47
28
  context: playwright.BrowserContext;
48
29
  session: RunApiSession;
49
30
  }): Promise<void>;
50
- export declare function getRemotePlaywrightContext(cdpAddress: string): Promise<{
51
- browser: playwright.Browser;
52
- context: playwright.BrowserContext;
53
- }>;
54
31
  export {};
@@ -4,95 +4,20 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.browserScriptsFile = void 0;
7
- exports.getRemotePlaywrightContext = getRemotePlaywrightContext;
8
- exports.launchChromium = launchChromium;
9
7
  exports.loadSessionToContext = loadSessionToContext;
10
8
  exports.withPlaywrightContext = withPlaywrightContext;
11
- var playwright = _interopRequireWildcard(require("playwright"));
12
- var _fsExtra = _interopRequireWildcard(require("fs-extra"));
13
- var fs = _fsExtra;
14
9
  var _contextStorageStateHelpers = require("./contextStorageStateHelpers");
15
- var _path = _interopRequireWildcard(require("path"));
10
+ var _path = _interopRequireDefault(require("path"));
11
+ var fs = _interopRequireWildcard(require("fs-extra"));
16
12
  var _fileUtils = require("../commands/common/utils/fileUtils");
17
- var _waitOn = _interopRequireDefault(require("wait-on"));
18
13
  var _errors = require("./runApi/errors");
19
14
  var _neverthrow = require("neverthrow");
20
15
  var _setupContextHook = require("./setupContextHook");
21
16
  var _portfinder = require("portfinder");
22
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
+ var _launchBrowser = require("./launchBrowser");
23
18
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
24
19
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
25
- async function createUserDirWithPreferences() {
26
- const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
27
- const userDir = (0, _path.join)(playwrightTempDir, "userdir");
28
- const defaultDir = (0, _path.join)(userDir, "Default");
29
- await (0, _fsExtra.mkdir)(defaultDir, {
30
- recursive: true
31
- });
32
- const preferences = {
33
- plugins: {
34
- always_open_pdf_externally: true
35
- }
36
- };
37
- await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
38
- return userDir;
39
- }
40
- async function launchChromium({
41
- proxy,
42
- headless = true,
43
- downloadsPath,
44
- cdpAddress,
45
- cdpPort
46
- }) {
47
- if (cdpAddress) {
48
- const browser = await playwright.chromium.connectOverCDP(cdpAddress);
49
- if (browser.contexts().length === 0) {
50
- throw new Error("No browser contexts found in the connected browser");
51
- }
52
- const context = browser.contexts()[0];
53
- let page = context.pages().at(0);
54
- if (!page) {
55
- page = await context.newPage();
56
- }
57
- return {
58
- page,
59
- context
60
- };
61
- }
62
- const extraArgs = [];
63
- const userDataDir = await createUserDirWithPreferences();
64
- if (cdpPort) {
65
- extraArgs.push(`--remote-debugging-port=${cdpPort}`);
66
- }
67
- const context = await playwright.chromium.launchPersistentContext(userDataDir, {
68
- headless,
69
- viewport: null,
70
- proxy,
71
- downloadsPath,
72
- args: extraArgs
73
- });
74
- context.once("close", async () => {
75
- try {
76
- await (0, _fsExtra.rm)(userDataDir, {
77
- recursive: true,
78
- force: true,
79
- retryDelay: 1000,
80
- maxRetries: 5
81
- });
82
- } catch (error) {
83
- console.error("Failed to remove user data dir", error);
84
- }
85
- });
86
- if (cdpPort) {
87
- const createdCdpAddress = getLocalCdpAddress(cdpPort);
88
- await waitOnCdpAddress(createdCdpAddress);
89
- }
90
- const page = context.pages().at(0) ?? (await context.newPage());
91
- return {
92
- page,
93
- context
94
- };
95
- }
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
96
21
  const browserScriptsFile = exports.browserScriptsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
97
22
  async function withPlaywrightContext({
98
23
  cdpAddress,
@@ -118,14 +43,14 @@ async function withPlaywrightContext({
118
43
  ({
119
44
  page,
120
45
  context
121
- } = await launchChromium({
46
+ } = await (0, _launchBrowser.launchBrowser)({
122
47
  cdpAddress
123
48
  }));
124
49
  } else {
125
50
  ({
126
51
  page,
127
52
  context
128
- } = await launchChromium({
53
+ } = await (0, _launchBrowser.launchBrowser)({
129
54
  proxy,
130
55
  headless,
131
56
  downloadsPath
@@ -139,18 +64,18 @@ async function withPlaywrightContext({
139
64
  ({
140
65
  context,
141
66
  page
142
- } = await launchChromium({
67
+ } = await (0, _launchBrowser.launchBrowser)({
143
68
  cdpAddress
144
69
  }));
145
70
  } else {
146
71
  const port = await (0, _portfinder.getPort)({
147
72
  port: 9222
148
73
  });
149
- hookCdpUrl = getLocalCdpAddress(port);
74
+ hookCdpUrl = (0, _launchBrowser.getLocalCdpAddress)(port);
150
75
  ({
151
76
  context,
152
77
  page
153
- } = await launchChromium({
78
+ } = await (0, _launchBrowser.launchBrowser)({
154
79
  proxy,
155
80
  headless,
156
81
  downloadsPath,
@@ -216,42 +141,4 @@ async function loadSessionToContext({
216
141
  sessionToLoad = await fs.readJson(fullPath);
217
142
  }
218
143
  await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
219
- }
220
- function getLocalCdpAddress(port) {
221
- return `http://localhost:${port}`;
222
- }
223
- async function waitOnCdpAddress(cdpAddress) {
224
- const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
225
- await (0, _waitOn.default)({
226
- resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
227
- delay: 100,
228
- interval: 100,
229
- timeout: 5000,
230
- tcpTimeout: 1000,
231
- window: 1000
232
- });
233
- }
234
- async function getRemotePlaywrightContext(cdpAddress) {
235
- const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright")));
236
- let browser = null;
237
- if (!cdpAddress) {
238
- throw new Error("cdpAddress is required");
239
- }
240
- try {
241
- await waitOnCdpAddress(cdpAddress);
242
- } catch (error) {
243
- console.error("Failed to connect to the browser");
244
- process.exit(128 + 9);
245
- }
246
- try {
247
- browser = await playwright.chromium.connectOverCDP(cdpAddress);
248
- } catch (e) {
249
- console.log(e);
250
- throw new Error("failed to connect to the browser");
251
- }
252
- const context = browser.contexts()[0];
253
- return {
254
- browser,
255
- context
256
- };
257
144
  }
@@ -673,22 +673,19 @@ export declare const runApiParametersSchema: z.ZodObject<{
673
673
  } | undefined;
674
674
  }, {
675
675
  environment: "standalone";
676
+ headless?: boolean | undefined;
676
677
  proxy?: {
677
678
  server: string;
678
679
  username: string;
679
680
  password: string;
680
681
  } | undefined;
681
- headless?: boolean | undefined;
682
682
  }>, z.ZodObject<{
683
683
  environment: z.ZodLiteral<"cdp">;
684
684
  cdpAddress: z.ZodString;
685
- mode: z.ZodUnion<[z.ZodLiteral<"vanilla">, z.ZodLiteral<"playwright">, z.ZodLiteral<"playwright-standalone">, z.ZodLiteral<"playwright-headless">]>;
686
685
  }, "strip", z.ZodTypeAny, {
687
- mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
688
686
  environment: "cdp";
689
687
  cdpAddress: string;
690
688
  }, {
691
- mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
692
689
  environment: "cdp";
693
690
  cdpAddress: string;
694
691
  }>]>>;
@@ -713,7 +710,6 @@ export declare const runApiParametersSchema: z.ZodObject<{
713
710
  password: string;
714
711
  } | undefined;
715
712
  } | {
716
- mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
717
713
  environment: "cdp";
718
714
  cdpAddress: string;
719
715
  };
@@ -799,14 +795,13 @@ export declare const runApiParametersSchema: z.ZodObject<{
799
795
  } | undefined;
800
796
  runOptions?: {
801
797
  environment: "standalone";
798
+ headless?: boolean | undefined;
802
799
  proxy?: {
803
800
  server: string;
804
801
  username: string;
805
802
  password: string;
806
803
  } | undefined;
807
- headless?: boolean | undefined;
808
804
  } | {
809
- mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
810
805
  environment: "cdp";
811
806
  cdpAddress: string;
812
807
  } | undefined;
@@ -65,8 +65,7 @@ const runApiParametersSchema = exports.runApiParametersSchema = _zod.default.obj
65
65
  }).optional()
66
66
  }), _zod.default.object({
67
67
  environment: _zod.default.literal("cdp"),
68
- cdpAddress: _zod.default.string(),
69
- mode: _zod.default.union([_zod.default.literal("vanilla"), _zod.default.literal("playwright"), _zod.default.literal("playwright-standalone"), _zod.default.literal("playwright-headless")])
68
+ cdpAddress: _zod.default.string()
70
69
  })]).default({
71
70
  environment: "standalone"
72
71
  }),