@imwz/wp-pattern-sentinel 0.2.3 → 0.2.4
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/package.json +1 -1
- package/src/main.js +17 -12
package/package.json
CHANGED
package/src/main.js
CHANGED
|
@@ -30,20 +30,25 @@ export async function main() {
|
|
|
30
30
|
args: ['--disable-web-security'],
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
//
|
|
33
|
+
// Login once, then share the session cookies across all worker contexts.
|
|
34
|
+
// Concurrent logins to WordPress (even with valid credentials) trigger a
|
|
35
|
+
// reauth=1 redirect loop — serialising login avoids this entirely.
|
|
34
36
|
let contexts;
|
|
35
37
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
const firstContext = await browser.newContext({ viewport: options.viewport });
|
|
39
|
+
const loginPage = await firstContext.newPage();
|
|
40
|
+
loginPage.setDefaultTimeout(60000);
|
|
41
|
+
const ok = await loginToWordPress(loginPage, options.adminUrl, options.user, options.pass);
|
|
42
|
+
await loginPage.close();
|
|
43
|
+
if (!ok) throw new Error('Failed to authenticate with WordPress');
|
|
44
|
+
|
|
45
|
+
const cookies = await firstContext.cookies();
|
|
46
|
+
contexts = [firstContext];
|
|
47
|
+
for (let i = 1; i < options.concurrency; i++) {
|
|
48
|
+
const ctx = await browser.newContext({ viewport: options.viewport });
|
|
49
|
+
await ctx.addCookies(cookies);
|
|
50
|
+
contexts.push(ctx);
|
|
51
|
+
}
|
|
47
52
|
} catch (error) {
|
|
48
53
|
log(error.message, 'red');
|
|
49
54
|
await browser.close();
|