@intuned/runtime-dev 1.3.6-brave.4 → 1.3.8-jsonl.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/common/utils/unixSocket.d.ts +19 -5
- package/dist/commands/common/utils/unixSocket.js +53 -10
- package/dist/commands/interface/run.js +11 -12
- 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/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
|
});
|
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export interface InterfaceClient {
|
|
2
|
+
sendJSON(data: any): void;
|
|
3
|
+
receiveJSON(): AsyncGenerator<any, void, unknown>;
|
|
4
|
+
close(): void;
|
|
5
|
+
get closed(): boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class SocketClient implements InterfaceClient {
|
|
5
8
|
static readonly LENGTH_HEADER_LENGTH = 4;
|
|
6
|
-
|
|
9
|
+
private readonly socket;
|
|
10
|
+
constructor(socketPath: string);
|
|
11
|
+
sendJSON(data: any): void;
|
|
12
|
+
receiveJSON(): AsyncGenerator<any, void, unknown>;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
get closed(): boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class JSONLFileClient implements InterfaceClient {
|
|
17
|
+
private readonly fileStream;
|
|
18
|
+
constructor(filePath: string);
|
|
7
19
|
sendJSON(data: any): void;
|
|
8
20
|
receiveJSON(): AsyncGenerator<any, void, unknown>;
|
|
21
|
+
close(): Promise<void>;
|
|
22
|
+
get closed(): boolean;
|
|
9
23
|
}
|
|
@@ -3,18 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.SocketClient = exports.JSONLFileClient = void 0;
|
|
7
|
+
var net = _interopRequireWildcard(require("net"));
|
|
8
|
+
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
9
|
+
var _readline = require("readline");
|
|
10
|
+
var _promises = require("timers/promises");
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
13
|
+
class SocketClient {
|
|
8
14
|
static LENGTH_HEADER_LENGTH = 4;
|
|
9
|
-
constructor(
|
|
10
|
-
this.socket =
|
|
15
|
+
constructor(socketPath) {
|
|
16
|
+
this.socket = net.createConnection(socketPath);
|
|
11
17
|
}
|
|
12
18
|
sendJSON(data) {
|
|
13
19
|
const dataToSend = JSON.stringify(data);
|
|
14
20
|
const length = Buffer.byteLength(dataToSend);
|
|
15
|
-
const buffer = Buffer.alloc(
|
|
21
|
+
const buffer = Buffer.alloc(SocketClient.LENGTH_HEADER_LENGTH + length);
|
|
16
22
|
buffer.writeUInt32BE(length, 0);
|
|
17
|
-
buffer.write(dataToSend,
|
|
23
|
+
buffer.write(dataToSend, SocketClient.LENGTH_HEADER_LENGTH);
|
|
18
24
|
this.socket.write(buffer);
|
|
19
25
|
}
|
|
20
26
|
async *receiveJSON() {
|
|
@@ -32,13 +38,50 @@ class JSONUnixSocket {
|
|
|
32
38
|
}
|
|
33
39
|
buffer = Buffer.concat([buffer, chunk]);
|
|
34
40
|
const length = buffer.readUInt32BE(0);
|
|
35
|
-
if (buffer.length < length +
|
|
41
|
+
if (buffer.length < length + SocketClient.LENGTH_HEADER_LENGTH) {
|
|
36
42
|
continue;
|
|
37
43
|
}
|
|
38
|
-
const data = buffer.subarray(
|
|
39
|
-
buffer = buffer.subarray(length +
|
|
44
|
+
const data = buffer.subarray(SocketClient.LENGTH_HEADER_LENGTH, length + SocketClient.LENGTH_HEADER_LENGTH);
|
|
45
|
+
buffer = buffer.subarray(length + SocketClient.LENGTH_HEADER_LENGTH);
|
|
40
46
|
yield JSON.parse(data.toString());
|
|
41
47
|
}
|
|
42
48
|
}
|
|
49
|
+
async close() {
|
|
50
|
+
this.socket.end();
|
|
51
|
+
await Promise.race([new Promise(resolve => this.socket.once("close", resolve)), new Promise(resolve => this.socket.once("error", resolve)), (0, _promises.setTimeout)(3000)]);
|
|
52
|
+
}
|
|
53
|
+
get closed() {
|
|
54
|
+
return this.socket.closed;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.SocketClient = SocketClient;
|
|
58
|
+
class JSONLFileClient {
|
|
59
|
+
constructor(filePath) {
|
|
60
|
+
this.fileStream = fs.createReadStream(filePath, {
|
|
61
|
+
encoding: "utf-8"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
sendJSON(data) {
|
|
65
|
+
console.log("Sending message", data);
|
|
66
|
+
}
|
|
67
|
+
async *receiveJSON() {
|
|
68
|
+
const rl = (0, _readline.createInterface)({
|
|
69
|
+
input: this.fileStream,
|
|
70
|
+
crlfDelay: Infinity
|
|
71
|
+
});
|
|
72
|
+
for await (const line of rl) {
|
|
73
|
+
if (line.trim() === "") {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
yield JSON.parse(line);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async close() {
|
|
80
|
+
this.fileStream.close();
|
|
81
|
+
await Promise.race([new Promise(resolve => this.fileStream.once("close", resolve)), new Promise(resolve => this.fileStream.once("error", resolve)), (0, _promises.setTimeout)(3000)]);
|
|
82
|
+
}
|
|
83
|
+
get closed() {
|
|
84
|
+
return this.fileStream.closed;
|
|
85
|
+
}
|
|
43
86
|
}
|
|
44
|
-
exports.
|
|
87
|
+
exports.JSONLFileClient = JSONLFileClient;
|
|
@@ -7,7 +7,6 @@ exports.runAutomationCLI = runAutomationCLI;
|
|
|
7
7
|
var _commander = require("commander");
|
|
8
8
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
9
9
|
var _asyncLocalStorage = require("../../common/asyncLocalStorage");
|
|
10
|
-
var net = _interopRequireWildcard(require("net"));
|
|
11
10
|
var _zod = _interopRequireDefault(require("zod"));
|
|
12
11
|
var _runApi = require("../../common/runApi");
|
|
13
12
|
var _enums = require("../../runtime/enums");
|
|
@@ -59,22 +58,23 @@ _dotenv.default.config({
|
|
|
59
58
|
path: `.env`
|
|
60
59
|
});
|
|
61
60
|
function runAutomationCLI(importFunction) {
|
|
62
|
-
_commander.program.description("run user automation and communicate using unix socket").argument("<socket-path>", "path to unix socket").action(async socketPath
|
|
61
|
+
_commander.program.description("run user automation and communicate using unix socket").argument("<socket-path>", "path to unix socket").option("--jsonl", "use a JSONL client instead of socket.", false).action(async (socketPath, {
|
|
62
|
+
jsonl
|
|
63
|
+
}) => {
|
|
63
64
|
let context;
|
|
64
65
|
const throttleTime = 60 * 1000;
|
|
65
66
|
let timeoutTimestamp = Date.now();
|
|
66
|
-
const client =
|
|
67
|
+
const client = jsonl ? new _unixSocket.JSONLFileClient(socketPath) : new _unixSocket.SocketClient(socketPath);
|
|
67
68
|
const abortController = new AbortController();
|
|
68
69
|
const interruptSignalHandler = async () => {
|
|
69
70
|
abortController.abort();
|
|
70
71
|
await (0, _promises.setTimeout)(60_000);
|
|
71
|
-
client.
|
|
72
|
+
await client.close();
|
|
72
73
|
process.exit(1);
|
|
73
74
|
};
|
|
74
75
|
process.on("SIGINT", interruptSignalHandler);
|
|
75
76
|
process.on("SIGTERM", interruptSignalHandler);
|
|
76
|
-
const
|
|
77
|
-
const messagesGenerator = jsonUnixSocket.receiveJSON();
|
|
77
|
+
const messagesGenerator = client.receiveJSON();
|
|
78
78
|
async function receiveMessages() {
|
|
79
79
|
const data = await messagesGenerator.next();
|
|
80
80
|
if (data.done) {
|
|
@@ -109,7 +109,7 @@ function runAutomationCLI(importFunction) {
|
|
|
109
109
|
extendTimeoutCallback: async () => {
|
|
110
110
|
if (Date.now() - timeoutTimestamp < throttleTime) return;
|
|
111
111
|
timeoutTimestamp = Date.now();
|
|
112
|
-
|
|
112
|
+
client.sendJSON({
|
|
113
113
|
type: "extend"
|
|
114
114
|
});
|
|
115
115
|
}
|
|
@@ -149,7 +149,7 @@ function runAutomationCLI(importFunction) {
|
|
|
149
149
|
break;
|
|
150
150
|
}
|
|
151
151
|
if (message.type === "error") {
|
|
152
|
-
|
|
152
|
+
client.sendJSON({
|
|
153
153
|
type: "done",
|
|
154
154
|
result: message.error.json,
|
|
155
155
|
success: false
|
|
@@ -157,7 +157,7 @@ function runAutomationCLI(importFunction) {
|
|
|
157
157
|
break;
|
|
158
158
|
}
|
|
159
159
|
if (message.type === "ping") {
|
|
160
|
-
|
|
160
|
+
client.sendJSON({
|
|
161
161
|
type: "pong"
|
|
162
162
|
});
|
|
163
163
|
break;
|
|
@@ -171,7 +171,7 @@ function runAutomationCLI(importFunction) {
|
|
|
171
171
|
} = messageOrResult;
|
|
172
172
|
const success = result.isOk();
|
|
173
173
|
const resultToSend = success ? result.value : result.error.json;
|
|
174
|
-
|
|
174
|
+
client.sendJSON({
|
|
175
175
|
type: "done",
|
|
176
176
|
result: resultToSend,
|
|
177
177
|
success
|
|
@@ -179,8 +179,7 @@ function runAutomationCLI(importFunction) {
|
|
|
179
179
|
break;
|
|
180
180
|
}
|
|
181
181
|
if (!client.closed) {
|
|
182
|
-
client.
|
|
183
|
-
await Promise.race([new Promise(resolve => client.once("close", resolve)), new Promise(resolve => client.once("error", resolve)), (0, _promises.setTimeout)(3000)]);
|
|
182
|
+
await client.close();
|
|
184
183
|
}
|
|
185
184
|
process.exit(0);
|
|
186
185
|
});
|
|
@@ -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
|
|
@@ -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-jsonl.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",
|