@intuned/runtime-dev 1.3.6-brave.4 → 1.3.8-deploy.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/auth-sessions/load.js +12 -9
- package/dist/commands/intuned-cli/commands/attempt_api.command.js +1 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +1 -1
- package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +1 -1
- package/dist/commands/intuned-cli/commands/authsession_record.command.js +3 -2
- package/dist/commands/intuned-cli/commands/run_api.command.js +1 -1
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +5 -5
- package/dist/commands/intuned-cli/controller/authSession.js +2 -2
- package/dist/commands/intuned-cli/controller/deploy.js +76 -5
- package/dist/commands/intuned-cli/controller/save.d.ts +4 -1
- package/dist/commands/intuned-cli/controller/save.js +5 -1
- package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +5 -5
- package/dist/commands/intuned-cli/helpers/browser.js +2 -2
- package/dist/common/extensionsHelpers.d.ts +1 -8
- package/dist/common/extensionsHelpers.js +4 -5
- package/dist/common/launchBrowser.d.ts +25 -0
- package/dist/common/launchBrowser.js +172 -0
- package/dist/common/playwrightContext.d.ts +1 -26
- package/dist/common/playwrightContext.js +11 -171
- package/dist/common/settingsSchema.d.ts +10 -37
- package/dist/common/settingsSchema.js +1 -5
- package/package.json +1 -2
|
@@ -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
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
});
|
|
@@ -15,7 +15,7 @@ const optionsSchema = _types.baseCommandOptionsSchema.extend({
|
|
|
15
15
|
authSession: _zod.z.string().optional(),
|
|
16
16
|
outputFile: _zod.z.string().optional()
|
|
17
17
|
});
|
|
18
|
-
const attemptApiCommand = exports.attemptApiCommand = (0, _types.withBaseOptions)(_attempt.attemptCommand.command("api").description("Execute an Intuned API attempt with parameters").argument("<api-name>", "Name of the API to run").argument("<parameters>", "Path to the JSON file containing API parameters OR the parameters as a JSON string").option("-a, --auth-session <id>", "ID of the auth session to use for the API. This is expected to be in ./auth-
|
|
18
|
+
const attemptApiCommand = exports.attemptApiCommand = (0, _types.withBaseOptions)(_attempt.attemptCommand.command("api").description("Execute an Intuned API attempt with parameters").argument("<api-name>", "Name of the API to run").argument("<parameters>", "Path to the JSON file containing API parameters OR the parameters as a JSON string").option("-a, --auth-session <id>", "ID of the auth session to use for the API. This is expected to be in ./auth-sessions-instances/<id>.json").option("-o, --output-file <path>", "output file path")).action((0, _helpers.cliCommandWrapper)(argsSchema, optionsSchema, async ([apiName, parameters], {
|
|
19
19
|
authSession,
|
|
20
20
|
...rest
|
|
21
21
|
}) => {
|
|
@@ -14,7 +14,7 @@ const argsSchema = _zod.z.tuple([_zod.z.string().min(1, "Parameters are required
|
|
|
14
14
|
const optionsSchema = _types.baseCommandOptionsSchema.extend({
|
|
15
15
|
id: _zod.z.string().optional()
|
|
16
16
|
});
|
|
17
|
-
const attemptAuthSessionCreateCommand = exports.attemptAuthSessionCreateCommand = (0, _types.withBaseOptions)(_attempt_authsession.attemptAuthSessionCommand.command("create").description("Create a new auth session").argument("<parameters>", "Parameters for the auth session command").option("--id <id>", "ID of the auth session to use for the command. Defaults to ./auth-
|
|
17
|
+
const attemptAuthSessionCreateCommand = exports.attemptAuthSessionCreateCommand = (0, _types.withBaseOptions)(_attempt_authsession.attemptAuthSessionCommand.command("create").description("Create a new auth session").argument("<parameters>", "Parameters for the auth session command").option("--id <id>", "ID of the auth session to use for the command. Defaults to ./auth-sessions-instances/[current timestamp].json")).action((0, _helpers.cliCommandWrapper)(argsSchema, optionsSchema, async ([parameters], options) => {
|
|
18
18
|
await (0, _helpers.assertAuthEnabled)();
|
|
19
19
|
const authSessionInput = (await (0, _controller.loadParameters)(parameters)) ?? {};
|
|
20
20
|
await (0, _authSession.executeAttemptCreateAuthSessionCLI)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const authSessionRecordCommand: import("commander").Command;
|
|
1
|
+
export declare const authSessionRecordCommand: import("commander").Command | null;
|
|
@@ -13,7 +13,8 @@ var _types = require("./types");
|
|
|
13
13
|
const optionsSchema = _run_authsession.baseRunAuthSessionCommandOptionsSchema.extend({
|
|
14
14
|
id: _zod.z.string().optional()
|
|
15
15
|
});
|
|
16
|
-
const
|
|
16
|
+
const isAuthSessionRecorderEnabled = process.env.INTUNED_AUTH_SESSION_RECORDER_ENABLED === "true";
|
|
17
|
+
const authSessionRecordCommand = exports.authSessionRecordCommand = isAuthSessionRecorderEnabled ? (0, _types.withBaseOptions)(_authsession.authSessionCommand.command("record").description("Record a new auth session").option("--id <id>", "ID of the auth session to use for the command. Defaults to auth-session-[current timestamp]").option("--check-attempts <number>", "Number of attempts to check the auth session validity", "1")).action((0, _helpers.cliCommandWrapper)(undefined, optionsSchema, async (_, {
|
|
17
18
|
checkAttempts,
|
|
18
19
|
...rest
|
|
19
20
|
}) => {
|
|
@@ -28,4 +29,4 @@ const authSessionRecordCommand = exports.authSessionRecordCommand = (0, _types.w
|
|
|
28
29
|
finishUrl,
|
|
29
30
|
...rest
|
|
30
31
|
});
|
|
31
|
-
}));
|
|
32
|
+
})) : null;
|
|
@@ -19,7 +19,7 @@ const optionsSchema = _types.baseCommandOptionsSchema.extend({
|
|
|
19
19
|
authSessionCheckAttempts: _types.authSessionCheckAttemptsSchema,
|
|
20
20
|
authSessionCreateAttempts: _types.authSessionCreateAttemptsSchema
|
|
21
21
|
});
|
|
22
|
-
const runApiCommand = exports.runApiCommand = (0, _types.withBaseOptions)(_run.runCommand.command("api").description("Execute an Intuned API run with parameters").argument("<api-name>", "Name of the API to run").argument("<parameters>", "Path to the JSON file containing API parameters OR the parameters as a JSON string").option("-a, --auth-session <id>", "ID of the auth session to use for the API. This is expected to be in ./auth-
|
|
22
|
+
const runApiCommand = exports.runApiCommand = (0, _types.withBaseOptions)(_run.runCommand.command("api").description("Execute an Intuned API run with parameters").argument("<api-name>", "Name of the API to run").argument("<parameters>", "Path to the JSON file containing API parameters OR the parameters as a JSON string").option("-a, --auth-session <id>", "ID of the auth session to use for the API. This is expected to be in ./auth-sessions-instances/<id>").option("--retries <number>", "Number of retries for the API call", "1").option("--no-auth-session-auto-recreate", "disable auto recreate for auth session").option("--auth-session-check-attempts <number>", "auth session check attempts", "1").option("--auth-session-create-attempts <number>", "auth session create attempts", "1").option("-o, --output-file <path>", "output file path")).action((0, _helpers.cliCommandWrapper)(argsSchema, optionsSchema, async ([apiName, parameters], {
|
|
23
23
|
retries,
|
|
24
24
|
outputFile,
|
|
25
25
|
authSession,
|
|
@@ -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
|
|
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/
|
|
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(
|
|
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(
|
|
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)(
|
|
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
|
|
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,
|
|
385
|
+
} = await (0, _launchBrowser.launchChromium)({
|
|
386
386
|
headless: false,
|
|
387
387
|
proxy,
|
|
388
388
|
appModeInitialUrl: startUrl
|
|
@@ -13,9 +13,18 @@ var _promises = require("timers/promises");
|
|
|
13
13
|
var _ms = _interopRequireDefault(require("ms"));
|
|
14
14
|
var _save = require("./save");
|
|
15
15
|
var _constants2 = require("../../../common/constants");
|
|
16
|
+
var _path = _interopRequireDefault(require("path"));
|
|
17
|
+
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
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; }
|
|
16
20
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
21
|
async function runDeployProject(projectName, auth) {
|
|
18
|
-
await (0, _save.runSaveProject)(projectName, auth);
|
|
22
|
+
const result = await (0, _save.runSaveProject)(projectName, auth);
|
|
23
|
+
const state = result?.state ?? "not-deployed";
|
|
24
|
+
let firstRun = undefined;
|
|
25
|
+
if (state === "not-deployed") {
|
|
26
|
+
firstRun = await handleFirstRunExperience();
|
|
27
|
+
}
|
|
19
28
|
const {
|
|
20
29
|
workspaceId,
|
|
21
30
|
apiKey
|
|
@@ -28,7 +37,10 @@ async function runDeployProject(projectName, auth) {
|
|
|
28
37
|
};
|
|
29
38
|
const response = await fetch(url, {
|
|
30
39
|
headers,
|
|
31
|
-
method: "POST"
|
|
40
|
+
method: "POST",
|
|
41
|
+
body: JSON.stringify({
|
|
42
|
+
firstRun: firstRun
|
|
43
|
+
})
|
|
32
44
|
});
|
|
33
45
|
if (!response.ok) {
|
|
34
46
|
if (response.status === 401) {
|
|
@@ -85,8 +97,12 @@ async function runDeployProject(projectName, auth) {
|
|
|
85
97
|
}
|
|
86
98
|
if (status === "completed") {
|
|
87
99
|
const url = (0, _helpers.getBaseUrl)();
|
|
100
|
+
const projectUrl = `${url}/projects/${projectId}`;
|
|
88
101
|
(0, _terminal.terminal)(`\n^g^+Project deployed successfully!^:\n`);
|
|
89
|
-
(0, _terminal.terminal)(`^+
|
|
102
|
+
(0, _terminal.terminal)(`^+View project:^s ^c^_${projectUrl}/runs^:\n`);
|
|
103
|
+
(0, _terminal.terminal)(`^+Run playground:^s ^c^_${projectUrl}/runs?playground=open^:\n`);
|
|
104
|
+
(0, _terminal.terminal)(`^+Manage jobs:^s ^c^_${projectUrl}/jobs^:\n`);
|
|
105
|
+
(0, _terminal.terminal)(`^+Trigger default job:^s ^c^_${projectUrl}/jobs/default?action=trigger^:\n`);
|
|
90
106
|
return;
|
|
91
107
|
}
|
|
92
108
|
let errorMessage = `^r^+An error occurred while deploying project:^:\n^R${message}^:\n`;
|
|
@@ -105,7 +121,7 @@ async function runDeployProject(projectName, auth) {
|
|
|
105
121
|
throw e;
|
|
106
122
|
}
|
|
107
123
|
}
|
|
108
|
-
const projectNameSchema = exports.projectNameSchema = _zod.z.string().min(1, "Project Name is required").max(
|
|
124
|
+
const projectNameSchema = exports.projectNameSchema = _zod.z.string().min(1, "Project Name is required").max(200, "Name must be 200 characters or less").regex(/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/, "Name can only contain lowercase letters, numbers, hyphens, and underscores in between").refine(value => !_zod.z.string().uuid().safeParse(value).success, {
|
|
109
125
|
message: "Name cannot be a UUID"
|
|
110
126
|
});
|
|
111
127
|
const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey) => {
|
|
@@ -136,4 +152,59 @@ const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey)
|
|
|
136
152
|
status: "failed",
|
|
137
153
|
message: `Deployment failed, please try again: ${data.message}`
|
|
138
154
|
};
|
|
139
|
-
};
|
|
155
|
+
};
|
|
156
|
+
{}
|
|
157
|
+
async function handleFirstRunExperience() {
|
|
158
|
+
let testAuthSessionInput = null;
|
|
159
|
+
const settings = await (0, _helpers.loadIntunedJson)();
|
|
160
|
+
const shouldPromptForTestAuthSession = settings.authSessions.enabled && settings.authSessions.type === "API";
|
|
161
|
+
let shouldPromptForDefaultJob = true;
|
|
162
|
+
if (shouldPromptForTestAuthSession) {
|
|
163
|
+
testAuthSessionInput = getFirstRunExperienceTestAuthSessionParameters({
|
|
164
|
+
shouldPromptForDefaultJob
|
|
165
|
+
});
|
|
166
|
+
if (!testAuthSessionInput) {
|
|
167
|
+
shouldPromptForDefaultJob = false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
testAuthSessionInput,
|
|
172
|
+
defaultJobInput: shouldPromptForDefaultJob ? getFirstRunExperienceDefaultJobParameters(settings["metadata"].defaultJobInput) : undefined
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
async function getFirstRunExperienceTestAuthSessionParameters({
|
|
176
|
+
shouldPromptForDefaultJob
|
|
177
|
+
}) {
|
|
178
|
+
const authSessionsDirectoryPath = _path.default.join(process.cwd(), _constants2.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
|
|
179
|
+
const authSessionId = (await fs.readdir(authSessionsDirectoryPath)).shift();
|
|
180
|
+
if (authSessionId) {
|
|
181
|
+
const {
|
|
182
|
+
metadata
|
|
183
|
+
} = await (0, _helpers.loadAuthSessionInstance)(authSessionId);
|
|
184
|
+
if (metadata.authSessionInput) {
|
|
185
|
+
const message = shouldPromptForDefaultJob ? "\n^cCreate a test auth session using ^:^+%s^:^c's parameters? (required for creating default job)^ " : "\n^cCreate a test auth session using ^:^+%s^:^c's parameters?^ ";
|
|
186
|
+
(0, _terminal.terminal)(message, authSessionId);
|
|
187
|
+
const answer = await _terminal.terminal.yesOrNo({
|
|
188
|
+
yes: ["y", "ENTER"],
|
|
189
|
+
no: ["n"]
|
|
190
|
+
}).promise;
|
|
191
|
+
(0, _terminal.terminal)("\n");
|
|
192
|
+
if (answer) {
|
|
193
|
+
return metadata.authSessionInput;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async function getFirstRunExperienceDefaultJobParameters({
|
|
199
|
+
defaultJobInput
|
|
200
|
+
}) {
|
|
201
|
+
(0, _terminal.terminal)("\n^cCreate a default job?^");
|
|
202
|
+
const answer = await _terminal.terminal.yesOrNo({
|
|
203
|
+
yes: ["y", "ENTER"],
|
|
204
|
+
no: ["n"]
|
|
205
|
+
}).promise;
|
|
206
|
+
(0, _terminal.terminal)("\n");
|
|
207
|
+
if (answer) {
|
|
208
|
+
return defaultJobInput;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { AuthCredentials } from "../types";
|
|
3
|
-
export declare function runSaveProject(projectName: string, auth: AuthCredentials): Promise<
|
|
3
|
+
export declare function runSaveProject(projectName: string, auth: AuthCredentials): Promise<{
|
|
4
|
+
projectId: string;
|
|
5
|
+
state: string;
|
|
6
|
+
} | undefined>;
|
|
4
7
|
export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
5
8
|
export declare const validateProjectName: (projectName: string) => {
|
|
6
9
|
isValid: true;
|
|
@@ -111,8 +111,12 @@ ${_constants2.API_KEY_ENV_VAR_KEY}=${apiKey}`);
|
|
|
111
111
|
await fs.appendFile(dotEnvPath, contentToAppend + "\n");
|
|
112
112
|
(0, _terminal.terminal)(`^g^+Updated .env file with project credentials.^:\n`);
|
|
113
113
|
}
|
|
114
|
+
return {
|
|
115
|
+
projectId,
|
|
116
|
+
state: "not-deployed"
|
|
117
|
+
};
|
|
114
118
|
}
|
|
115
|
-
const projectNameSchema = exports.projectNameSchema = _zod.z.string().min(1, "Project Name is required").max(
|
|
119
|
+
const projectNameSchema = exports.projectNameSchema = _zod.z.string().min(1, "Project Name is required").max(200, "Name must be 200 characters or less").regex(/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/, "Name can only contain lowercase letters, numbers, hyphens, and underscores in between").refine(value => !_zod.z.string().uuid().safeParse(value).success, {
|
|
116
120
|
message: "Name cannot be a UUID"
|
|
117
121
|
});
|
|
118
122
|
const validateProjectName = projectName => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var _vitest = require("vitest");
|
|
4
4
|
var _browser = require("../browser");
|
|
5
|
-
var
|
|
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/
|
|
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)(
|
|
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)(
|
|
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)(
|
|
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
|
|
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,
|
|
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 {
|
|
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
|
-
...
|
|
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,28 +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
|
-
|
|
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
|
-
executablePath?: string;
|
|
18
|
-
}): Promise<{
|
|
19
|
-
page: playwright.Page;
|
|
20
|
-
context: playwright.BrowserContext;
|
|
21
|
-
}>;
|
|
22
|
-
export declare function launchChromium(options: {
|
|
23
|
-
cdpAddress: string;
|
|
24
|
-
}): Promise<{
|
|
25
|
-
page: playwright.Page;
|
|
26
|
-
context: playwright.BrowserContext;
|
|
27
|
-
}>;
|
|
6
|
+
import { type Proxy } from "./launchBrowser";
|
|
28
7
|
export declare const browserScriptsFile: string;
|
|
29
8
|
type WithPlaywrightContextParameters = {
|
|
30
9
|
importFunction: ImportFunction;
|
|
@@ -49,8 +28,4 @@ export declare function loadSessionToContext({ context, session, }: {
|
|
|
49
28
|
context: playwright.BrowserContext;
|
|
50
29
|
session: RunApiSession;
|
|
51
30
|
}): Promise<void>;
|
|
52
|
-
export declare function getRemotePlaywrightContext(cdpAddress: string): Promise<{
|
|
53
|
-
browser: playwright.Browser;
|
|
54
|
-
context: playwright.BrowserContext;
|
|
55
|
-
}>;
|
|
56
31
|
export {};
|
|
@@ -4,129 +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 =
|
|
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
|
-
var _child_process = require("child_process");
|
|
22
16
|
var _portfinder = require("portfinder");
|
|
23
|
-
var
|
|
24
|
-
var _util = require("util");
|
|
25
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
var _launchBrowser = require("./launchBrowser");
|
|
26
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); }
|
|
27
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; }
|
|
28
|
-
|
|
29
|
-
async function createUserDirWithPreferences() {
|
|
30
|
-
const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
|
|
31
|
-
const userDir = (0, _path.join)(playwrightTempDir, "userdir");
|
|
32
|
-
const defaultDir = (0, _path.join)(userDir, "Default");
|
|
33
|
-
await (0, _fsExtra.mkdir)(defaultDir, {
|
|
34
|
-
recursive: true
|
|
35
|
-
});
|
|
36
|
-
const preferences = {
|
|
37
|
-
plugins: {
|
|
38
|
-
always_open_pdf_externally: true
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
|
|
42
|
-
return userDir;
|
|
43
|
-
}
|
|
44
|
-
async function launchChromium({
|
|
45
|
-
proxy,
|
|
46
|
-
headless = true,
|
|
47
|
-
downloadsPath,
|
|
48
|
-
cdpAddress,
|
|
49
|
-
cdpPort,
|
|
50
|
-
appModeInitialUrl,
|
|
51
|
-
executablePath
|
|
52
|
-
}) {
|
|
53
|
-
if (cdpAddress) {
|
|
54
|
-
const browser = await playwright.chromium.connectOverCDP(cdpAddress);
|
|
55
|
-
if (browser.contexts().length === 0) {
|
|
56
|
-
throw new Error("No browser contexts found in the connected browser");
|
|
57
|
-
}
|
|
58
|
-
const context = browser.contexts()[0];
|
|
59
|
-
let page = context.pages().at(0);
|
|
60
|
-
if (!page) {
|
|
61
|
-
page = await context.newPage();
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
page,
|
|
65
|
-
context
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
const defaultArgsToIgnore = ["--disable-extensions", "--disable-component-extensions-with-background-pages", "--disable-background-networking", "--disable-backgrounding-occluded-windows", "--disable-background-timer-throttling"];
|
|
69
|
-
const extraArgs = [];
|
|
70
|
-
const userDataDir = await createUserDirWithPreferences();
|
|
71
|
-
if ((0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
72
|
-
const extensionsList = (0, _extensionsHelpers.buildExtensionsList)();
|
|
73
|
-
const extensions = extensionsList.join(",");
|
|
74
|
-
extraArgs.push(`--disable-extensions-except=${extensions}`);
|
|
75
|
-
extraArgs.push(`--load-extension=${extensions}`);
|
|
76
|
-
await (0, _extensionsHelpers.setupIntunedExtension)();
|
|
77
|
-
}
|
|
78
|
-
if (cdpPort) {
|
|
79
|
-
extraArgs.push(`--remote-debugging-port=${cdpPort}`);
|
|
80
|
-
}
|
|
81
|
-
if (headless) {
|
|
82
|
-
defaultArgsToIgnore.push("--headless=old");
|
|
83
|
-
extraArgs.push("--headless=new");
|
|
84
|
-
}
|
|
85
|
-
if (appModeInitialUrl) {
|
|
86
|
-
extraArgs.push(`--app=${appModeInitialUrl}`);
|
|
87
|
-
}
|
|
88
|
-
if (executablePath) {
|
|
89
|
-
console.log("Using custom executable path:", executablePath);
|
|
90
|
-
executablePath = await fs.realpath(executablePath);
|
|
91
|
-
if (!(await fs.exists(executablePath))) {
|
|
92
|
-
console.log(`Warning: Executable path ${executablePath} does not exist. Falling back to default.`);
|
|
93
|
-
executablePath = undefined;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const context = await playwright.chromium.launchPersistentContext(userDataDir, {
|
|
97
|
-
executablePath,
|
|
98
|
-
headless,
|
|
99
|
-
viewport: null,
|
|
100
|
-
proxy,
|
|
101
|
-
downloadsPath,
|
|
102
|
-
args: extraArgs,
|
|
103
|
-
ignoreDefaultArgs: defaultArgsToIgnore
|
|
104
|
-
});
|
|
105
|
-
context.once("close", async () => {
|
|
106
|
-
try {
|
|
107
|
-
await (0, _fsExtra.rm)(userDataDir, {
|
|
108
|
-
recursive: true,
|
|
109
|
-
force: true,
|
|
110
|
-
retryDelay: 1000,
|
|
111
|
-
maxRetries: 5
|
|
112
|
-
});
|
|
113
|
-
} catch (error) {
|
|
114
|
-
console.error("Failed to remove user data dir", error);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
if (cdpPort) {
|
|
118
|
-
const createdCdpAddress = getLocalCdpAddress(cdpPort);
|
|
119
|
-
await waitOnCdpAddress(createdCdpAddress);
|
|
120
|
-
}
|
|
121
|
-
const page = context.pages().at(0) ?? (await context.newPage());
|
|
122
|
-
if ((0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
123
|
-
await (0, _extensionsHelpers.getIntunedExtensionWorker)(context);
|
|
124
|
-
}
|
|
125
|
-
return {
|
|
126
|
-
page,
|
|
127
|
-
context
|
|
128
|
-
};
|
|
129
|
-
}
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
130
21
|
const browserScriptsFile = exports.browserScriptsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
|
|
131
22
|
async function withPlaywrightContext({
|
|
132
23
|
cdpAddress,
|
|
@@ -152,18 +43,17 @@ async function withPlaywrightContext({
|
|
|
152
43
|
({
|
|
153
44
|
page,
|
|
154
45
|
context
|
|
155
|
-
} = await
|
|
46
|
+
} = await (0, _launchBrowser.launchBrowser)({
|
|
156
47
|
cdpAddress
|
|
157
48
|
}));
|
|
158
49
|
} else {
|
|
159
50
|
({
|
|
160
51
|
page,
|
|
161
52
|
context
|
|
162
|
-
} = await
|
|
53
|
+
} = await (0, _launchBrowser.launchBrowser)({
|
|
163
54
|
proxy,
|
|
164
55
|
headless,
|
|
165
|
-
downloadsPath
|
|
166
|
-
executablePath: await getExecutablePath()
|
|
56
|
+
downloadsPath
|
|
167
57
|
}));
|
|
168
58
|
}
|
|
169
59
|
return await fn(context, page);
|
|
@@ -174,23 +64,22 @@ async function withPlaywrightContext({
|
|
|
174
64
|
({
|
|
175
65
|
context,
|
|
176
66
|
page
|
|
177
|
-
} = await
|
|
67
|
+
} = await (0, _launchBrowser.launchBrowser)({
|
|
178
68
|
cdpAddress
|
|
179
69
|
}));
|
|
180
70
|
} else {
|
|
181
71
|
const port = await (0, _portfinder.getPort)({
|
|
182
72
|
port: 9222
|
|
183
73
|
});
|
|
184
|
-
hookCdpUrl = getLocalCdpAddress(port);
|
|
74
|
+
hookCdpUrl = (0, _launchBrowser.getLocalCdpAddress)(port);
|
|
185
75
|
({
|
|
186
76
|
context,
|
|
187
77
|
page
|
|
188
|
-
} = await
|
|
78
|
+
} = await (0, _launchBrowser.launchBrowser)({
|
|
189
79
|
proxy,
|
|
190
80
|
headless,
|
|
191
81
|
downloadsPath,
|
|
192
|
-
cdpPort: port
|
|
193
|
-
executablePath: await getExecutablePath()
|
|
82
|
+
cdpPort: port
|
|
194
83
|
}));
|
|
195
84
|
}
|
|
196
85
|
let hookResult;
|
|
@@ -252,53 +141,4 @@ async function loadSessionToContext({
|
|
|
252
141
|
sessionToLoad = await fs.readJson(fullPath);
|
|
253
142
|
}
|
|
254
143
|
await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
|
|
255
|
-
}
|
|
256
|
-
function getLocalCdpAddress(port) {
|
|
257
|
-
return `http://localhost:${port}`;
|
|
258
|
-
}
|
|
259
|
-
async function waitOnCdpAddress(cdpAddress) {
|
|
260
|
-
const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
|
|
261
|
-
await (0, _waitOn.default)({
|
|
262
|
-
resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
|
|
263
|
-
delay: 100,
|
|
264
|
-
interval: 100,
|
|
265
|
-
timeout: 5000,
|
|
266
|
-
tcpTimeout: 1000,
|
|
267
|
-
window: 1000
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
async function getRemotePlaywrightContext(cdpAddress) {
|
|
271
|
-
const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright")));
|
|
272
|
-
let browser = null;
|
|
273
|
-
if (!cdpAddress) {
|
|
274
|
-
throw new Error("cdpAddress is required");
|
|
275
|
-
}
|
|
276
|
-
try {
|
|
277
|
-
await waitOnCdpAddress(cdpAddress);
|
|
278
|
-
} catch (error) {
|
|
279
|
-
console.error("Failed to connect to the browser");
|
|
280
|
-
process.exit(128 + 9);
|
|
281
|
-
}
|
|
282
|
-
try {
|
|
283
|
-
browser = await playwright.chromium.connectOverCDP(cdpAddress);
|
|
284
|
-
} catch (e) {
|
|
285
|
-
console.log(e);
|
|
286
|
-
throw new Error("failed to connect to the browser");
|
|
287
|
-
}
|
|
288
|
-
const context = browser.contexts()[0];
|
|
289
|
-
return {
|
|
290
|
-
browser,
|
|
291
|
-
context
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
async function getExecutablePath() {
|
|
295
|
-
if (process.env.BROWSER_TYPE === "brave") {
|
|
296
|
-
console.log("Using Brave browser");
|
|
297
|
-
const {
|
|
298
|
-
stdout: bravePath
|
|
299
|
-
} = await execAsync("which brave-browser-stable");
|
|
300
|
-
console.log("Brave path:", bravePath);
|
|
301
|
-
return bravePath ?? undefined;
|
|
302
|
-
}
|
|
303
|
-
return undefined;
|
|
304
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.
|
|
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
|
|
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.
|
|
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.
|
|
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-dev",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8-deploy.0",
|
|
4
4
|
"description": "Intuned runtime",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -110,7 +110,6 @@
|
|
|
110
110
|
"@types/promptly": "^3.0.4",
|
|
111
111
|
"@types/terminal-kit": "^2.5.7",
|
|
112
112
|
"@types/wait-on": "^5.3.4",
|
|
113
|
-
"@types/which": "^3.0.4",
|
|
114
113
|
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
|
115
114
|
"@typescript-eslint/parser": "^7.5.0",
|
|
116
115
|
"@vitest/ui": "^1.1.3",
|