@intuned/runtime-dev 0.0.1 → 0.1.0-test.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/InterfaceTemplate/index.ts +1 -0
- package/Intuned.json +5 -0
- package/WebTemplate/api.ts +92 -90
- package/WebTemplate/controllers/authSessions/check.ts +23 -29
- package/WebTemplate/controllers/authSessions/create.ts +46 -71
- package/WebTemplate/controllers/authSessions/index.ts +4 -4
- package/WebTemplate/controllers/authSessions/killOperation.ts +1 -1
- package/WebTemplate/controllers/authSessions/resumeOperation.ts +28 -52
- package/WebTemplate/controllers/authSessions/store.ts +11 -6
- package/WebTemplate/controllers/runApi/helpers.ts +47 -146
- package/WebTemplate/index.playwright.ts +42 -32
- package/WebTemplate/index.vanilla.ts +2 -20
- package/WebTemplate/jobs.ts +2 -13
- package/WebTemplate/utils.ts +1 -85
- package/WebTemplate.zip +0 -0
- package/api/authed.ts +12 -0
- package/api/test.ts +3 -0
- package/api/test2.ts +25 -0
- package/auth-sessions/check.ts +9 -0
- package/auth-sessions/create.ts +32 -0
- package/authSessions +1 -0
- package/bin/intuned-api-run +2 -0
- package/bin/intuned-auth-session-check +2 -0
- package/bin/intuned-auth-session-create +2 -0
- package/bin/intuned-auth-session-load +2 -0
- package/bin/intuned-auth-session-refresh +2 -0
- package/bin/intuned-browser-save-state +2 -0
- package/bin/intuned-browser-start +2 -0
- package/bin/intuned-build +2 -0
- package/bin/intuned-ts-check +2 -0
- package/dist/commands/api/run.d.ts +6 -0
- package/dist/commands/api/run.js +113 -0
- package/dist/commands/auth-sessions/load.d.ts +2 -0
- package/dist/commands/auth-sessions/load.js +32 -0
- package/dist/commands/auth-sessions/run-check.d.ts +2 -0
- package/dist/commands/auth-sessions/run-check.js +56 -0
- package/dist/commands/auth-sessions/run-create.d.ts +2 -0
- package/dist/commands/auth-sessions/run-create.js +96 -0
- package/dist/commands/browser/save-state.d.ts +2 -0
- package/dist/commands/browser/save-state.js +17 -0
- package/dist/commands/browser/start-browser.d.ts +2 -0
- package/dist/commands/browser/start-browser.js +14 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +83 -0
- package/dist/commands/common/browserUtils.d.ts +14 -0
- package/dist/commands/common/browserUtils.js +58 -0
- package/dist/commands/common/getDefaultExportFromFile.d.ts +1 -0
- package/dist/commands/common/getDefaultExportFromFile.js +19 -0
- package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
- package/dist/commands/common/getFirstLineNumber.js +103 -0
- package/{src/commands/common/getFirstLineNumber.test.ts → dist/commands/common/getFirstLineNumber.test.js} +75 -121
- package/dist/commands/common/sendMessageToClient.d.ts +1 -0
- package/dist/commands/common/sendMessageToClient.js +10 -0
- package/dist/commands/common/utils/fileUtils.d.ts +6 -0
- package/dist/commands/common/utils/fileUtils.js +33 -0
- package/dist/commands/common/utils/settings.d.ts +2 -0
- package/dist/commands/common/utils/settings.js +28 -0
- package/dist/commands/common/utils/unixSocket.d.ts +9 -0
- package/dist/commands/common/utils/unixSocket.js +45 -0
- package/dist/commands/common/utils/webTemplate.d.ts +1 -0
- package/dist/commands/common/utils/webTemplate.js +31 -0
- package/dist/commands/interface/run.d.ts +2 -0
- package/dist/commands/interface/run.js +161 -0
- package/dist/commands/ts-check.d.ts +2 -0
- package/dist/commands/ts-check.js +54 -0
- package/dist/common/Logger/Logger/index.d.ts +12 -0
- package/dist/common/Logger/Logger/index.js +60 -0
- package/{src/common/Logger/Logger/types.ts → dist/common/Logger/Logger/types.d.ts} +4 -5
- package/dist/common/Logger/Logger/types.js +5 -0
- package/dist/common/Logger/index.d.ts +12 -0
- package/dist/common/Logger/index.js +60 -0
- package/{src/common/Logger/types.ts → dist/common/Logger/types.d.ts} +4 -5
- package/dist/common/Logger/types.js +5 -0
- package/dist/common/asyncLocalStorage/index.d.ts +16 -0
- package/dist/common/asyncLocalStorage/index.js +17 -0
- package/dist/common/cleanEnvironmentVariables.d.ts +1 -0
- package/dist/common/cleanEnvironmentVariables.js +16 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +7 -0
- package/dist/common/contextStorageStateHelpers.d.ts +14 -0
- package/dist/common/contextStorageStateHelpers.js +50 -0
- package/dist/common/getPlaywrightConstructs.d.ts +30 -0
- package/dist/common/getPlaywrightConstructs.js +192 -0
- package/dist/common/jwtTokenManager.d.ts +16 -0
- package/dist/common/jwtTokenManager.js +81 -0
- package/dist/common/runApi/errors.d.ts +71 -0
- package/dist/common/runApi/errors.js +172 -0
- package/dist/common/runApi/index.d.ts +12 -0
- package/dist/common/runApi/index.js +288 -0
- package/dist/common/runApi/types.d.ts +486 -0
- package/dist/common/runApi/types.js +50 -0
- package/dist/common/settingsSchema.d.ts +19 -0
- package/dist/common/settingsSchema.js +17 -0
- package/dist/common/telemetry.d.ts +3 -0
- package/dist/common/telemetry.js +32 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +69 -0
- package/dist/runtime/RunError.d.ts +5 -0
- package/dist/runtime/RunError.js +19 -0
- package/dist/runtime/downloadDirectory.d.ts +1 -0
- package/dist/runtime/downloadDirectory.js +19 -0
- package/dist/runtime/enums.d.js +5 -0
- package/dist/runtime/enums.js +18 -0
- package/dist/runtime/executionHelpers.test.js +53 -0
- package/dist/runtime/export.d.js +5 -0
- package/dist/runtime/extendPayload.d.ts +2 -0
- package/dist/runtime/extendPayload.js +21 -0
- package/dist/runtime/extendTimeout.d.ts +1 -0
- package/dist/runtime/extendTimeout.js +30 -0
- package/{src/runtime/index.ts → dist/runtime/index.d.ts} +2 -3
- package/dist/runtime/index.js +53 -0
- package/dist/runtime/requestMoreInfo.d.ts +18 -0
- package/dist/runtime/requestMoreInfo.js +25 -0
- package/dist/runtime/runInfo.d.ts +2 -0
- package/dist/runtime/runInfo.js +21 -0
- package/output.txt +39 -0
- package/package.json +9 -7
- package/testing +0 -0
- package/tsconfig.json +2 -1
- package/.vite/deps_temp_01af7156/package.json +0 -3
- package/.vscode/extensions.json +0 -3
- package/.vscode/launch.json +0 -102
- package/.vscode/settings.json +0 -12
- package/playwright.config.ts +0 -48
- package/src/commands/api/run.ts +0 -225
- package/src/commands/auth-sessions/load.ts +0 -42
- package/src/commands/auth-sessions/run-check.ts +0 -70
- package/src/commands/auth-sessions/run-create.ts +0 -124
- package/src/commands/browser/save-state.ts +0 -22
- package/src/commands/browser/start-browser.ts +0 -17
- package/src/commands/build.ts +0 -125
- package/src/commands/common/browserUtils.ts +0 -80
- package/src/commands/common/getDefaultExportFromFile.ts +0 -13
- package/src/commands/common/getFirstLineNumber.ts +0 -146
- package/src/commands/common/sendMessageToClient.ts +0 -8
- package/src/commands/common/utils/fileUtils.ts +0 -25
- package/src/commands/common/utils/settings.ts +0 -23
- package/src/commands/common/utils/webTemplate.ts +0 -46
- package/src/commands/testing/saveVisibleHtml.ts +0 -29
- package/src/commands/ts-check.ts +0 -88
- package/src/common/Logger/Logger/index.ts +0 -64
- package/src/common/Logger/index.ts +0 -64
- package/src/common/asyncLocalStorage/index.ts +0 -29
- package/src/common/cleanEnvironmentVariables.ts +0 -13
- package/src/common/constants.ts +0 -1
- package/src/common/contextStorageStateHelpers.ts +0 -71
- package/src/common/getPlaywrightConstructs.ts +0 -283
- package/src/common/jwtTokenManager.ts +0 -111
- package/src/common/settingsSchema.ts +0 -16
- package/src/common/telemetry.ts +0 -49
- package/src/index.ts +0 -14
- package/src/runtime/RunError.ts +0 -16
- package/src/runtime/downloadDirectory.ts +0 -14
- package/src/runtime/enums.ts +0 -11
- package/src/runtime/executionHelpers.test.ts +0 -70
- package/src/runtime/extendPayload.ts +0 -22
- package/src/runtime/extendTimeout.ts +0 -32
- package/src/runtime/requestMoreInfo.ts +0 -40
- package/src/runtime/runInfo.ts +0 -19
- package/vite.config.ts +0 -17
- /package/{src → dist}/common/assets/browser_scripts.js +0 -0
- /package/{src → dist}/runtime/enums.d.ts +0 -0
- /package/{src → dist}/runtime/export.d.ts +0 -0
package/src/commands/ts-check.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import * as ts from "typescript";
|
|
3
|
-
import { program } from "commander";
|
|
4
|
-
import * as fs from "fs-extra";
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
import { moveWebTemplateFiles } from "./common/utils/webTemplate";
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.description("Check TypeScript types in the project")
|
|
10
|
-
.allowUnknownOption()
|
|
11
|
-
.action(async () => {
|
|
12
|
-
await moveWebTemplateFiles();
|
|
13
|
-
|
|
14
|
-
const templateTsConfig = path.resolve(
|
|
15
|
-
__dirname,
|
|
16
|
-
"..",
|
|
17
|
-
"..",
|
|
18
|
-
"template.tsconfig.json"
|
|
19
|
-
);
|
|
20
|
-
await fs.copy(templateTsConfig, "./intuned/WebTemplate/tsconfig.json");
|
|
21
|
-
|
|
22
|
-
checkTypes();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
function checkTypes() {
|
|
26
|
-
const configPath = ts.findConfigFile(
|
|
27
|
-
"./intuned/WebTemplate",
|
|
28
|
-
ts.sys.fileExists,
|
|
29
|
-
"tsconfig.json"
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
if (!configPath) {
|
|
33
|
-
console.error("Could not find a valid 'tsconfig.json'.");
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const readConfigResult = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
38
|
-
const config = readConfigResult.config;
|
|
39
|
-
|
|
40
|
-
const parseConfigHost = {
|
|
41
|
-
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
|
42
|
-
readDirectory: ts.sys.readDirectory,
|
|
43
|
-
fileExists: ts.sys.fileExists,
|
|
44
|
-
readFile: ts.sys.readFile,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const parsed = ts.parseJsonConfigFileContent(
|
|
48
|
-
config,
|
|
49
|
-
parseConfigHost,
|
|
50
|
-
"./intuned"
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const program = ts.createProgram(parsed.fileNames, parsed.options);
|
|
54
|
-
const emitResult = program.emit();
|
|
55
|
-
|
|
56
|
-
const allDiagnostics = ts
|
|
57
|
-
.getPreEmitDiagnostics(program)
|
|
58
|
-
.concat(emitResult.diagnostics);
|
|
59
|
-
|
|
60
|
-
allDiagnostics.forEach((diagnostic) => {
|
|
61
|
-
if (diagnostic.file) {
|
|
62
|
-
const { line, character } = ts.getLineAndCharacterOfPosition(
|
|
63
|
-
diagnostic.file,
|
|
64
|
-
diagnostic.start!
|
|
65
|
-
);
|
|
66
|
-
const message = ts.flattenDiagnosticMessageText(
|
|
67
|
-
diagnostic.messageText,
|
|
68
|
-
"\n"
|
|
69
|
-
);
|
|
70
|
-
console.log(
|
|
71
|
-
`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`
|
|
72
|
-
);
|
|
73
|
-
} else {
|
|
74
|
-
console.log(
|
|
75
|
-
ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
if (allDiagnostics.length === 0) {
|
|
81
|
-
console.log("✨ TypeScript type checking passed without errors.");
|
|
82
|
-
} else {
|
|
83
|
-
console.error("Errors found during TypeScript type checking.");
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
program.parse(process.argv);
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { formatWithOptions } from "node:util";
|
|
2
|
-
import { LogEntry, LogLevel, LogMetadata } from "./types";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
|
|
5
|
-
const format = formatWithOptions.bind(undefined, { colors: true });
|
|
6
|
-
|
|
7
|
-
const LOG_LEVEL_COLORS: Record<LogLevel, chalk.Chalk> = {
|
|
8
|
-
TRACE: chalk.gray,
|
|
9
|
-
DEBUG: chalk.blue,
|
|
10
|
-
INFO: chalk.green,
|
|
11
|
-
WARN: chalk.yellow,
|
|
12
|
-
ERROR: chalk.red,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
class Logger {
|
|
16
|
-
logFunction(entry: LogEntry): void {
|
|
17
|
-
const { level, timestamp, message, meta } = entry;
|
|
18
|
-
const date = new Date(timestamp);
|
|
19
|
-
const levelColor = LOG_LEVEL_COLORS[level];
|
|
20
|
-
|
|
21
|
-
if (meta === undefined) {
|
|
22
|
-
process.stderr.write(
|
|
23
|
-
`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`
|
|
24
|
-
);
|
|
25
|
-
} else {
|
|
26
|
-
process.stderr.write(
|
|
27
|
-
`${format(date)} [@intuned/sdk][${levelColor(
|
|
28
|
-
level
|
|
29
|
-
)}] ${message} ${format(meta)}\n`
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private log(level: LogLevel, message: string, meta?: LogMetadata): void {
|
|
35
|
-
this.logFunction({
|
|
36
|
-
level,
|
|
37
|
-
message,
|
|
38
|
-
meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
|
|
39
|
-
timestamp: Date.now(),
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
trace(message: string, meta?: LogMetadata): void {
|
|
44
|
-
this.log("TRACE", message, meta);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
debug(message: string, meta?: LogMetadata): void {
|
|
48
|
-
this.log("DEBUG", message, meta);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
info(message: string, meta?: LogMetadata): void {
|
|
52
|
-
this.log("INFO", message, meta);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
warn(message: string, meta?: LogMetadata): void {
|
|
56
|
-
this.log("WARN", message, meta);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
error(message: string, meta?: LogMetadata): void {
|
|
60
|
-
this.log("ERROR", message, meta);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const logger = new Logger();
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { formatWithOptions } from "node:util";
|
|
2
|
-
import { LogEntry, LogLevel, LogMetadata } from "./types";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
|
|
5
|
-
const format = formatWithOptions.bind(undefined, { colors: true });
|
|
6
|
-
|
|
7
|
-
const LOG_LEVEL_COLORS: Record<LogLevel, chalk.Chalk> = {
|
|
8
|
-
TRACE: chalk.gray,
|
|
9
|
-
DEBUG: chalk.blue,
|
|
10
|
-
INFO: chalk.green,
|
|
11
|
-
WARN: chalk.yellow,
|
|
12
|
-
ERROR: chalk.red,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
class Logger {
|
|
16
|
-
logFunction(entry: LogEntry): void {
|
|
17
|
-
const { level, timestamp, message, meta } = entry;
|
|
18
|
-
const date = new Date(timestamp);
|
|
19
|
-
const levelColor = LOG_LEVEL_COLORS[level];
|
|
20
|
-
|
|
21
|
-
if (meta === undefined) {
|
|
22
|
-
process.stderr.write(
|
|
23
|
-
`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`
|
|
24
|
-
);
|
|
25
|
-
} else {
|
|
26
|
-
process.stderr.write(
|
|
27
|
-
`${format(date)} [@intuned/sdk][${levelColor(
|
|
28
|
-
level
|
|
29
|
-
)}] ${message} ${format(meta)}\n`
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private log(level: LogLevel, message: string, meta?: LogMetadata): void {
|
|
35
|
-
this.logFunction({
|
|
36
|
-
level,
|
|
37
|
-
message,
|
|
38
|
-
meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
|
|
39
|
-
timestamp: Date.now(),
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
trace(message: string, meta?: LogMetadata): void {
|
|
44
|
-
this.log("TRACE", message, meta);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
debug(message: string, meta?: LogMetadata): void {
|
|
48
|
-
this.log("DEBUG", message, meta);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
info(message: string, meta?: LogMetadata): void {
|
|
52
|
-
this.log("INFO", message, meta);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
warn(message: string, meta?: LogMetadata): void {
|
|
56
|
-
this.log("WARN", message, meta);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
error(message: string, meta?: LogMetadata): void {
|
|
60
|
-
this.log("ERROR", message, meta);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const logger = new Logger();
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
2
|
-
import { Payload, RunInfo } from "../../runtime/export";
|
|
3
|
-
|
|
4
|
-
export const asyncLocalStorage = new AsyncLocalStorage<InternalRunInfo>();
|
|
5
|
-
|
|
6
|
-
export function runWithContext<R, TArgs extends any[]>(
|
|
7
|
-
contextData: InternalRunInfo,
|
|
8
|
-
callback: (...args: TArgs) => R,
|
|
9
|
-
...args: TArgs
|
|
10
|
-
): R {
|
|
11
|
-
return asyncLocalStorage.run(contextData, callback, ...args);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface TimeoutInfo {
|
|
15
|
-
extendTimeoutCallback?: () => Promise<void>;
|
|
16
|
-
timeoutDuration?: number;
|
|
17
|
-
timeoutTimestamp?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface InternalRunInfo extends RunInfo {
|
|
21
|
-
extendedPayloads: Payload[];
|
|
22
|
-
timeoutInfo?: TimeoutInfo;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function getExecutionContext() {
|
|
26
|
-
const contextData = asyncLocalStorage.getStore();
|
|
27
|
-
|
|
28
|
-
return contextData as InternalRunInfo | undefined;
|
|
29
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function cleanEnvironmentVariables() {
|
|
2
|
-
Object.keys(process.env)
|
|
3
|
-
.filter((i) => {
|
|
4
|
-
if (i.toLocaleLowerCase().startsWith("npm")) {
|
|
5
|
-
return true;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (i.toLocaleLowerCase().startsWith("fly") && i !== "FLY_ALLOC_ID") {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
})
|
|
12
|
-
.forEach((i) => delete process.env[i]);
|
|
13
|
-
}
|
package/src/common/constants.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { BrowserContext } from "@intuned/playwright";
|
|
2
|
-
import * as playwright from "@intuned/playwright-core";
|
|
3
|
-
|
|
4
|
-
function sessionStorageToArray(
|
|
5
|
-
storage: Record<string, string>
|
|
6
|
-
): { name: string; value: string }[] {
|
|
7
|
-
const result: { name: string; value: string }[] = [];
|
|
8
|
-
|
|
9
|
-
for (const key in storage) {
|
|
10
|
-
result.push({ name: key, value: storage[key] });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface OriginSessionStorage {
|
|
17
|
-
origin: string;
|
|
18
|
-
sessionStorage: Array<{
|
|
19
|
-
name: string;
|
|
20
|
-
value: string;
|
|
21
|
-
}>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type IntunedStorageState = Exclude<
|
|
25
|
-
playwright.BrowserContextOptions["storageState"],
|
|
26
|
-
string
|
|
27
|
-
> & {
|
|
28
|
-
sessionStorage?: OriginSessionStorage[];
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export async function getContextStorageState(
|
|
32
|
-
context: BrowserContext
|
|
33
|
-
): Promise<IntunedStorageState> {
|
|
34
|
-
const cookiesAndLocalStorage = await context.storageState();
|
|
35
|
-
const pages = await context.pages();
|
|
36
|
-
|
|
37
|
-
const pagesSessions: OriginSessionStorage[] = [];
|
|
38
|
-
for (const page of pages) {
|
|
39
|
-
const [origin, session] = await page.evaluate(() => [
|
|
40
|
-
location.origin,
|
|
41
|
-
sessionStorage as Record<string, string>,
|
|
42
|
-
]);
|
|
43
|
-
|
|
44
|
-
const transformed = sessionStorageToArray(session);
|
|
45
|
-
|
|
46
|
-
pagesSessions.push({ origin, sessionStorage: transformed });
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
...cookiesAndLocalStorage,
|
|
51
|
-
sessionStorage: pagesSessions,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function setContextStorageState(
|
|
56
|
-
context: BrowserContext,
|
|
57
|
-
storage: IntunedStorageState
|
|
58
|
-
) {
|
|
59
|
-
await (context as any).intunedSetStorageState(storage);
|
|
60
|
-
|
|
61
|
-
const sessionStorage = storage.sessionStorage;
|
|
62
|
-
|
|
63
|
-
await context.addInitScript((storage) => {
|
|
64
|
-
for (const { origin, sessionStorage } of storage) {
|
|
65
|
-
if (window.location.origin === origin) {
|
|
66
|
-
for (const item of sessionStorage)
|
|
67
|
-
window.sessionStorage.setItem(item.name, item.value);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}, sessionStorage);
|
|
71
|
-
}
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import * as playwright from "@intuned/playwright-core";
|
|
2
|
-
import { existsSync, mkdir, mkdtemp, rm, writeFile, readFile } from "fs-extra";
|
|
3
|
-
import {
|
|
4
|
-
IntunedStorageState,
|
|
5
|
-
setContextStorageState,
|
|
6
|
-
} from "./contextStorageStateHelpers";
|
|
7
|
-
import { join } from "path";
|
|
8
|
-
import path from "path";
|
|
9
|
-
import type { Browser, Page } from "@intuned/playwright-core";
|
|
10
|
-
import * as fs from "fs-extra";
|
|
11
|
-
import { getFullPathInProject } from "../commands/common/utils/fileUtils";
|
|
12
|
-
import waitOn from "wait-on";
|
|
13
|
-
import { getDownloadDirectoryPath } from "../runtime";
|
|
14
|
-
|
|
15
|
-
interface Proxy {
|
|
16
|
-
server: string;
|
|
17
|
-
username: string;
|
|
18
|
-
password: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface GetPlaywrightConstructsOptions {
|
|
22
|
-
proxy?: Proxy;
|
|
23
|
-
headless?: boolean;
|
|
24
|
-
storageState?: IntunedStorageState;
|
|
25
|
-
downloadsPath: string;
|
|
26
|
-
userDataDir?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async function createUserDirWithPreferences() {
|
|
30
|
-
const playwrightTempDir = await mkdtemp("/tmp/pw-");
|
|
31
|
-
const userDir = join(playwrightTempDir, "userdir");
|
|
32
|
-
const defaultDir = join(userDir, "Default");
|
|
33
|
-
await mkdir(defaultDir, {
|
|
34
|
-
recursive: true,
|
|
35
|
-
});
|
|
36
|
-
const preferences = {
|
|
37
|
-
plugins: {
|
|
38
|
-
always_open_pdf_externally: true,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
await writeFile(join(defaultDir, "Preferences"), JSON.stringify(preferences));
|
|
42
|
-
|
|
43
|
-
return userDir;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function getProductionPlaywrightConstructs({
|
|
47
|
-
proxy,
|
|
48
|
-
headless = true,
|
|
49
|
-
storageState,
|
|
50
|
-
downloadsPath,
|
|
51
|
-
}: GetPlaywrightConstructsOptions): Promise<{
|
|
52
|
-
page: playwright.Page;
|
|
53
|
-
context: playwright.BrowserContext;
|
|
54
|
-
}> {
|
|
55
|
-
const extraArgs = [
|
|
56
|
-
"--no-first-run",
|
|
57
|
-
"--disable-sync",
|
|
58
|
-
"--disable-translate",
|
|
59
|
-
"--disable-features=TranslateUI",
|
|
60
|
-
"--disable-features=NetworkService",
|
|
61
|
-
"--lang=en",
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
if (headless) {
|
|
65
|
-
extraArgs.push("--headless=new");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const executablePath = playwright.chromium.executablePath();
|
|
69
|
-
// use chromium 127 instead of 125, this depends on the docker image playwright version.
|
|
70
|
-
const chromium127Path = executablePath.replace(
|
|
71
|
-
"chromium-1117",
|
|
72
|
-
"chromium-1124"
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const isChrome127There = existsSync(chromium127Path);
|
|
76
|
-
|
|
77
|
-
const userAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${
|
|
78
|
-
isChrome127There ? 127 : 125
|
|
79
|
-
}.0.0.0 Safari/537.36`;
|
|
80
|
-
|
|
81
|
-
const userDataDir = await createUserDirWithPreferences();
|
|
82
|
-
|
|
83
|
-
const context = await playwright.chromium.launchPersistentContext(
|
|
84
|
-
userDataDir,
|
|
85
|
-
{
|
|
86
|
-
headless,
|
|
87
|
-
ignoreDefaultArgs: [...getChromiumLaunchArgsToIgnore(), "--headless"],
|
|
88
|
-
proxy,
|
|
89
|
-
executablePath: isChrome127There ? chromium127Path : executablePath,
|
|
90
|
-
args: extraArgs,
|
|
91
|
-
downloadsPath,
|
|
92
|
-
userAgent,
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
context.once("close", async () => {
|
|
97
|
-
try {
|
|
98
|
-
await rm(userDataDir, {
|
|
99
|
-
recursive: true,
|
|
100
|
-
force: true,
|
|
101
|
-
retryDelay: 1000,
|
|
102
|
-
maxRetries: 5,
|
|
103
|
-
});
|
|
104
|
-
} catch (error) {
|
|
105
|
-
console.error("Failed to remove user data dir", error);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
if (storageState) {
|
|
110
|
-
await setContextStorageState(context, storageState);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const assetsFile = path.join(__dirname, "./assets/browser_scripts.js");
|
|
114
|
-
await context.addInitScript({
|
|
115
|
-
path: assetsFile,
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
let page = context.pages().at(0);
|
|
119
|
-
|
|
120
|
-
if (page) {
|
|
121
|
-
const scriptString = await readFile(assetsFile, "utf8");
|
|
122
|
-
await page.evaluate(scriptString);
|
|
123
|
-
} else {
|
|
124
|
-
page = await context.newPage();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
page,
|
|
129
|
-
context,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const getChromiumLaunchArgsToIgnore = () => [
|
|
134
|
-
"--disable-field-trial-config",
|
|
135
|
-
"--disable-background-networking",
|
|
136
|
-
"--enable-features=NetworkService,NetworkServiceInProcess",
|
|
137
|
-
"--disable-background-timer-throttling",
|
|
138
|
-
"--disable-backgrounding-occluded-windows",
|
|
139
|
-
"--disable-back-forward-cache",
|
|
140
|
-
"--disable-breakpad",
|
|
141
|
-
"--disable-client-side-phishing-detection",
|
|
142
|
-
"--disable-component-extensions-with-background-pages",
|
|
143
|
-
"--disable-component-update",
|
|
144
|
-
"--no-default-browser-check",
|
|
145
|
-
"--disable-default-apps",
|
|
146
|
-
"--disable-dev-shm-usage",
|
|
147
|
-
"--disable-extensions",
|
|
148
|
-
"--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,TranslateUI",
|
|
149
|
-
"--allow-pre-commit-input",
|
|
150
|
-
"--disable-hang-monitor",
|
|
151
|
-
"--disable-ipc-flooding-protection",
|
|
152
|
-
"--disable-prompt-on-repost",
|
|
153
|
-
"--disable-renderer-backgrounding",
|
|
154
|
-
"--force-color-profile=srgb",
|
|
155
|
-
"--metrics-recording-only",
|
|
156
|
-
"--no-first-run",
|
|
157
|
-
"--enable-automation",
|
|
158
|
-
"--password-store=basic",
|
|
159
|
-
"--use-mock-keychain",
|
|
160
|
-
"--no-service-autorun",
|
|
161
|
-
"--export-tagged-pdf",
|
|
162
|
-
"--enable-use-zoom-for-dsf=false",
|
|
163
|
-
];
|
|
164
|
-
|
|
165
|
-
export async function getPlaywrightConstructsForMode(
|
|
166
|
-
mode:
|
|
167
|
-
| "vanilla"
|
|
168
|
-
| "playwright"
|
|
169
|
-
| "playwright-standalone"
|
|
170
|
-
| "playwright-headless",
|
|
171
|
-
cdpAddress: string | undefined,
|
|
172
|
-
authSessionPath?: string
|
|
173
|
-
): Promise<{
|
|
174
|
-
page: playwright.Page;
|
|
175
|
-
context: playwright.BrowserContext;
|
|
176
|
-
}> {
|
|
177
|
-
if (mode == "playwright-standalone") {
|
|
178
|
-
if (!cdpAddress) {
|
|
179
|
-
throw new Error("cdpAddress is required");
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const { context } = await getRemotePlaywrightContext(cdpAddress);
|
|
183
|
-
if (!context) {
|
|
184
|
-
throw new Error("no context found");
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const assetsFile = path.join(__dirname, "./assets/browser_scripts.js");
|
|
188
|
-
await context.addInitScript({
|
|
189
|
-
path: assetsFile,
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
const pages = await context.pages();
|
|
193
|
-
let page: Page | null = null;
|
|
194
|
-
if (pages.length > 0) {
|
|
195
|
-
page = pages[0];
|
|
196
|
-
const scriptString = await fs.readFile(assetsFile, "utf8");
|
|
197
|
-
await page.evaluate(scriptString);
|
|
198
|
-
} else {
|
|
199
|
-
page = await context.newPage();
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (authSessionPath) {
|
|
203
|
-
await loadAuthSessionToContext(context, authSessionPath);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return {
|
|
207
|
-
page,
|
|
208
|
-
context,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const downloadsPath = getDownloadDirectoryPath();
|
|
213
|
-
if (mode === "playwright" || mode === "playwright-headless") {
|
|
214
|
-
const productionConstructs = await getProductionPlaywrightConstructs({
|
|
215
|
-
headless: mode === "playwright-headless",
|
|
216
|
-
downloadsPath,
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
if (authSessionPath) {
|
|
220
|
-
await loadAuthSessionToContext(
|
|
221
|
-
productionConstructs.context,
|
|
222
|
-
authSessionPath
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return {
|
|
227
|
-
...productionConstructs,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
throw "invalid mode";
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export async function loadAuthSessionToContext(
|
|
235
|
-
context: playwright.BrowserContext,
|
|
236
|
-
authSessionPath: string
|
|
237
|
-
) {
|
|
238
|
-
const fullPath = getFullPathInProject(authSessionPath);
|
|
239
|
-
const data = await fs.readJson(fullPath);
|
|
240
|
-
|
|
241
|
-
await setContextStorageState(context, data);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export async function getRemotePlaywrightContext(cdpAddress: string) {
|
|
245
|
-
const playwright = await import("@intuned/playwright-core");
|
|
246
|
-
let browser: Browser | null = null;
|
|
247
|
-
|
|
248
|
-
if (!cdpAddress) {
|
|
249
|
-
throw new Error("cdpAddress is required");
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const cdpAddressWithoutProtocol = cdpAddress
|
|
253
|
-
.replace("http://", "")
|
|
254
|
-
.replace("https://", "")
|
|
255
|
-
.replace("localhost", "127.0.0.1");
|
|
256
|
-
|
|
257
|
-
try {
|
|
258
|
-
await waitOn({
|
|
259
|
-
resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
|
|
260
|
-
delay: 100,
|
|
261
|
-
interval: 100,
|
|
262
|
-
timeout: 5000,
|
|
263
|
-
tcpTimeout: 1000,
|
|
264
|
-
window: 1000,
|
|
265
|
-
});
|
|
266
|
-
} catch (error) {
|
|
267
|
-
console.error("Failed to connect to the browser");
|
|
268
|
-
// 128 is the exit code for SIGINT https://tldp.org/LDP/abs/html/exitcodes.html
|
|
269
|
-
// 9 is the SIGKILL signal
|
|
270
|
-
process.exit(128 + 9);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
try {
|
|
274
|
-
browser = await playwright.chromium.connectOverCDP(cdpAddress);
|
|
275
|
-
} catch (e) {
|
|
276
|
-
console.log(e);
|
|
277
|
-
throw new Error("failed to connect to the browser");
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const context = browser.contexts()[0];
|
|
281
|
-
|
|
282
|
-
return { browser, context };
|
|
283
|
-
}
|