@intuned/runtime-dev 1.2.1-hooks.0 → 1.2.1-hooks.2
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.
|
@@ -33,10 +33,18 @@ async function createUserDirWithPreferences() {
|
|
|
33
33
|
await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
|
|
34
34
|
return userDir;
|
|
35
35
|
}
|
|
36
|
-
async function
|
|
37
|
-
|
|
36
|
+
async function loadInitializeContextHook(importFunction) {
|
|
37
|
+
console.log("Loading initializeContext hook");
|
|
38
|
+
const result = await importFunction("hooks/initializeContext");
|
|
39
|
+
console.log({
|
|
40
|
+
result
|
|
41
|
+
});
|
|
38
42
|
if (result.isErr()) {
|
|
39
|
-
|
|
43
|
+
if (result.error.type === "not_found") {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
console.error("Error loading initializeBrowser hook");
|
|
47
|
+
throw result.error.error;
|
|
40
48
|
}
|
|
41
49
|
return result.value.default;
|
|
42
50
|
}
|
|
@@ -51,13 +59,14 @@ async function getProductionPlaywrightConstructs({
|
|
|
51
59
|
let page;
|
|
52
60
|
let hook = null;
|
|
53
61
|
if (importFunction) {
|
|
54
|
-
hook = await
|
|
62
|
+
hook = await loadInitializeContextHook(importFunction);
|
|
55
63
|
}
|
|
56
64
|
if (hook) {
|
|
57
65
|
({
|
|
58
66
|
page,
|
|
59
67
|
context
|
|
60
68
|
} = await hook({
|
|
69
|
+
type: "launch",
|
|
61
70
|
proxy,
|
|
62
71
|
headless
|
|
63
72
|
}));
|
|
@@ -108,27 +117,23 @@ async function getProductionPlaywrightConstructs({
|
|
|
108
117
|
context
|
|
109
118
|
};
|
|
110
119
|
}
|
|
111
|
-
async function loadGetIDEPageAndContextHook(importFunction) {
|
|
112
|
-
const result = await importFunction("hooks/createDeployedContextAndPage");
|
|
113
|
-
if (result.isErr()) {
|
|
114
|
-
throw result.error;
|
|
115
|
-
}
|
|
116
|
-
return result.value.default;
|
|
117
|
-
}
|
|
118
120
|
async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession, importFunction) {
|
|
119
121
|
let hook = null;
|
|
120
122
|
if (importFunction) {
|
|
121
|
-
hook = await
|
|
123
|
+
hook = await loadInitializeContextHook(importFunction);
|
|
122
124
|
}
|
|
123
125
|
if (mode == "playwright-standalone") {
|
|
124
126
|
if (!cdpAddress) {
|
|
125
127
|
throw new Error("cdpAddress is required");
|
|
126
128
|
}
|
|
127
129
|
let context;
|
|
130
|
+
let page = null;
|
|
128
131
|
if (hook) {
|
|
129
132
|
({
|
|
130
|
-
context
|
|
133
|
+
context,
|
|
134
|
+
page
|
|
131
135
|
} = await hook({
|
|
136
|
+
type: "cdp",
|
|
132
137
|
cdpAddress
|
|
133
138
|
}));
|
|
134
139
|
} else {
|
|
@@ -143,14 +148,15 @@ async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession, imp
|
|
|
143
148
|
await context.addInitScript({
|
|
144
149
|
path: assetsFile
|
|
145
150
|
});
|
|
146
|
-
const pages =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
const pages = context.pages();
|
|
152
|
+
if (!page) {
|
|
153
|
+
if (pages.length > 0) {
|
|
154
|
+
page = pages[0];
|
|
155
|
+
const scriptString = await fs.readFile(assetsFile, "utf8");
|
|
156
|
+
await page.evaluate(scriptString);
|
|
157
|
+
} else {
|
|
158
|
+
page = await context.newPage();
|
|
159
|
+
}
|
|
154
160
|
}
|
|
155
161
|
if (authSession) {
|
|
156
162
|
await loadSessionToContext({
|