@intuned/runtime 1.3.5 → 1.3.7

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.
@@ -5,6 +5,7 @@ var _commander = require("commander");
5
5
  var _playwrightContext = require("../../common/playwrightContext");
6
6
  var _settings = require("../common/utils/settings");
7
7
  var _dotenv = _interopRequireDefault(require("dotenv"));
8
+ var _neverthrow = require("neverthrow");
8
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
10
  _dotenv.default.config({
10
11
  path: `.env`
@@ -17,15 +18,17 @@ _commander.program.description("load auth session to browser").option("--cdpAddr
17
18
  if (!setting.authSessions.enabled) {
18
19
  throw new Error("Auth session is not enabled");
19
20
  }
20
- const {
21
- context
22
- } = await (0, _playwrightContext.getRemotePlaywrightContext)(cdpAddress);
23
- await (0, _playwrightContext.loadSessionToContext)({
24
- context,
25
- session: {
26
- type: "file",
27
- path: authSessionPath
28
- }
21
+ await (0, _playwrightContext.withPlaywrightContext)({
22
+ cdpAddress
23
+ }, async context => {
24
+ await (0, _playwrightContext.loadSessionToContext)({
25
+ context,
26
+ session: {
27
+ type: "file",
28
+ path: authSessionPath
29
+ }
30
+ });
31
+ return (0, _neverthrow.ok)({});
29
32
  });
30
33
  process.exit(0);
31
34
  });
@@ -6,7 +6,7 @@ var _helpers = require("../../helpers");
6
6
  var _neverthrow = require("neverthrow");
7
7
  var _runApi = require("../../../../common/runApi");
8
8
  var _browser = require("../../helpers/browser");
9
- var _playwrightContext = require("../../../../common/playwrightContext");
9
+ var _launchBrowser = require("../../../../common/launchBrowser");
10
10
  var _promises = require("timers/promises");
11
11
  const _checkPassedResult = (0, _neverthrow.ok)({
12
12
  result: true
@@ -48,7 +48,7 @@ _vitest.vi.mock("timers/promises", () => ({
48
48
  _vitest.vi.mock("../../../../common/contextStorageStateHelpers", () => ({
49
49
  getStorageState: _vitest.vi.fn()
50
50
  }));
51
- _vitest.vi.mock("../../../../common/playwrightContext", () => ({
51
+ _vitest.vi.mock("../../../../common/launchBrowser", () => ({
52
52
  launchChromium: _vitest.vi.fn()
53
53
  }));
54
54
  _vitest.vi.mock("../../../../common/runApi", async importOriginal => {
@@ -947,7 +947,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
947
947
  pages: _vitest.vi.fn().mockReturnValue([mockPage]),
948
948
  close: _vitest.vi.fn()
949
949
  };
950
- _vitest.vi.mocked(_playwrightContext.launchChromium).mockResolvedValue({
950
+ _vitest.vi.mocked(_launchBrowser.launchChromium).mockResolvedValue({
951
951
  context: mockContext,
952
952
  page: mockPage
953
953
  });
@@ -964,7 +964,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
964
964
  });
965
965
  afterEach(() => {
966
966
  _vitest.vi.mocked(_runApi.runApi).mockReset();
967
- _vitest.vi.mocked(_playwrightContext.launchChromium).mockReset();
967
+ _vitest.vi.mocked(_launchBrowser.launchChromium).mockReset();
968
968
  _vitest.vi.useRealTimers();
969
969
  });
970
970
  (0, _vitest.it)("launches browser with app mode", async () => {
@@ -976,7 +976,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
976
976
  headless: false,
977
977
  keepBrowserOpen: false
978
978
  });
979
- (0, _vitest.expect)(_playwrightContext.launchChromium).toHaveBeenCalledWith(_vitest.expect.objectContaining({
979
+ (0, _vitest.expect)(_launchBrowser.launchChromium).toHaveBeenCalledWith(_vitest.expect.objectContaining({
980
980
  appModeInitialUrl: "startUrl"
981
981
  }));
982
982
  });
@@ -16,7 +16,7 @@ var _constants = require("../../../common/constants");
16
16
  var _tsNodeImport = require("../../common/tsNodeImport");
17
17
  var _terminal = require("../helpers/terminal");
18
18
  var _browser = require("../helpers/browser");
19
- var _playwrightContext = require("../../../common/playwrightContext");
19
+ var _launchBrowser = require("../../../common/launchBrowser");
20
20
  var _promises = require("timers/promises");
21
21
  var _contextStorageStateHelpers = require("../../../common/contextStorageStateHelpers");
22
22
  async function executeRunValidateAuthSessionCLI({
@@ -382,7 +382,7 @@ async function recordAuthSession({
382
382
  const {
383
383
  context,
384
384
  page
385
- } = await (0, _playwrightContext.launchChromium)({
385
+ } = await (0, _launchBrowser.launchChromium)({
386
386
  headless: false,
387
387
  proxy,
388
388
  appModeInitialUrl: startUrl
@@ -152,32 +152,6 @@ const validateIntunedProject = async () => {
152
152
  };
153
153
  }
154
154
  }
155
- }, {
156
- name: "package.json",
157
- check: async () => {
158
- try {
159
- const packageJsonPath = path.join(currentDirectoryToSave, "package.json");
160
- await fs.exists(packageJsonPath);
161
- const packageJson = JSON.parse(await fs.readFile(packageJsonPath, {
162
- encoding: "utf-8"
163
- }));
164
- const userCodePlaywrightVersion = packageJson.dependencies?.playwright;
165
- if (userCodePlaywrightVersion !== _constants.CURRENT_PLAYWRIGHT_VERSION) {
166
- return {
167
- isValid: false,
168
- errorMessage: `Playwright version mismatch: expected ${_constants.CURRENT_PLAYWRIGHT_VERSION}, found ${userCodePlaywrightVersion || "none"}`
169
- };
170
- }
171
- return {
172
- isValid: true
173
- };
174
- } catch (error) {
175
- return {
176
- isValid: false,
177
- errorMessage: "Package.json file not found or cannot be read"
178
- };
179
- }
180
- }
181
155
  }, {
182
156
  name: intunedSettingsFile.name,
183
157
  check: async () => {
@@ -2,7 +2,7 @@
2
2
 
3
3
  var _vitest = require("vitest");
4
4
  var _browser = require("../browser");
5
- var _playwrightContext = require("../../../../common/playwrightContext");
5
+ var _launchBrowser = require("../../../../common/launchBrowser");
6
6
  function getTerminal() {
7
7
  return new Proxy(() => ({}), {
8
8
  get: () => getTerminal(),
@@ -15,7 +15,7 @@ _vitest.vi.mock("fs-extra", () => ({
15
15
  _vitest.vi.mock("portfinder", () => ({
16
16
  getPort: _vitest.vi.fn().mockResolvedValue(1234)
17
17
  }));
18
- _vitest.vi.mock("../../../../common/playwrightContext", () => ({
18
+ _vitest.vi.mock("../../../../common/launchBrowser", () => ({
19
19
  launchChromium: _vitest.vi.fn().mockImplementation(async () => ({
20
20
  context: {
21
21
  close: _vitest.vi.fn().mockResolvedValue(undefined)
@@ -60,7 +60,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
60
60
  headless: false,
61
61
  proxy: "proxy"
62
62
  });
63
- (0, _vitest.expect)(_playwrightContext.launchChromium).toHaveBeenCalledWith({
63
+ (0, _vitest.expect)(_launchBrowser.launchChromium).toHaveBeenCalledWith({
64
64
  headless: false,
65
65
  cdpPort: 1234,
66
66
  proxy: "proxy"
@@ -78,7 +78,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
78
78
  });
79
79
  const firstContext = (0, _browser._getContextForTest)();
80
80
  (0, _vitest.expect)(firstContext).not.toBeNull();
81
- (0, _vitest.expect)(_playwrightContext.launchChromium).toHaveBeenCalledTimes(1);
81
+ (0, _vitest.expect)(_launchBrowser.launchChromium).toHaveBeenCalledTimes(1);
82
82
  await (0, _browser.getCLIRunOptions)({
83
83
  keepBrowserOpen: true,
84
84
  headless: false,
@@ -87,7 +87,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
87
87
  const secondContext = (0, _browser._getContextForTest)();
88
88
  (0, _vitest.expect)(secondContext).not.toBeNull();
89
89
  (0, _vitest.expect)(firstContext).not.toBe(secondContext);
90
- (0, _vitest.expect)(_playwrightContext.launchChromium).toHaveBeenCalledTimes(2);
90
+ (0, _vitest.expect)(_launchBrowser.launchChromium).toHaveBeenCalledTimes(2);
91
91
  });
92
92
  (0, _vitest.it)("keeps context open until explicitly closed", async () => {
93
93
  await (0, _browser.getCLIRunOptions)({
@@ -7,7 +7,7 @@ exports._getContextForTest = _getContextForTest;
7
7
  exports.closeCliBrowser = closeCliBrowser;
8
8
  exports.getCLIRunOptions = getCLIRunOptions;
9
9
  exports.isCliBrowserLaunched = isCliBrowserLaunched;
10
- var _playwrightContext = require("../../../common/playwrightContext");
10
+ var _launchBrowser = require("../../../common/launchBrowser");
11
11
  var _portfinder = require("portfinder");
12
12
  var _proxy = require("./proxy");
13
13
  let context = null;
@@ -35,7 +35,7 @@ async function getCLIRunOptions({
35
35
  const port = await (0, _portfinder.getPort)({});
36
36
  ({
37
37
  context
38
- } = await (0, _playwrightContext.launchChromium)({
38
+ } = await (0, _launchBrowser.launchChromium)({
39
39
  headless,
40
40
  proxy: proxy ? (0, _proxy.parseUrlProxy)(proxy) : undefined,
41
41
  cdpPort: port
@@ -1,15 +1,8 @@
1
1
  import * as playwright from "playwright";
2
- import { CaptchaSolverSettings } from "./settingsSchema";
3
- type CaptchaSolverSettingsWithRunContext = CaptchaSolverSettings & {
4
- workspaceId: string;
5
- projectId: string;
6
- baseUrl: string;
7
- token?: string;
8
- };
2
+ import { CaptchaSolverSettingsWithRunContext } from "./settingsSchema";
9
3
  export declare function buildExtensionsList(): string[];
10
4
  export declare function getIntunedExtensionPath(): string;
11
5
  export declare function isIntunedExtensionEnabled(): boolean;
12
6
  export declare function getIntunedExtensionWorker(context: playwright.BrowserContext): Promise<playwright.Worker | null>;
13
7
  export declare function getIntunedExtensionSettings(): Promise<CaptchaSolverSettingsWithRunContext>;
14
8
  export declare function setupIntunedExtension(): Promise<void>;
15
- export {};
@@ -56,18 +56,17 @@ async function getIntunedExtensionWorker(context) {
56
56
  }
57
57
  async function getIntunedExtensionSettings() {
58
58
  const settings = await (0, _settings.getSettings)();
59
- const captchaSolverSettings = settings.captchaSolver ?? _settingsSchema.captchaSolverSettingsSchema.parse({});
60
59
  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
60
  if (!domain || !workspaceId || !projectId) {
62
61
  const missingEnvVars = [domain && "FUNCTIONS_DOMAIN", workspaceId && _constants.WORKSPACE_ID_ENV_VAR_KEY, projectId && `INTUNED_INTEGRATION_ID OR ${_constants.PROJECT_ID_ENV_VAR_KEY}`];
63
62
  throw new Error(`Missing required environment variables: ${missingEnvVars}`);
64
63
  }
65
64
  return {
66
- ...captchaSolverSettings,
67
- baseUrl: domain,
68
- token: _jwtTokenManager.backendFunctionsTokenManager.token,
65
+ ...(settings.captchaSolver ?? _settingsSchema.captchaSolverSettingsSchema.parse({})),
69
66
  workspaceId,
70
- projectId
67
+ projectId,
68
+ baseUrl: domain,
69
+ token: _jwtTokenManager.backendFunctionsTokenManager.token
71
70
  };
72
71
  }
73
72
  async function setupIntunedExtension() {
@@ -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,27 +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
- appModeInitialUrl?: string;
17
- }): Promise<{
18
- page: playwright.Page;
19
- context: playwright.BrowserContext;
20
- }>;
21
- export declare function launchChromium(options: {
22
- cdpAddress: string;
23
- }): Promise<{
24
- page: playwright.Page;
25
- context: playwright.BrowserContext;
26
- }>;
6
+ import { type Proxy } from "./launchBrowser";
27
7
  export declare const browserScriptsFile: string;
28
8
  type WithPlaywrightContextParameters = {
29
9
  importFunction: ImportFunction;
@@ -48,8 +28,4 @@ export declare function loadSessionToContext({ context, session, }: {
48
28
  context: playwright.BrowserContext;
49
29
  session: RunApiSession;
50
30
  }): Promise<void>;
51
- export declare function getRemotePlaywrightContext(cdpAddress: string): Promise<{
52
- browser: playwright.Browser;
53
- context: playwright.BrowserContext;
54
- }>;
55
31
  export {};
@@ -4,116 +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
- var _extensionsHelpers = require("./extensionsHelpers");
23
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
+ var _launchBrowser = require("./launchBrowser");
24
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); }
25
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; }
26
- async function createUserDirWithPreferences() {
27
- const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
28
- const userDir = (0, _path.join)(playwrightTempDir, "userdir");
29
- const defaultDir = (0, _path.join)(userDir, "Default");
30
- await (0, _fsExtra.mkdir)(defaultDir, {
31
- recursive: true
32
- });
33
- const preferences = {
34
- plugins: {
35
- always_open_pdf_externally: true
36
- }
37
- };
38
- await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
39
- return userDir;
40
- }
41
- async function launchChromium({
42
- proxy,
43
- headless = true,
44
- downloadsPath,
45
- cdpAddress,
46
- cdpPort,
47
- appModeInitialUrl
48
- }) {
49
- if (cdpAddress) {
50
- const browser = await playwright.chromium.connectOverCDP(cdpAddress);
51
- if (browser.contexts().length === 0) {
52
- throw new Error("No browser contexts found in the connected browser");
53
- }
54
- const context = browser.contexts()[0];
55
- let page = context.pages().at(0);
56
- if (!page) {
57
- page = await context.newPage();
58
- }
59
- return {
60
- page,
61
- context
62
- };
63
- }
64
- const defaultArgsToIgnore = ["--disable-extensions", "--disable-component-extensions-with-background-pages", "--disable-background-networking", "--disable-backgrounding-occluded-windows", "--disable-background-timer-throttling"];
65
- const extraArgs = [];
66
- const userDataDir = await createUserDirWithPreferences();
67
- if ((0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
68
- const extensionsList = (0, _extensionsHelpers.buildExtensionsList)();
69
- const extensions = extensionsList.join(",");
70
- extraArgs.push(`--disable-extensions-except=${extensions}`);
71
- extraArgs.push(`--load-extension=${extensions}`);
72
- await (0, _extensionsHelpers.setupIntunedExtension)();
73
- }
74
- if (cdpPort) {
75
- extraArgs.push(`--remote-debugging-port=${cdpPort}`);
76
- }
77
- if (headless) {
78
- defaultArgsToIgnore.push("--headless=old");
79
- extraArgs.push("--headless=new");
80
- }
81
- if (appModeInitialUrl) {
82
- extraArgs.push(`--app=${appModeInitialUrl}`);
83
- }
84
- const context = await playwright.chromium.launchPersistentContext(userDataDir, {
85
- headless,
86
- viewport: null,
87
- proxy,
88
- downloadsPath,
89
- args: extraArgs,
90
- ignoreDefaultArgs: defaultArgsToIgnore
91
- });
92
- context.once("close", async () => {
93
- try {
94
- await (0, _fsExtra.rm)(userDataDir, {
95
- recursive: true,
96
- force: true,
97
- retryDelay: 1000,
98
- maxRetries: 5
99
- });
100
- } catch (error) {
101
- console.error("Failed to remove user data dir", error);
102
- }
103
- });
104
- if (cdpPort) {
105
- const createdCdpAddress = getLocalCdpAddress(cdpPort);
106
- await waitOnCdpAddress(createdCdpAddress);
107
- }
108
- const page = context.pages().at(0) ?? (await context.newPage());
109
- if ((0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
110
- await (0, _extensionsHelpers.getIntunedExtensionWorker)(context);
111
- }
112
- return {
113
- page,
114
- context
115
- };
116
- }
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
117
21
  const browserScriptsFile = exports.browserScriptsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
118
22
  async function withPlaywrightContext({
119
23
  cdpAddress,
@@ -139,14 +43,14 @@ async function withPlaywrightContext({
139
43
  ({
140
44
  page,
141
45
  context
142
- } = await launchChromium({
46
+ } = await (0, _launchBrowser.launchBrowser)({
143
47
  cdpAddress
144
48
  }));
145
49
  } else {
146
50
  ({
147
51
  page,
148
52
  context
149
- } = await launchChromium({
53
+ } = await (0, _launchBrowser.launchBrowser)({
150
54
  proxy,
151
55
  headless,
152
56
  downloadsPath
@@ -160,18 +64,18 @@ async function withPlaywrightContext({
160
64
  ({
161
65
  context,
162
66
  page
163
- } = await launchChromium({
67
+ } = await (0, _launchBrowser.launchBrowser)({
164
68
  cdpAddress
165
69
  }));
166
70
  } else {
167
71
  const port = await (0, _portfinder.getPort)({
168
72
  port: 9222
169
73
  });
170
- hookCdpUrl = getLocalCdpAddress(port);
74
+ hookCdpUrl = (0, _launchBrowser.getLocalCdpAddress)(port);
171
75
  ({
172
76
  context,
173
77
  page
174
- } = await launchChromium({
78
+ } = await (0, _launchBrowser.launchBrowser)({
175
79
  proxy,
176
80
  headless,
177
81
  downloadsPath,
@@ -237,42 +141,4 @@ async function loadSessionToContext({
237
141
  sessionToLoad = await fs.readJson(fullPath);
238
142
  }
239
143
  await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
240
- }
241
- function getLocalCdpAddress(port) {
242
- return `http://localhost:${port}`;
243
- }
244
- async function waitOnCdpAddress(cdpAddress) {
245
- const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
246
- await (0, _waitOn.default)({
247
- resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
248
- delay: 100,
249
- interval: 100,
250
- timeout: 5000,
251
- tcpTimeout: 1000,
252
- window: 1000
253
- });
254
- }
255
- async function getRemotePlaywrightContext(cdpAddress) {
256
- const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright")));
257
- let browser = null;
258
- if (!cdpAddress) {
259
- throw new Error("cdpAddress is required");
260
- }
261
- try {
262
- await waitOnCdpAddress(cdpAddress);
263
- } catch (error) {
264
- console.error("Failed to connect to the browser");
265
- process.exit(128 + 9);
266
- }
267
- try {
268
- browser = await playwright.chromium.connectOverCDP(cdpAddress);
269
- } catch (e) {
270
- console.log(e);
271
- throw new Error("failed to connect to the browser");
272
- }
273
- const context = browser.contexts()[0];
274
- return {
275
- browser,
276
- context
277
- };
278
144
  }
@@ -1,10 +1,6 @@
1
1
  import * as z from "zod";
2
2
  export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
3
3
  enabled: z.ZodDefault<z.ZodBoolean>;
4
- workspaceId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
5
- projectId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
6
- baseUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
7
- token: z.ZodNullable<z.ZodOptional<z.ZodString>>;
8
4
  cloudflare: z.ZodOptional<z.ZodObject<{
9
5
  enabled: z.ZodBoolean;
10
6
  }, "strip", z.ZodTypeAny, {
@@ -93,7 +89,7 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
93
89
  inputLocators: string[];
94
90
  labelLocators: string[];
95
91
  }>>;
96
- settings: z.ZodDefault<z.ZodOptional<z.ZodObject<{
92
+ settings: z.ZodDefault<z.ZodObject<{
97
93
  autoSolve: z.ZodDefault<z.ZodBoolean>;
98
94
  solveDelay: z.ZodDefault<z.ZodNumber>;
99
95
  maxRetries: z.ZodDefault<z.ZodNumber>;
@@ -108,7 +104,7 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
108
104
  solveDelay?: number | undefined;
109
105
  maxRetries?: number | undefined;
110
106
  timeout?: number | undefined;
111
- }>>>;
107
+ }>>;
112
108
  }, "strip", z.ZodTypeAny, {
113
109
  enabled: boolean;
114
110
  settings: {
@@ -117,10 +113,6 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
117
113
  maxRetries: number;
118
114
  timeout: number;
119
115
  };
120
- workspaceId?: string | null | undefined;
121
- projectId?: string | null | undefined;
122
- baseUrl?: string | null | undefined;
123
- token?: string | null | undefined;
124
116
  cloudflare?: {
125
117
  enabled: boolean;
126
118
  } | undefined;
@@ -159,10 +151,6 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
159
151
  } | undefined;
160
152
  }, {
161
153
  enabled?: boolean | undefined;
162
- workspaceId?: string | null | undefined;
163
- projectId?: string | null | undefined;
164
- baseUrl?: string | null | undefined;
165
- token?: string | null | undefined;
166
154
  cloudflare?: {
167
155
  enabled: boolean;
168
156
  } | undefined;
@@ -206,7 +194,12 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
206
194
  timeout?: number | undefined;
207
195
  } | undefined;
208
196
  }>>;
209
- export type CaptchaSolverSettings = z.infer<typeof captchaSolverSettingsSchema>;
197
+ export type CaptchaSolverSettingsWithRunContext = z.infer<typeof captchaSolverSettingsSchema> & {
198
+ workspaceId: string;
199
+ projectId: string;
200
+ baseUrl: string;
201
+ token?: string;
202
+ };
210
203
  export declare const settingsSchema: z.ZodObject<{
211
204
  authSessions: z.ZodDefault<z.ZodOptional<z.ZodObject<{
212
205
  enabled: z.ZodBoolean;
@@ -217,10 +210,6 @@ export declare const settingsSchema: z.ZodObject<{
217
210
  }>>>;
218
211
  captchaSolver: z.ZodOptional<z.ZodDefault<z.ZodObject<{
219
212
  enabled: z.ZodDefault<z.ZodBoolean>;
220
- workspaceId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
221
- projectId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
222
- baseUrl: z.ZodNullable<z.ZodOptional<z.ZodString>>;
223
- token: z.ZodNullable<z.ZodOptional<z.ZodString>>;
224
213
  cloudflare: z.ZodOptional<z.ZodObject<{
225
214
  enabled: z.ZodBoolean;
226
215
  }, "strip", z.ZodTypeAny, {
@@ -309,7 +298,7 @@ export declare const settingsSchema: z.ZodObject<{
309
298
  inputLocators: string[];
310
299
  labelLocators: string[];
311
300
  }>>;
312
- settings: z.ZodDefault<z.ZodOptional<z.ZodObject<{
301
+ settings: z.ZodDefault<z.ZodObject<{
313
302
  autoSolve: z.ZodDefault<z.ZodBoolean>;
314
303
  solveDelay: z.ZodDefault<z.ZodNumber>;
315
304
  maxRetries: z.ZodDefault<z.ZodNumber>;
@@ -324,7 +313,7 @@ export declare const settingsSchema: z.ZodObject<{
324
313
  solveDelay?: number | undefined;
325
314
  maxRetries?: number | undefined;
326
315
  timeout?: number | undefined;
327
- }>>>;
316
+ }>>;
328
317
  }, "strip", z.ZodTypeAny, {
329
318
  enabled: boolean;
330
319
  settings: {
@@ -333,10 +322,6 @@ export declare const settingsSchema: z.ZodObject<{
333
322
  maxRetries: number;
334
323
  timeout: number;
335
324
  };
336
- workspaceId?: string | null | undefined;
337
- projectId?: string | null | undefined;
338
- baseUrl?: string | null | undefined;
339
- token?: string | null | undefined;
340
325
  cloudflare?: {
341
326
  enabled: boolean;
342
327
  } | undefined;
@@ -375,10 +360,6 @@ export declare const settingsSchema: z.ZodObject<{
375
360
  } | undefined;
376
361
  }, {
377
362
  enabled?: boolean | undefined;
378
- workspaceId?: string | null | undefined;
379
- projectId?: string | null | undefined;
380
- baseUrl?: string | null | undefined;
381
- token?: string | null | undefined;
382
363
  cloudflare?: {
383
364
  enabled: boolean;
384
365
  } | undefined;
@@ -434,10 +415,6 @@ export declare const settingsSchema: z.ZodObject<{
434
415
  maxRetries: number;
435
416
  timeout: number;
436
417
  };
437
- workspaceId?: string | null | undefined;
438
- projectId?: string | null | undefined;
439
- baseUrl?: string | null | undefined;
440
- token?: string | null | undefined;
441
418
  cloudflare?: {
442
419
  enabled: boolean;
443
420
  } | undefined;
@@ -481,10 +458,6 @@ export declare const settingsSchema: z.ZodObject<{
481
458
  } | undefined;
482
459
  captchaSolver?: {
483
460
  enabled?: boolean | undefined;
484
- workspaceId?: string | null | undefined;
485
- projectId?: string | null | undefined;
486
- baseUrl?: string | null | undefined;
487
- token?: string | null | undefined;
488
461
  cloudflare?: {
489
462
  enabled: boolean;
490
463
  } | undefined;
@@ -28,10 +28,6 @@ const captchaSolverSolveSettingsSchema = z.object({
28
28
  });
29
29
  const captchaSolverSettingsSchema = exports.captchaSolverSettingsSchema = z.object({
30
30
  enabled: z.boolean().default(false),
31
- workspaceId: z.string().optional().nullable(),
32
- projectId: z.string().optional().nullable(),
33
- baseUrl: z.string().optional().nullable(),
34
- token: z.string().optional().nullable(),
35
31
  cloudflare: baseCaptchaSchema.optional(),
36
32
  googleRecaptchaV2: baseCaptchaSchema.optional(),
37
33
  googleRecaptchaV3: baseCaptchaSchema.optional(),
@@ -42,7 +38,7 @@ const captchaSolverSettingsSchema = exports.captchaSolverSettingsSchema = z.obje
42
38
  lemin: baseCaptchaSchema.optional(),
43
39
  customCaptcha: customCaptchaSchema.optional(),
44
40
  text: textCaptchaSchema.optional(),
45
- settings: captchaSolverSolveSettingsSchema.optional().default({})
41
+ settings: captchaSolverSolveSettingsSchema.default(captchaSolverSolveSettingsSchema.parse({}))
46
42
  }).default({});
47
43
  const authSessionsSchema = z.object({
48
44
  enabled: z.boolean()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
package/WebTemplate.zip DELETED
Binary file