@empiricalrun/playwright-utils 0.40.0 → 0.40.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.
- package/CHANGELOG.md +12 -0
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +34 -23
- package/dist/captcha/index.js +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @empiricalrun/playwright-utils
|
|
2
2
|
|
|
3
|
+
## 0.40.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d40f308: fix: auth store does not load storage state for logged in cases
|
|
8
|
+
|
|
9
|
+
## 0.40.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 644366a: fix: incorrect types
|
|
14
|
+
|
|
3
15
|
## 0.40.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare class AuthStore<T extends WithKey<{}>> {
|
|
|
26
26
|
static getValueFromAuthState(userContext: {
|
|
27
27
|
key: string;
|
|
28
28
|
}, query: QueryFilter): string | undefined;
|
|
29
|
-
private
|
|
29
|
+
private loadAuthStateIntoPage;
|
|
30
30
|
private saveAuthState;
|
|
31
31
|
static location(userContext: {
|
|
32
32
|
key: string;
|
package/dist/auth/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAI5D,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,KAAK,OAAO,GAAG,SAAS,GAAG,kBAAkB,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1B,OAAO,EAAE,cAAc,EACvB,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC;CAoB5B"}
|
package/dist/auth/index.js
CHANGED
|
@@ -30,22 +30,18 @@ class AuthStore {
|
|
|
30
30
|
shouldDoLogin = true;
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
|
|
33
|
+
// Load cached auth state into this.page's context so the check
|
|
34
|
+
// and any subsequent caller code all operate on the same page.
|
|
35
|
+
await this.loadAuthStateIntoPage(this.page, storagePath);
|
|
34
36
|
try {
|
|
35
|
-
const methodResult = await this.checkLoggedInFunc(page, this.userContext);
|
|
37
|
+
const methodResult = await this.checkLoggedInFunc(this.page, this.userContext);
|
|
36
38
|
if (methodResult) {
|
|
37
|
-
|
|
38
|
-
// where we have loaded the auth state
|
|
39
|
-
loggedInPage = page;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
await page.close();
|
|
39
|
+
loggedInPage = this.page;
|
|
43
40
|
}
|
|
44
41
|
shouldDoLogin = !methodResult;
|
|
45
42
|
}
|
|
46
43
|
catch {
|
|
47
44
|
shouldDoLogin = true;
|
|
48
|
-
await page.close();
|
|
49
45
|
}
|
|
50
46
|
}
|
|
51
47
|
if (shouldDoLogin) {
|
|
@@ -78,24 +74,39 @@ class AuthStore {
|
|
|
78
74
|
}
|
|
79
75
|
}
|
|
80
76
|
}
|
|
81
|
-
async
|
|
77
|
+
async loadAuthStateIntoPage(page, storagePath) {
|
|
82
78
|
if (this.appType === "web-app") {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
const authState = JSON.parse(fs_1.default.readFileSync(storagePath, "utf-8"));
|
|
80
|
+
if (authState.cookies?.length) {
|
|
81
|
+
await page.context().addCookies(authState.cookies);
|
|
82
|
+
}
|
|
83
|
+
if (authState.origins?.length) {
|
|
84
|
+
// Use a temporary page to set localStorage without navigating
|
|
85
|
+
// the caller's page away from its current URL
|
|
86
|
+
const tmp = await page.context().newPage();
|
|
87
|
+
try {
|
|
88
|
+
for (const origin of authState.origins) {
|
|
89
|
+
if (!origin.localStorage?.length)
|
|
90
|
+
continue;
|
|
91
|
+
await tmp.goto(origin.origin, {
|
|
92
|
+
waitUntil: "domcontentloaded",
|
|
93
|
+
});
|
|
94
|
+
await tmp.evaluate((items) => {
|
|
95
|
+
localStorage.clear();
|
|
96
|
+
for (const item of items) {
|
|
97
|
+
localStorage.setItem(item.name, item.value);
|
|
98
|
+
}
|
|
99
|
+
}, origin.localStorage);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
await tmp.close();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
90
106
|
}
|
|
91
107
|
else if (this.appType === "chrome-extension") {
|
|
92
|
-
|
|
93
|
-
// existing browser context
|
|
94
|
-
const context = page.context();
|
|
95
|
-
await AuthStore.loadStateForCrx(context, this.userContext);
|
|
96
|
-
return await context.newPage();
|
|
108
|
+
await AuthStore.loadStateForCrx(page.context(), this.userContext);
|
|
97
109
|
}
|
|
98
|
-
throw new Error(`unable to load auth state for app type: ${this.appType}`);
|
|
99
110
|
}
|
|
100
111
|
async saveAuthState(storagePath) {
|
|
101
112
|
if (this.appType === "web-app") {
|
package/dist/captcha/index.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.solveRecaptcha = solveRecaptcha;
|
|
7
7
|
const dashboard_client_1 = require("@empiricalrun/dashboard-client");
|
|
8
8
|
const puppeteer_extra_plugin_recaptcha_1 = __importDefault(require("puppeteer-extra-plugin-recaptcha"));
|
|
9
|
-
const POLLING_INTERVAL =
|
|
10
|
-
const MAX_POLLING_TIME =
|
|
9
|
+
const POLLING_INTERVAL = 10_000;
|
|
10
|
+
const MAX_POLLING_TIME = 300_000;
|
|
11
11
|
function buildTask(captcha) {
|
|
12
12
|
const taskType = captcha._vendor === "hcaptcha"
|
|
13
13
|
? "HCaptchaTaskProxyless"
|
|
@@ -65,7 +65,7 @@ async function solveSingleViaProxy(apiClient, captcha) {
|
|
|
65
65
|
body: { endpoint: "/getTaskResult", body: { taskId } },
|
|
66
66
|
});
|
|
67
67
|
assertNoError(result);
|
|
68
|
-
if (result.status ===
|
|
68
|
+
if (result.status === "ready" && result.solution) {
|
|
69
69
|
const token = result.solution.gRecaptchaResponse || result.solution.token;
|
|
70
70
|
if (token) {
|
|
71
71
|
solution.text = token;
|