@intuned/runtime-dev 1.3.27-dev7 → 1.3.28-dev1
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/CHANGELOG.md +4 -0
- package/dist/common/launchBrowser.d.ts +3 -0
- package/dist/common/launchBrowser.js +36 -10
- package/dist/common/playwrightContext.d.ts +3 -1
- package/dist/common/playwrightContext.js +9 -4
- package/dist/common/runApi/index.js +2 -0
- package/dist/vendor/runtime-interface.js +6 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as playwright from "playwright";
|
|
3
3
|
import { Result } from "neverthrow";
|
|
4
|
+
import type { ProfileMode } from "@intuned/runtime-interface";
|
|
4
5
|
export declare function getEncryptedProfileChromeArgs({ encryptedProfile, platform, disableMacKeychainPrompts, }: {
|
|
5
6
|
encryptedProfile?: boolean;
|
|
6
7
|
platform?: NodeJS.Platform;
|
|
@@ -30,6 +31,7 @@ export type LaunchChromiumStandaloneOptions = {
|
|
|
30
31
|
ignoreHttpErrors?: boolean;
|
|
31
32
|
profileTemplatePath?: string;
|
|
32
33
|
encryptedProfile?: boolean;
|
|
34
|
+
profileMode?: ProfileMode;
|
|
33
35
|
timeout?: number;
|
|
34
36
|
};
|
|
35
37
|
export type LaunchChromiumCdpOptions = {
|
|
@@ -37,6 +39,7 @@ export type LaunchChromiumCdpOptions = {
|
|
|
37
39
|
cdpTargetId?: string;
|
|
38
40
|
profileTemplatePath?: string;
|
|
39
41
|
encryptedProfile?: boolean;
|
|
42
|
+
profileMode?: ProfileMode;
|
|
40
43
|
timeout?: number;
|
|
41
44
|
};
|
|
42
45
|
export declare function launchChromium(options: LaunchChromiumStandaloneOptions): Promise<LaunchBrowserResult>;
|
|
@@ -50,7 +50,21 @@ const DEFAULT_USER_PREFERENCES = {
|
|
|
50
50
|
password_manager_enabled: false
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
async function createUserDirWithPreferences(profileTemplatePath) {
|
|
53
|
+
async function createUserDirWithPreferences(profileTemplatePath, profileMode = "persistent") {
|
|
54
|
+
if (profileMode === "persistent" && profileTemplatePath && (await fs.pathExists(profileTemplatePath))) {
|
|
55
|
+
const defaultDir = (0, _path.join)(profileTemplatePath, "Default");
|
|
56
|
+
const preferencesPath = (0, _path.join)(defaultDir, "Preferences");
|
|
57
|
+
await (0, _fsExtra.mkdir)(defaultDir, {
|
|
58
|
+
recursive: true
|
|
59
|
+
});
|
|
60
|
+
if (!(await fs.pathExists(preferencesPath))) {
|
|
61
|
+
await (0, _fsExtra.writeFile)(preferencesPath, JSON.stringify(DEFAULT_USER_PREFERENCES));
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
userDir: profileTemplatePath,
|
|
65
|
+
ephemeral: false
|
|
66
|
+
};
|
|
67
|
+
}
|
|
54
68
|
const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
|
|
55
69
|
const userDir = (0, _path.join)(playwrightTempDir, "userdir");
|
|
56
70
|
const defaultDir = (0, _path.join)(userDir, "Default");
|
|
@@ -73,13 +87,19 @@ async function createUserDirWithPreferences(profileTemplatePath) {
|
|
|
73
87
|
}
|
|
74
88
|
const mergedPreferences = mergePreferences(templatePreferences, DEFAULT_USER_PREFERENCES);
|
|
75
89
|
await (0, _fsExtra.writeFile)(preferencesPath, JSON.stringify(mergedPreferences));
|
|
76
|
-
return
|
|
90
|
+
return {
|
|
91
|
+
userDir,
|
|
92
|
+
ephemeral: true
|
|
93
|
+
};
|
|
77
94
|
}
|
|
78
95
|
await (0, _fsExtra.mkdir)(defaultDir, {
|
|
79
96
|
recursive: true
|
|
80
97
|
});
|
|
81
98
|
await (0, _fsExtra.writeFile)(preferencesPath, JSON.stringify(DEFAULT_USER_PREFERENCES));
|
|
82
|
-
return
|
|
99
|
+
return {
|
|
100
|
+
userDir,
|
|
101
|
+
ephemeral: true
|
|
102
|
+
};
|
|
83
103
|
}
|
|
84
104
|
function isPlainObject(value) {
|
|
85
105
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -152,6 +172,7 @@ async function launchChromium(options) {
|
|
|
152
172
|
ignoreHttpErrors: ignoreHttpErrorsParam,
|
|
153
173
|
profileTemplatePath,
|
|
154
174
|
encryptedProfile,
|
|
175
|
+
profileMode,
|
|
155
176
|
timeout
|
|
156
177
|
} = options;
|
|
157
178
|
let {
|
|
@@ -168,7 +189,10 @@ async function launchChromium(options) {
|
|
|
168
189
|
if (stealthConfig.enabled) {
|
|
169
190
|
extraArgs.push("--stealth-mode");
|
|
170
191
|
}
|
|
171
|
-
const
|
|
192
|
+
const {
|
|
193
|
+
userDir: userDataDir,
|
|
194
|
+
ephemeral: shouldCleanupUserDir
|
|
195
|
+
} = await createUserDirWithPreferences(profileTemplatePath, profileMode);
|
|
172
196
|
if ((0, _extensionsHelpers.isIntunedExtensionLoaded)()) {
|
|
173
197
|
const extensionsList = (0, _extensionsHelpers.buildExtensionsList)();
|
|
174
198
|
const extensions = extensionsList.join(",");
|
|
@@ -224,12 +248,14 @@ async function launchChromium(options) {
|
|
|
224
248
|
}
|
|
225
249
|
context.once("close", async () => {
|
|
226
250
|
try {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
251
|
+
if (shouldCleanupUserDir) {
|
|
252
|
+
await (0, _fsExtra.rm)(userDataDir, {
|
|
253
|
+
recursive: true,
|
|
254
|
+
force: true,
|
|
255
|
+
retryDelay: 1000,
|
|
256
|
+
maxRetries: 5
|
|
257
|
+
});
|
|
258
|
+
}
|
|
233
259
|
if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
234
260
|
await (0, _intunedExtensionServer.cleanIntunedExtensionServer)();
|
|
235
261
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as playwright from "playwright";
|
|
2
2
|
import { Err, Ok } from "neverthrow";
|
|
3
3
|
import { type Proxy } from "./launchBrowser";
|
|
4
|
-
import { ImportFunction, RunAutomationError, RunApiSession } from "@intuned/runtime-interface";
|
|
4
|
+
import { ImportFunction, RunAutomationError, RunApiSession, type ProfileMode } from "@intuned/runtime-interface";
|
|
5
5
|
type WithPlaywrightContextParameters = {
|
|
6
6
|
importFunction: ImportFunction;
|
|
7
7
|
apiName: string;
|
|
@@ -20,12 +20,14 @@ export declare function withPlaywrightContext<R>(options: {
|
|
|
20
20
|
ignoreHttpErrors?: boolean;
|
|
21
21
|
profileTemplatePath?: string;
|
|
22
22
|
encryptedProfile?: boolean;
|
|
23
|
+
profileMode?: ProfileMode;
|
|
23
24
|
} & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
|
|
24
25
|
export declare function withPlaywrightContext<R>(options: {
|
|
25
26
|
cdpAddress: string;
|
|
26
27
|
cdpTargetId?: string;
|
|
27
28
|
profileTemplatePath?: string;
|
|
28
29
|
encryptedProfile?: boolean;
|
|
30
|
+
profileMode?: ProfileMode;
|
|
29
31
|
} & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
|
|
30
32
|
export declare function loadSessionToContext({ context, session, }: {
|
|
31
33
|
context: playwright.BrowserContext;
|
|
@@ -23,6 +23,7 @@ async function withPlaywrightContext({
|
|
|
23
23
|
ignoreHttpErrors: cliIgnoreHttpErrors,
|
|
24
24
|
profileTemplatePath,
|
|
25
25
|
encryptedProfile,
|
|
26
|
+
profileMode,
|
|
26
27
|
importFunction,
|
|
27
28
|
apiName,
|
|
28
29
|
apiParameters
|
|
@@ -47,7 +48,8 @@ async function withPlaywrightContext({
|
|
|
47
48
|
cdpAddress,
|
|
48
49
|
cdpTargetId,
|
|
49
50
|
profileTemplatePath,
|
|
50
|
-
encryptedProfile
|
|
51
|
+
encryptedProfile,
|
|
52
|
+
profileMode
|
|
51
53
|
}));
|
|
52
54
|
} else {
|
|
53
55
|
({
|
|
@@ -59,7 +61,8 @@ async function withPlaywrightContext({
|
|
|
59
61
|
downloadsPath,
|
|
60
62
|
ignoreHttpErrors,
|
|
61
63
|
profileTemplatePath,
|
|
62
|
-
encryptedProfile
|
|
64
|
+
encryptedProfile,
|
|
65
|
+
profileMode
|
|
63
66
|
}));
|
|
64
67
|
}
|
|
65
68
|
return await fn(context, page);
|
|
@@ -74,7 +77,8 @@ async function withPlaywrightContext({
|
|
|
74
77
|
cdpAddress,
|
|
75
78
|
cdpTargetId,
|
|
76
79
|
profileTemplatePath,
|
|
77
|
-
encryptedProfile
|
|
80
|
+
encryptedProfile,
|
|
81
|
+
profileMode
|
|
78
82
|
}));
|
|
79
83
|
} else {
|
|
80
84
|
const port = await (0, _portfinder.getPort)({
|
|
@@ -90,7 +94,8 @@ async function withPlaywrightContext({
|
|
|
90
94
|
cdpPort: port,
|
|
91
95
|
ignoreHttpErrors,
|
|
92
96
|
profileTemplatePath,
|
|
93
|
-
encryptedProfile
|
|
97
|
+
encryptedProfile,
|
|
98
|
+
profileMode
|
|
94
99
|
}));
|
|
95
100
|
hookCdpUrl = (0, _launchBrowser.getLocalCdpAddress)(port);
|
|
96
101
|
}
|
|
@@ -150,6 +150,7 @@ async function runApi({
|
|
|
150
150
|
ignoreHttpErrors: runOptions.ignoreHttpErrors,
|
|
151
151
|
profileTemplatePath: runOptions.profileTemplatePath,
|
|
152
152
|
encryptedProfile: runOptions.encryptedProfile,
|
|
153
|
+
profileMode: runOptions.profileMode,
|
|
153
154
|
...playwrightContextParameters
|
|
154
155
|
}, runAutomationWithContext);
|
|
155
156
|
} finally {
|
|
@@ -161,6 +162,7 @@ async function runApi({
|
|
|
161
162
|
cdpTargetId: runOptions.cdpTargetId,
|
|
162
163
|
profileTemplatePath: runOptions.profileTemplatePath,
|
|
163
164
|
encryptedProfile: runOptions.encryptedProfile,
|
|
165
|
+
profileMode: runOptions.profileMode,
|
|
164
166
|
...playwrightContextParameters
|
|
165
167
|
}, runAutomationWithContext);
|
|
166
168
|
}
|
|
@@ -165,7 +165,7 @@ var require_types = __commonJS({
|
|
|
165
165
|
return mod && mod.__esModule ? mod : { "default": mod };
|
|
166
166
|
};
|
|
167
167
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
168
|
-
exports2.outputRunApiSchema = exports2.pongMessageSchema = exports2.doneMessageSchema = exports2.extendMessageSchema = exports2.runApiInputSchema = exports2.pingSchema = exports2.tokenUpdateSchema = exports2.abortRunApiSchema = exports2.startRunApiSchema = exports2.startRunApiParametersSchema = exports2.runApiParametersSchema = exports2.runApiRunOptionsSchema = exports2.runApiCdpRunOptionsSchema = exports2.runApiStandaloneRunOptionsSchema = exports2.runApiProxySchema = exports2.runApiAuthSchema = exports2.runApiTracingSchema = exports2.runApiAutomationFunctionSchema = exports2.runApiSessionSchema = exports2.runApiStorageStateSchema = void 0;
|
|
168
|
+
exports2.outputRunApiSchema = exports2.pongMessageSchema = exports2.doneMessageSchema = exports2.extendMessageSchema = exports2.runApiInputSchema = exports2.pingSchema = exports2.tokenUpdateSchema = exports2.abortRunApiSchema = exports2.startRunApiSchema = exports2.startRunApiParametersSchema = exports2.runApiParametersSchema = exports2.runApiRunOptionsSchema = exports2.runApiCdpRunOptionsSchema = exports2.runApiStandaloneRunOptionsSchema = exports2.profileModeSchema = exports2.runApiProxySchema = exports2.runApiAuthSchema = exports2.runApiTracingSchema = exports2.runApiAutomationFunctionSchema = exports2.runApiSessionSchema = exports2.runApiStorageStateSchema = void 0;
|
|
169
169
|
exports2.runApiResultOkSchema = runApiResultOkSchema;
|
|
170
170
|
exports2.runApiResultWithSessionOkSchema = runApiResultWithSessionOkSchema;
|
|
171
171
|
var zod_1 = __importDefault(require("zod"));
|
|
@@ -222,20 +222,23 @@ var require_types = __commonJS({
|
|
|
222
222
|
username: zod_1.default.string(),
|
|
223
223
|
password: zod_1.default.string()
|
|
224
224
|
});
|
|
225
|
+
exports2.profileModeSchema = zod_1.default.enum(["isolated", "persistent"]).default("persistent");
|
|
225
226
|
exports2.runApiStandaloneRunOptionsSchema = zod_1.default.object({
|
|
226
227
|
environment: zod_1.default.literal("standalone"),
|
|
227
228
|
headless: zod_1.default.boolean().default(true),
|
|
228
229
|
proxy: exports2.runApiProxySchema.optional(),
|
|
229
230
|
ignoreHttpErrors: zod_1.default.boolean().optional(),
|
|
230
231
|
profileTemplatePath: zod_1.default.string().optional(),
|
|
231
|
-
encryptedProfile: zod_1.default.boolean().optional()
|
|
232
|
+
encryptedProfile: zod_1.default.boolean().optional(),
|
|
233
|
+
profileMode: exports2.profileModeSchema
|
|
232
234
|
});
|
|
233
235
|
exports2.runApiCdpRunOptionsSchema = zod_1.default.object({
|
|
234
236
|
environment: zod_1.default.literal("cdp"),
|
|
235
237
|
cdpAddress: zod_1.default.string(),
|
|
236
238
|
cdpTargetId: zod_1.default.string().optional(),
|
|
237
239
|
profileTemplatePath: zod_1.default.string().optional(),
|
|
238
|
-
encryptedProfile: zod_1.default.boolean().optional()
|
|
240
|
+
encryptedProfile: zod_1.default.boolean().optional(),
|
|
241
|
+
profileMode: exports2.profileModeSchema
|
|
239
242
|
});
|
|
240
243
|
exports2.runApiRunOptionsSchema = zod_1.default.discriminatedUnion("environment", [
|
|
241
244
|
exports2.runApiStandaloneRunOptionsSchema,
|