@letsscrapedata/controller 0.0.65 → 0.0.67
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/index.cjs +259 -222
- package/dist/index.d.cts +37 -2
- package/dist/index.d.ts +37 -2
- package/dist/index.js +255 -222
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
// src/types/types.ts
|
|
2
|
+
var ControllerEvent = /* @__PURE__ */ ((ControllerEvent2) => {
|
|
3
|
+
ControllerEvent2["BROWSERCONTEXT_CLOSE"] = "close";
|
|
4
|
+
ControllerEvent2["BROWSERCONTEXT_PAGE"] = "page";
|
|
5
|
+
ControllerEvent2["BROWSERCONTEXT_TARGETCREATED"] = "targetcreated";
|
|
6
|
+
ControllerEvent2["BROWSER_DISCONNECTED"] = "disconnected";
|
|
7
|
+
ControllerEvent2["PAGE_CLOSE"] = "close";
|
|
8
|
+
ControllerEvent2["PAGE_POUP"] = "popup";
|
|
9
|
+
ControllerEvent2["PAGE_REQUEST"] = "request";
|
|
10
|
+
ControllerEvent2["PAGE_RESPONSE"] = "response";
|
|
11
|
+
return ControllerEvent2;
|
|
12
|
+
})(ControllerEvent || {});
|
|
13
|
+
var LsdPageEvent = /* @__PURE__ */ ((LsdPageEvent2) => {
|
|
14
|
+
LsdPageEvent2["PAGE_CLOSE"] = "pageClose";
|
|
15
|
+
LsdPageEvent2["PAGE_POPUP"] = "pagePopup";
|
|
16
|
+
return LsdPageEvent2;
|
|
17
|
+
})(LsdPageEvent || {});
|
|
18
|
+
var LsdBrowserContextEvent = /* @__PURE__ */ ((LsdBrowserContextEvent2) => {
|
|
19
|
+
LsdBrowserContextEvent2["PAGE_CLOSE"] = "pageClose";
|
|
20
|
+
return LsdBrowserContextEvent2;
|
|
21
|
+
})(LsdBrowserContextEvent || {});
|
|
22
|
+
var LsdBrowserEvent = /* @__PURE__ */ ((LsdBrowserEvent2) => {
|
|
23
|
+
LsdBrowserEvent2["BROWSER_CONTEXT_CLOSE"] = "browserContextClose";
|
|
24
|
+
return LsdBrowserEvent2;
|
|
25
|
+
})(LsdBrowserEvent || {});
|
|
26
|
+
|
|
1
27
|
// src/utils/log.ts
|
|
2
28
|
import { log, LogLevel } from "@letsscrapedata/utils";
|
|
3
29
|
var pkgLog = log;
|
|
@@ -9,6 +35,9 @@ function setControllerLogFun(logFun) {
|
|
|
9
35
|
return false;
|
|
10
36
|
}
|
|
11
37
|
}
|
|
38
|
+
async function logdbg(...args) {
|
|
39
|
+
await pkgLog(LogLevel.DBG, ...args);
|
|
40
|
+
}
|
|
12
41
|
async function loginfo(...args) {
|
|
13
42
|
await pkgLog(LogLevel.INF, ...args);
|
|
14
43
|
}
|
|
@@ -372,7 +401,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
372
401
|
const cookieItems = await this.#getCookies(page);
|
|
373
402
|
const domainSet = new Set(cookieItems.map((c) => c.domain));
|
|
374
403
|
if (domainSet.size !== 1) {
|
|
375
|
-
logwarn(
|
|
404
|
+
logwarn(`##browser LsdPage domains in clearCookies: ${Array.from(domainSet.values())}`);
|
|
376
405
|
}
|
|
377
406
|
for (const domain of domainSet.values()) {
|
|
378
407
|
await browserContext.clearCookies({ domain });
|
|
@@ -578,15 +607,15 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
578
607
|
}
|
|
579
608
|
const page = this.#page;
|
|
580
609
|
const pageId = this.#pageId;
|
|
581
|
-
page.on("close"
|
|
582
|
-
loginfo(`##browser
|
|
610
|
+
page.on("close" /* PAGE_CLOSE */, async () => {
|
|
611
|
+
loginfo(`##browser page ${pageId} closed @LsdPage`);
|
|
583
612
|
if (!page.pageInfo) {
|
|
584
|
-
logerr(
|
|
613
|
+
logerr(`##browser LsdPage logic error in page.on("close")`);
|
|
585
614
|
}
|
|
586
|
-
this.emit("pageClose");
|
|
587
|
-
this.#lsdBrowserContext.emit("pageClose"
|
|
615
|
+
this.emit("pageClose" /* PAGE_CLOSE */);
|
|
616
|
+
this.#lsdBrowserContext.emit("pageClose" /* PAGE_CLOSE */, this);
|
|
588
617
|
});
|
|
589
|
-
page.on("popup"
|
|
618
|
+
page.on("popup" /* PAGE_POUP */, (p) => {
|
|
590
619
|
if (p) {
|
|
591
620
|
let evtData = null;
|
|
592
621
|
const pageInfo = p.pageInfo;
|
|
@@ -600,12 +629,12 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
600
629
|
pageInfo.relatedId = page.pageInfo.taskId;
|
|
601
630
|
}
|
|
602
631
|
} else {
|
|
603
|
-
logerr(`##browser
|
|
632
|
+
logerr(`##browser page ${pageId} has popup without page.pageInfo @LsdPage`);
|
|
604
633
|
}
|
|
605
|
-
loginfo(`##browser
|
|
606
|
-
this.emit("pagePopup"
|
|
634
|
+
loginfo(`##browser page ${pageId} has popup ${popupPageId} @LsdPage`);
|
|
635
|
+
this.emit("pagePopup" /* PAGE_POPUP */, evtData);
|
|
607
636
|
} else {
|
|
608
|
-
logerr(`##browser ${pageId} has popup page with null page`);
|
|
637
|
+
logerr(`##browser page ${pageId} has popup page with null page @LsdPage`);
|
|
609
638
|
}
|
|
610
639
|
});
|
|
611
640
|
}
|
|
@@ -620,13 +649,14 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
620
649
|
const currentTime = getCurrentUnixTime();
|
|
621
650
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
622
651
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
623
|
-
this.#pageId = `
|
|
652
|
+
this.#pageId = `PlaywrightPage-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
624
653
|
this.#closeWhenFree = false;
|
|
625
654
|
this.#resquestInterceptionOptions = [];
|
|
626
655
|
this.#responseInterceptionOptions = [];
|
|
627
656
|
this.#client = null;
|
|
628
657
|
this.#responseCb = null;
|
|
629
658
|
this.#isDebugTask = false;
|
|
659
|
+
loginfo(`##browser LsdPage ${this.#pageId} ${openType}ed`);
|
|
630
660
|
this.#addPageOn();
|
|
631
661
|
}
|
|
632
662
|
async addPreloadScript(scriptOrFunc, arg) {
|
|
@@ -707,7 +737,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
707
737
|
}
|
|
708
738
|
async close() {
|
|
709
739
|
if (this.#status === "closed") {
|
|
710
|
-
logwarn(
|
|
740
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already closed.`);
|
|
711
741
|
return true;
|
|
712
742
|
} else if (this.#status === "busy") {
|
|
713
743
|
throw new Error(`Page ${this.#pageId} cannot be closed because it is busy.`);
|
|
@@ -718,6 +748,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
718
748
|
await this.#page.close();
|
|
719
749
|
this.#page = null;
|
|
720
750
|
this.#status = "closed";
|
|
751
|
+
loginfo(`##browser LsdPage ${this.#pageId} is closed`);
|
|
721
752
|
return true;
|
|
722
753
|
}
|
|
723
754
|
closeWhenFree() {
|
|
@@ -802,10 +833,11 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
802
833
|
return [];
|
|
803
834
|
}
|
|
804
835
|
async free() {
|
|
805
|
-
if (this.#status === "free") {
|
|
806
|
-
logwarn(
|
|
836
|
+
if (this.#status === "free" && this.pageInfo().openType !== "popup") {
|
|
837
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already free.`);
|
|
807
838
|
}
|
|
808
839
|
this.#status = "free";
|
|
840
|
+
logdbg(`##browser LsdPage ${this.#pageId} is freed`);
|
|
809
841
|
await this.clearRequestInterceptions();
|
|
810
842
|
await this.clearResponseInterceptions();
|
|
811
843
|
return true;
|
|
@@ -1087,7 +1119,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
1087
1119
|
}
|
|
1088
1120
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
1089
1121
|
if (actOptions.length <= 0) {
|
|
1090
|
-
logwarn("
|
|
1122
|
+
logwarn("##browser LsdPage invalid paras in setRequestInterception");
|
|
1091
1123
|
return false;
|
|
1092
1124
|
}
|
|
1093
1125
|
const firstRequestInterception = this.#resquestInterceptionOptions.length <= 0;
|
|
@@ -1110,9 +1142,9 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
1110
1142
|
const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
1111
1143
|
if (this.#isDebugTask) {
|
|
1112
1144
|
if (matchedFlag) {
|
|
1113
|
-
|
|
1145
|
+
loginfo(`##browser matched request ${request.method()} ${request.url()}`);
|
|
1114
1146
|
} else {
|
|
1115
|
-
|
|
1147
|
+
logdbg(`##browser unmatched request ${request.method()} ${request.url()}`);
|
|
1116
1148
|
}
|
|
1117
1149
|
}
|
|
1118
1150
|
if (matchedFlag) {
|
|
@@ -1168,9 +1200,9 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
1168
1200
|
}
|
|
1169
1201
|
if (this.#isDebugTask) {
|
|
1170
1202
|
if (matchedFlag) {
|
|
1171
|
-
|
|
1203
|
+
loginfo(`##browser matched response ${request.method()} ${request.url()}`);
|
|
1172
1204
|
} else {
|
|
1173
|
-
|
|
1205
|
+
logdbg(`##browser unmatched response ${request.method()} ${request.url()}`);
|
|
1174
1206
|
}
|
|
1175
1207
|
}
|
|
1176
1208
|
if (!matchedFlag) {
|
|
@@ -1208,7 +1240,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
1208
1240
|
}
|
|
1209
1241
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
1210
1242
|
if (actOptions.length <= 0) {
|
|
1211
|
-
logwarn("
|
|
1243
|
+
logwarn("##browser LsdPage invalid paras in setResponseInterception");
|
|
1212
1244
|
return false;
|
|
1213
1245
|
}
|
|
1214
1246
|
const firstResponseInterception = this.#responseInterceptionOptions.length <= 0;
|
|
@@ -1221,7 +1253,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
1221
1253
|
}
|
|
1222
1254
|
if (firstResponseInterception && this.#responseInterceptionOptions.length > 0) {
|
|
1223
1255
|
this.#responseCb = this.#responseListener.bind(this);
|
|
1224
|
-
this.#page.on("response"
|
|
1256
|
+
this.#page.on("response" /* PAGE_RESPONSE */, this.#responseCb);
|
|
1225
1257
|
}
|
|
1226
1258
|
return true;
|
|
1227
1259
|
}
|
|
@@ -1269,6 +1301,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
1269
1301
|
throw new Error(`Page ${this.#pageId} is already busy!!!`);
|
|
1270
1302
|
}
|
|
1271
1303
|
this.#status = "busy";
|
|
1304
|
+
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
1272
1305
|
return true;
|
|
1273
1306
|
}
|
|
1274
1307
|
async waitForElement(selector, options = {}) {
|
|
@@ -1407,11 +1440,10 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1407
1440
|
for (const page of pages) {
|
|
1408
1441
|
const pageInfo = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType, openTime: this.#createTime, lastStatusUpdateTime, taskId: 0, relatedId: 0, misc: {} };
|
|
1409
1442
|
const lsdPage = new PlaywrightPage(this, page, pageInfo);
|
|
1443
|
+
this.#lsdPages.push(lsdPage);
|
|
1410
1444
|
if (this.#maxViewportOfNewPage) {
|
|
1411
1445
|
await lsdPage.maximizeViewport();
|
|
1412
1446
|
}
|
|
1413
|
-
this.#lsdPages.push(lsdPage);
|
|
1414
|
-
loginfo(`##browser ${lsdPage.id()} ${openType}ed`);
|
|
1415
1447
|
}
|
|
1416
1448
|
}
|
|
1417
1449
|
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, maxViewportOfNewPage = true) {
|
|
@@ -1441,8 +1473,9 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1441
1473
|
this.#lsdPages = [];
|
|
1442
1474
|
this.#nextPageIdx = 1;
|
|
1443
1475
|
this.#gettingPage = false;
|
|
1476
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} is created`);
|
|
1444
1477
|
this.#initPages();
|
|
1445
|
-
browserContext.on("page"
|
|
1478
|
+
browserContext.on("page" /* BROWSERCONTEXT_PAGE */, async (page) => {
|
|
1446
1479
|
const pageInfo = page.pageInfo;
|
|
1447
1480
|
if (pageInfo) {
|
|
1448
1481
|
const { browserIdx: browserIdx2, browserContextIdx: browserContextIdx2, pageIdx } = pageInfo;
|
|
@@ -1451,27 +1484,26 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1451
1484
|
const currentTime2 = getCurrentUnixTime2();
|
|
1452
1485
|
const pageInfo2 = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType: "other", openTime: currentTime2, lastStatusUpdateTime: currentTime2, taskId: 0, relatedId: 0, misc: {} };
|
|
1453
1486
|
const lsdPage = new PlaywrightPage(this, page, pageInfo2);
|
|
1487
|
+
this.#lsdPages.push(lsdPage);
|
|
1454
1488
|
if (this.#maxViewportOfNewPage) {
|
|
1455
1489
|
await lsdPage.maximizeViewport();
|
|
1456
1490
|
}
|
|
1457
|
-
this.#lsdPages.push(lsdPage);
|
|
1458
|
-
loginfo(`##page ${lsdPage.id()} created`);
|
|
1459
1491
|
}
|
|
1460
1492
|
});
|
|
1461
|
-
browserContext.on("close"
|
|
1493
|
+
browserContext.on("close" /* BROWSERCONTEXT_CLOSE */, (bc) => {
|
|
1462
1494
|
if (browserContext !== bc) {
|
|
1463
1495
|
logerr(`##browser different browserContext in browserContext.on("close")`);
|
|
1464
1496
|
}
|
|
1465
|
-
this.#lsdBrowser.emit("browserContextClose"
|
|
1497
|
+
this.#lsdBrowser.emit("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, this);
|
|
1466
1498
|
});
|
|
1467
|
-
this.on("pageClose"
|
|
1499
|
+
this.on("pageClose" /* PAGE_CLOSE */, (lsdPage) => {
|
|
1468
1500
|
if (!(lsdPage instanceof PlaywrightPage)) {
|
|
1469
|
-
logerr(
|
|
1501
|
+
logerr(`##browser LsdBrowserContext invalid data in LsdBrowserContext.on("pageClose)`);
|
|
1470
1502
|
return;
|
|
1471
1503
|
}
|
|
1472
1504
|
const idx = this.#lsdPages.findIndex((p) => p === lsdPage);
|
|
1473
1505
|
if (idx < 0) {
|
|
1474
|
-
logerr(
|
|
1506
|
+
logerr(`##browser LsdBrowserContext invalid lsdPage in LsdBrowserContext.on("pageClose)`);
|
|
1475
1507
|
return;
|
|
1476
1508
|
}
|
|
1477
1509
|
this.#lsdPages.splice(idx, 1);
|
|
@@ -1488,7 +1520,7 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1488
1520
|
if (this.#browserContext) {
|
|
1489
1521
|
this.#status = "closed";
|
|
1490
1522
|
this.#lastStatusUpdateTime = getCurrentUnixTime2();
|
|
1491
|
-
loginfo(
|
|
1523
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} closed at ${this.#lastStatusUpdateTime}`);
|
|
1492
1524
|
await this.#browserContext.close();
|
|
1493
1525
|
}
|
|
1494
1526
|
return true;
|
|
@@ -1503,12 +1535,12 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1503
1535
|
await sleep(200);
|
|
1504
1536
|
}
|
|
1505
1537
|
}
|
|
1506
|
-
logwarn(
|
|
1538
|
+
logwarn(`##browser LsdBrowserContext cannot get the gettingLock.`);
|
|
1507
1539
|
return false;
|
|
1508
1540
|
}
|
|
1509
1541
|
#freeGettingLock() {
|
|
1510
1542
|
if (!this.#gettingPage) {
|
|
1511
|
-
logwarn(
|
|
1543
|
+
logwarn(`##browser LsdBrowserContext gettingLock is already free now.`);
|
|
1512
1544
|
}
|
|
1513
1545
|
this.#gettingPage = false;
|
|
1514
1546
|
}
|
|
@@ -1517,7 +1549,7 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1517
1549
|
maxPageFreeSeconds = this.#maxPageFreeSeconds;
|
|
1518
1550
|
}
|
|
1519
1551
|
if (maxPageFreeSeconds <= 0) {
|
|
1520
|
-
logwarn(
|
|
1552
|
+
logwarn(`##browser LsdBrowserContext please set valid maxPageFreeSeconds to close free pages`);
|
|
1521
1553
|
return false;
|
|
1522
1554
|
}
|
|
1523
1555
|
const gotLock = await this.#tryToGetGettingLock();
|
|
@@ -1614,7 +1646,7 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1614
1646
|
}
|
|
1615
1647
|
}
|
|
1616
1648
|
id() {
|
|
1617
|
-
return `
|
|
1649
|
+
return `PlaywrightContext-${this.#browserIdx}-${this.#browserContextIdx}`;
|
|
1618
1650
|
}
|
|
1619
1651
|
isFree() {
|
|
1620
1652
|
return this.#status === "free";
|
|
@@ -1748,34 +1780,33 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends EventEmitter3 {
|
|
|
1748
1780
|
this.#executablePath = executablePath;
|
|
1749
1781
|
this.#nextBrowserContextIdx = 1;
|
|
1750
1782
|
this.#closeFreePagesIntervalId = null;
|
|
1751
|
-
loginfo(`##browser ${this.id()} ${this.#browserCreationMethod}ed
|
|
1783
|
+
loginfo(`##browser LsdBrowser ${this.id()} ${this.#browserCreationMethod}ed}`);
|
|
1752
1784
|
const browserContexts = browser.contexts();
|
|
1753
1785
|
if (browserContexts.length > 0) {
|
|
1754
|
-
logwarn(
|
|
1786
|
+
logwarn(`##browser LsdBrowser there are ${browserContexts.length} new browserContexts when playwright launches new browser`);
|
|
1755
1787
|
}
|
|
1756
1788
|
const incognito = typeof options?.incognito === "boolean" ? options.incognito : true;
|
|
1757
1789
|
for (const browserContext of browserContexts) {
|
|
1758
1790
|
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
1759
1791
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
1760
|
-
loginfo(`##browserContext ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
1761
1792
|
}
|
|
1762
|
-
browser.on("disconnected"
|
|
1793
|
+
browser.on("disconnected" /* BROWSER_DISCONNECTED */, () => {
|
|
1763
1794
|
loginfo(`##browser ${this.id()} disconnected`);
|
|
1764
1795
|
if (this.#lsdBrowserContexts.length > 0) {
|
|
1765
|
-
logerr(
|
|
1796
|
+
logerr(`##browser LsdBrowser ${this.id()} has browserContexts when disconnected`);
|
|
1766
1797
|
}
|
|
1767
1798
|
});
|
|
1768
|
-
this.on("browserContextClose"
|
|
1799
|
+
this.on("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, (lsdBrowserContext) => {
|
|
1769
1800
|
if (!(lsdBrowserContext instanceof PlaywrightBrowserContext)) {
|
|
1770
|
-
logerr(
|
|
1801
|
+
logerr(`##browser LsdBrowser invalid data in LsdBrowser.on("browserContextClose)`);
|
|
1771
1802
|
return;
|
|
1772
1803
|
}
|
|
1773
1804
|
const idx = this.#lsdBrowserContexts.findIndex((bc) => bc === lsdBrowserContext);
|
|
1774
1805
|
if (idx < 0) {
|
|
1775
|
-
logerr(
|
|
1806
|
+
logerr(`##browser LsdBrowser invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
1776
1807
|
return;
|
|
1777
1808
|
}
|
|
1778
|
-
loginfo(`##
|
|
1809
|
+
loginfo(`##browser ${lsdBrowserContext.id()} closed
|
|
1779
1810
|
`);
|
|
1780
1811
|
this.#lsdBrowserContexts.splice(idx, 1);
|
|
1781
1812
|
if (this.#lsdBrowserContexts.length === 0) {
|
|
@@ -1796,7 +1827,7 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends EventEmitter3 {
|
|
|
1796
1827
|
}
|
|
1797
1828
|
async newBrowserContext(options) {
|
|
1798
1829
|
if (this.#lsdBrowserContexts.length >= this.#maxBrowserContextsPerBrowser()) {
|
|
1799
|
-
logwarn(`##browser ${this.id()} can not create more new browserContext`);
|
|
1830
|
+
logwarn(`##browser LsdBrowser ${this.id()} can not create more new browserContext`);
|
|
1800
1831
|
return null;
|
|
1801
1832
|
}
|
|
1802
1833
|
const browserContextOptions = {};
|
|
@@ -1815,7 +1846,6 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends EventEmitter3 {
|
|
|
1815
1846
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
1816
1847
|
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
1817
1848
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
1818
|
-
loginfo(`##browser ${lsdBrowserContext.id()} created`);
|
|
1819
1849
|
return lsdBrowserContext;
|
|
1820
1850
|
}
|
|
1821
1851
|
async close() {
|
|
@@ -1826,6 +1856,7 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends EventEmitter3 {
|
|
|
1826
1856
|
await lsdBrowserContext.close();
|
|
1827
1857
|
}
|
|
1828
1858
|
await this.#browser.close();
|
|
1859
|
+
loginfo(`##browser LsdBrowser ${this.id()} is closed`);
|
|
1829
1860
|
return true;
|
|
1830
1861
|
}
|
|
1831
1862
|
browserContexts() {
|
|
@@ -1851,7 +1882,7 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends EventEmitter3 {
|
|
|
1851
1882
|
return this.#executablePath;
|
|
1852
1883
|
}
|
|
1853
1884
|
id() {
|
|
1854
|
-
return `
|
|
1885
|
+
return `PlaywrightBrowser-${this.#browserType}-${this.#browserIdx}`;
|
|
1855
1886
|
}
|
|
1856
1887
|
isConnected() {
|
|
1857
1888
|
return this.#browser.isConnected();
|
|
@@ -2084,7 +2115,6 @@ var PuppeteerElement = class _PuppeteerElement {
|
|
|
2084
2115
|
await this.#$ele.click(actOptions);
|
|
2085
2116
|
} else if (clickType === "evaluate") {
|
|
2086
2117
|
await this.#frame.evaluate(async (ev) => await ev.click(), this.#$ele);
|
|
2087
|
-
await this.#$ele.click(actOptions);
|
|
2088
2118
|
} else {
|
|
2089
2119
|
unreachable3(clickType);
|
|
2090
2120
|
}
|
|
@@ -2387,15 +2417,15 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2387
2417
|
}
|
|
2388
2418
|
const page = this.#page;
|
|
2389
2419
|
const pageId = this.#pageId;
|
|
2390
|
-
page.on("close"
|
|
2391
|
-
loginfo(`##browser
|
|
2420
|
+
page.on("close" /* PAGE_CLOSE */, async () => {
|
|
2421
|
+
loginfo(`##browser page ${pageId} closed @LsdPage`);
|
|
2392
2422
|
if (!page.pageInfo) {
|
|
2393
|
-
logerr(
|
|
2423
|
+
logerr(`##browser LsdPage logic error in page.on("close")`);
|
|
2394
2424
|
}
|
|
2395
|
-
this.emit("pageClose");
|
|
2396
|
-
this.#lsdBrowserContext.emit("pageClose"
|
|
2425
|
+
this.emit("pageClose" /* PAGE_CLOSE */);
|
|
2426
|
+
this.#lsdBrowserContext.emit("pageClose" /* PAGE_CLOSE */, this);
|
|
2397
2427
|
});
|
|
2398
|
-
page.on("popup"
|
|
2428
|
+
page.on("popup" /* PAGE_POUP */, (p) => {
|
|
2399
2429
|
if (p) {
|
|
2400
2430
|
let evtData = null;
|
|
2401
2431
|
const pageInfo = p.pageInfo;
|
|
@@ -2409,12 +2439,12 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2409
2439
|
pageInfo.relatedId = page.pageInfo.taskId;
|
|
2410
2440
|
}
|
|
2411
2441
|
} else {
|
|
2412
|
-
logerr(`##browser
|
|
2442
|
+
logerr(`##browser page ${pageId} has popup without page.pageInfo @LsdPage`);
|
|
2413
2443
|
}
|
|
2414
|
-
loginfo(`##browser
|
|
2415
|
-
this.emit("pagePopup"
|
|
2444
|
+
loginfo(`##browser page ${pageId} has popup ${popupPageId} @LsdPage`);
|
|
2445
|
+
this.emit("pagePopup" /* PAGE_POPUP */, evtData);
|
|
2416
2446
|
} else {
|
|
2417
|
-
logerr(`##browser ${pageId} has popup page with null page`);
|
|
2447
|
+
logerr(`##browser page ${pageId} has popup page with null page @LsdPage`);
|
|
2418
2448
|
}
|
|
2419
2449
|
});
|
|
2420
2450
|
}
|
|
@@ -2429,12 +2459,13 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2429
2459
|
const currentTime = getCurrentUnixTime4();
|
|
2430
2460
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
2431
2461
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
2432
|
-
this.#pageId = `
|
|
2462
|
+
this.#pageId = `PuppeteerPage-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
2433
2463
|
this.#closeWhenFree = false;
|
|
2434
2464
|
this.#requestInterceptionNum = 0;
|
|
2435
2465
|
this.#responseInterceptionNum = 0;
|
|
2436
2466
|
this.#client = null;
|
|
2437
2467
|
this.#isDebugTask = false;
|
|
2468
|
+
loginfo(`##browser LsdPage ${this.#pageId} ${openType}ed`);
|
|
2438
2469
|
this.#addPageOn();
|
|
2439
2470
|
}
|
|
2440
2471
|
async addPreloadScript(scriptOrFunc, arg) {
|
|
@@ -2512,7 +2543,7 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2512
2543
|
}
|
|
2513
2544
|
async close() {
|
|
2514
2545
|
if (this.#status === "closed") {
|
|
2515
|
-
logwarn(
|
|
2546
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already closed.`);
|
|
2516
2547
|
return true;
|
|
2517
2548
|
} else if (this.#status === "busy") {
|
|
2518
2549
|
throw new Error(`Page ${this.#pageId} cannot be closed because it is busy.`);
|
|
@@ -2523,6 +2554,7 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2523
2554
|
await this.#page.close();
|
|
2524
2555
|
this.#page = null;
|
|
2525
2556
|
this.#status = "closed";
|
|
2557
|
+
loginfo(`##browser LsdPage ${this.#pageId} is closed`);
|
|
2526
2558
|
return true;
|
|
2527
2559
|
}
|
|
2528
2560
|
closeWhenFree() {
|
|
@@ -2607,10 +2639,11 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2607
2639
|
return [];
|
|
2608
2640
|
}
|
|
2609
2641
|
async free() {
|
|
2610
|
-
if (this.#status === "free") {
|
|
2611
|
-
logwarn(
|
|
2642
|
+
if (this.#status === "free" && this.pageInfo().openType !== "popup") {
|
|
2643
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already free.`);
|
|
2612
2644
|
}
|
|
2613
2645
|
this.#status = "free";
|
|
2646
|
+
logdbg(`##browser LsdPage ${this.#pageId} is freed`);
|
|
2614
2647
|
await this.clearRequestInterceptions();
|
|
2615
2648
|
await this.clearResponseInterceptions();
|
|
2616
2649
|
return true;
|
|
@@ -2894,7 +2927,7 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2894
2927
|
}
|
|
2895
2928
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
2896
2929
|
if (actOptions.length <= 0) {
|
|
2897
|
-
logwarn("
|
|
2930
|
+
logwarn("##browser LsdPage invalid paras in setRequestInterception");
|
|
2898
2931
|
return false;
|
|
2899
2932
|
}
|
|
2900
2933
|
if (this.#requestInterceptionNum <= 0) {
|
|
@@ -2903,16 +2936,16 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2903
2936
|
} else {
|
|
2904
2937
|
this.#requestInterceptionNum++;
|
|
2905
2938
|
}
|
|
2906
|
-
this.#page.on("request"
|
|
2939
|
+
this.#page.on("request" /* PAGE_REQUEST */, async (request) => {
|
|
2907
2940
|
try {
|
|
2908
2941
|
for (const option of actOptions) {
|
|
2909
2942
|
const { requestMatch, action, fulfill } = option;
|
|
2910
2943
|
const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
2911
2944
|
if (this.#isDebugTask) {
|
|
2912
2945
|
if (matchedFlag) {
|
|
2913
|
-
|
|
2946
|
+
loginfo(`##browser matched request ${request.method()} ${request.url()}`);
|
|
2914
2947
|
} else {
|
|
2915
|
-
|
|
2948
|
+
logdbg(`##browser unmatched request ${request.method()} ${request.url()}`);
|
|
2916
2949
|
}
|
|
2917
2950
|
}
|
|
2918
2951
|
if (matchedFlag) {
|
|
@@ -2949,11 +2982,11 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2949
2982
|
}
|
|
2950
2983
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
2951
2984
|
if (actOptions.length <= 0) {
|
|
2952
|
-
logwarn("
|
|
2985
|
+
logwarn("##browser LsdPage invalid paras in setResponseInterception");
|
|
2953
2986
|
return false;
|
|
2954
2987
|
}
|
|
2955
2988
|
this.#responseInterceptionNum++;
|
|
2956
|
-
this.#page.on("response"
|
|
2989
|
+
this.#page.on("response" /* PAGE_RESPONSE */, async (response) => {
|
|
2957
2990
|
try {
|
|
2958
2991
|
if (!response.ok() || !this.#page) {
|
|
2959
2992
|
return false;
|
|
@@ -2976,9 +3009,9 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2976
3009
|
}
|
|
2977
3010
|
if (this.#isDebugTask) {
|
|
2978
3011
|
if (matchedFlag) {
|
|
2979
|
-
|
|
3012
|
+
loginfo(`##browser matched response ${request.method()} ${request.url()}`);
|
|
2980
3013
|
} else {
|
|
2981
|
-
|
|
3014
|
+
logdbg(`##browser unmatched response ${request.method()} ${request.url()}`);
|
|
2982
3015
|
}
|
|
2983
3016
|
}
|
|
2984
3017
|
if (!matchedFlag) {
|
|
@@ -2997,6 +3030,7 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2997
3030
|
requestData,
|
|
2998
3031
|
responseData
|
|
2999
3032
|
});
|
|
3033
|
+
loginfo(`##browser cache matched response: ${requestUrl}`);
|
|
3000
3034
|
}
|
|
3001
3035
|
if (typeof handler === "function") {
|
|
3002
3036
|
const pageData = { pageUrl, cookies: "" };
|
|
@@ -3062,6 +3096,7 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
3062
3096
|
throw new Error(`Page ${this.#pageId} is already busy!!!`);
|
|
3063
3097
|
}
|
|
3064
3098
|
this.#status = "busy";
|
|
3099
|
+
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
3065
3100
|
return true;
|
|
3066
3101
|
}
|
|
3067
3102
|
async waitForElement(selector, options = {}) {
|
|
@@ -3172,14 +3207,13 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
3172
3207
|
for (const page of pages) {
|
|
3173
3208
|
const pageInfo = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType, openTime: this.#createTime, lastStatusUpdateTime, taskId: 0, relatedId: 0, misc: {} };
|
|
3174
3209
|
const lsdPage = new PuppeteerPage(this, page, pageInfo);
|
|
3210
|
+
this.#lsdPages.push(lsdPage);
|
|
3175
3211
|
if (this.#maxViewportOfNewPage) {
|
|
3176
3212
|
await lsdPage.maximizeViewport();
|
|
3177
3213
|
}
|
|
3178
3214
|
if (this.#userAgent) {
|
|
3179
3215
|
await lsdPage.setUserAgent(this.#userAgent);
|
|
3180
3216
|
}
|
|
3181
|
-
this.#lsdPages.push(lsdPage);
|
|
3182
|
-
loginfo(`##browser ${lsdPage.id()} ${openType}ed`);
|
|
3183
3217
|
}
|
|
3184
3218
|
}
|
|
3185
3219
|
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, userAgent = "", maxViewportOfNewPage = true) {
|
|
@@ -3208,8 +3242,9 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
3208
3242
|
this.#lsdPages = [];
|
|
3209
3243
|
this.#nextPageIdx = 1;
|
|
3210
3244
|
this.#gettingPage = false;
|
|
3245
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} is created`);
|
|
3211
3246
|
this.#initPages();
|
|
3212
|
-
browserContext.on("targetcreated"
|
|
3247
|
+
browserContext.on("targetcreated" /* BROWSERCONTEXT_TARGETCREATED */, async (p) => {
|
|
3213
3248
|
if (p.type() === "page") {
|
|
3214
3249
|
const page = await p.page();
|
|
3215
3250
|
if (!page) {
|
|
@@ -3223,30 +3258,36 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
3223
3258
|
const currentTime2 = getCurrentUnixTime5();
|
|
3224
3259
|
const pageInfo2 = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType: "other", openTime: currentTime2, lastStatusUpdateTime: currentTime2, taskId: 0, relatedId: 0, misc: {} };
|
|
3225
3260
|
const lsdPage = new PuppeteerPage(this, page, pageInfo2);
|
|
3226
|
-
|
|
3227
|
-
await lsdPage.maximizeViewport();
|
|
3228
|
-
}
|
|
3261
|
+
this.#lsdPages.push(lsdPage);
|
|
3229
3262
|
if (this.#userAgent) {
|
|
3230
3263
|
await lsdPage.setUserAgent(this.#userAgent);
|
|
3231
3264
|
}
|
|
3232
|
-
this.#
|
|
3233
|
-
|
|
3265
|
+
if (this.#maxViewportOfNewPage) {
|
|
3266
|
+
await lsdPage.maximizeViewport();
|
|
3267
|
+
}
|
|
3234
3268
|
}
|
|
3235
3269
|
}
|
|
3236
3270
|
});
|
|
3237
|
-
|
|
3271
|
+
browserContext.on("close" /* BROWSERCONTEXT_CLOSE */, (bc) => {
|
|
3272
|
+
logerr(`##browser LsdBrowserContext puppeteer BrowserContext receives close event`);
|
|
3273
|
+
if (browserContext !== bc) {
|
|
3274
|
+
logerr(`##browser LsdBrowserContext different browserContext in browserContext.on("close")`);
|
|
3275
|
+
}
|
|
3276
|
+
this.#lsdBrowser.emit("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, this);
|
|
3277
|
+
});
|
|
3278
|
+
this.on("pageClose" /* PAGE_CLOSE */, (lsdPage) => {
|
|
3238
3279
|
if (!(lsdPage instanceof PuppeteerPage)) {
|
|
3239
|
-
logerr(
|
|
3280
|
+
logerr(`##browser LsdBrowserContext invalid data in LsdBrowserContext.on("pageClose)`);
|
|
3240
3281
|
return;
|
|
3241
3282
|
}
|
|
3242
3283
|
const idx = this.#lsdPages.findIndex((p) => p === lsdPage);
|
|
3243
3284
|
if (idx < 0) {
|
|
3244
|
-
logerr(
|
|
3285
|
+
logerr(`##browser LsdBrowserContext invalid lsdPage in LsdBrowserContext.on("pageClose)`);
|
|
3245
3286
|
return;
|
|
3246
3287
|
}
|
|
3247
3288
|
this.#lsdPages.splice(idx, 1);
|
|
3248
3289
|
if (this.#lsdPages.length === 0) {
|
|
3249
|
-
this.#lsdBrowser.emit("browserContextClose"
|
|
3290
|
+
this.#lsdBrowser.emit("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, this);
|
|
3250
3291
|
}
|
|
3251
3292
|
return;
|
|
3252
3293
|
});
|
|
@@ -3261,7 +3302,7 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
3261
3302
|
if (this.#browserContext) {
|
|
3262
3303
|
this.#status = "closed";
|
|
3263
3304
|
this.#lastStatusUpdateTime = getCurrentUnixTime5();
|
|
3264
|
-
loginfo(
|
|
3305
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} closed at ${this.#lastStatusUpdateTime}`);
|
|
3265
3306
|
if (this.#browserContextCreationMethod !== "launch") {
|
|
3266
3307
|
await this.#browserContext.close();
|
|
3267
3308
|
}
|
|
@@ -3278,12 +3319,12 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
3278
3319
|
await sleep2(200);
|
|
3279
3320
|
}
|
|
3280
3321
|
}
|
|
3281
|
-
logwarn(
|
|
3322
|
+
logwarn(`##browser LsdBrowserContext cannot get the gettingLock.`);
|
|
3282
3323
|
return false;
|
|
3283
3324
|
}
|
|
3284
3325
|
#freeGettingLock() {
|
|
3285
3326
|
if (!this.#gettingPage) {
|
|
3286
|
-
logwarn(
|
|
3327
|
+
logwarn(`##browser LsdBrowserContext gettingLock is already free now.`);
|
|
3287
3328
|
}
|
|
3288
3329
|
this.#gettingPage = false;
|
|
3289
3330
|
}
|
|
@@ -3292,7 +3333,7 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
3292
3333
|
maxPageFreeSeconds = this.#maxPageFreeSeconds;
|
|
3293
3334
|
}
|
|
3294
3335
|
if (maxPageFreeSeconds <= 0) {
|
|
3295
|
-
logwarn(
|
|
3336
|
+
logwarn(`##browser LsdBrowserContext please set valid maxPageFreeSeconds to close free pages`);
|
|
3296
3337
|
return false;
|
|
3297
3338
|
}
|
|
3298
3339
|
const gotLock = await this.#tryToGetGettingLock();
|
|
@@ -3391,7 +3432,7 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
3391
3432
|
}
|
|
3392
3433
|
}
|
|
3393
3434
|
id() {
|
|
3394
|
-
return `
|
|
3435
|
+
return `PuppeteerContext-${this.#browserIdx}-${this.#browserContextIdx}`;
|
|
3395
3436
|
}
|
|
3396
3437
|
isIncognito() {
|
|
3397
3438
|
return this.#incognito;
|
|
@@ -3425,7 +3466,7 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
3425
3466
|
}
|
|
3426
3467
|
if (localStorageOrigins.length > 0) {
|
|
3427
3468
|
await origPage.setRequestInterception(true);
|
|
3428
|
-
origPage.on("request"
|
|
3469
|
+
origPage.on("request" /* PAGE_REQUEST */, (request) => {
|
|
3429
3470
|
request.respond({
|
|
3430
3471
|
status: 200,
|
|
3431
3472
|
// contentType: "text/html; charset=utf-8", // "text/plain",
|
|
@@ -3528,28 +3569,27 @@ var PuppeteerBrowser = class _PuppeteerBrowser extends EventEmitter6 {
|
|
|
3528
3569
|
this.#executablePath = executablePath;
|
|
3529
3570
|
this.#nextBrowserContextIdx = 1;
|
|
3530
3571
|
this.#closeFreePagesIntervalId = null;
|
|
3531
|
-
loginfo(`##browser
|
|
3572
|
+
loginfo(`##browser LsdBrowser ${this.id()} ${this.#browserCreationMethod}ed}`);
|
|
3532
3573
|
const browserContexts = browser.browserContexts();
|
|
3533
3574
|
const incognito = typeof options?.incognito === "boolean" ? options.incognito : false;
|
|
3534
3575
|
for (const browserContext of browserContexts) {
|
|
3535
3576
|
const lsdBrowserContext = new PuppeteerBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), this.#userAgent(), maxViewportOfNewPage);
|
|
3536
3577
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
3537
|
-
loginfo(`##browser ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
3538
3578
|
}
|
|
3539
|
-
browser.on("disconnected"
|
|
3579
|
+
browser.on("disconnected" /* BROWSER_DISCONNECTED */, () => {
|
|
3540
3580
|
loginfo(`##browser ${this.id()} disconnected`);
|
|
3541
3581
|
if (this.#lsdBrowserContexts.length > 0) {
|
|
3542
|
-
logerr(
|
|
3582
|
+
logerr(`##browser LsdBrowser ${this.id()} has browserContexts when disconnected`);
|
|
3543
3583
|
}
|
|
3544
3584
|
});
|
|
3545
|
-
this.on("browserContextClose"
|
|
3585
|
+
this.on("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, (lsdBrowserContext) => {
|
|
3546
3586
|
if (!(lsdBrowserContext instanceof PuppeteerBrowserContext)) {
|
|
3547
|
-
logerr(
|
|
3587
|
+
logerr(`##browser LsdBrowser invalid data in LsdBrowser.on("browserContextClose)`);
|
|
3548
3588
|
return;
|
|
3549
3589
|
}
|
|
3550
3590
|
const idx = this.#lsdBrowserContexts.findIndex((bc) => bc === lsdBrowserContext);
|
|
3551
3591
|
if (idx < 0) {
|
|
3552
|
-
logerr(
|
|
3592
|
+
logerr(`##browser LsdBrowser invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
3553
3593
|
return;
|
|
3554
3594
|
}
|
|
3555
3595
|
loginfo(`##browser ${lsdBrowserContext.id()} closed
|
|
@@ -3573,7 +3613,7 @@ var PuppeteerBrowser = class _PuppeteerBrowser extends EventEmitter6 {
|
|
|
3573
3613
|
}
|
|
3574
3614
|
async newBrowserContext(options) {
|
|
3575
3615
|
if (this.#lsdBrowserContexts.length >= this.#maxBrowserContextsPerBrowser()) {
|
|
3576
|
-
logwarn(`##browser ${this.id()} can not create more new browserContext`);
|
|
3616
|
+
logwarn(`##browser LsdBrowser ${this.id()} can not create more new browserContext`);
|
|
3577
3617
|
return null;
|
|
3578
3618
|
}
|
|
3579
3619
|
const browserContextOptions = {};
|
|
@@ -3586,7 +3626,6 @@ var PuppeteerBrowser = class _PuppeteerBrowser extends EventEmitter6 {
|
|
|
3586
3626
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
3587
3627
|
const lsdBrowserContext = new PuppeteerBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), userAgent, maxViewportOfNewPage);
|
|
3588
3628
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
3589
|
-
loginfo(`##browser ${lsdBrowserContext.id()} created`);
|
|
3590
3629
|
return lsdBrowserContext;
|
|
3591
3630
|
}
|
|
3592
3631
|
async close() {
|
|
@@ -3597,6 +3636,7 @@ var PuppeteerBrowser = class _PuppeteerBrowser extends EventEmitter6 {
|
|
|
3597
3636
|
await lsdBrowserContext.close();
|
|
3598
3637
|
}
|
|
3599
3638
|
await this.#browser.close();
|
|
3639
|
+
loginfo(`##browser LsdBrowser ${this.id()} is closed`);
|
|
3600
3640
|
return true;
|
|
3601
3641
|
}
|
|
3602
3642
|
browserContexts() {
|
|
@@ -3622,7 +3662,7 @@ var PuppeteerBrowser = class _PuppeteerBrowser extends EventEmitter6 {
|
|
|
3622
3662
|
return this.#executablePath;
|
|
3623
3663
|
}
|
|
3624
3664
|
id() {
|
|
3625
|
-
return `
|
|
3665
|
+
return `PuppeteerBrowser-${this.#browserIdx}`;
|
|
3626
3666
|
}
|
|
3627
3667
|
isConnected() {
|
|
3628
3668
|
return this.#browser.connected;
|
|
@@ -4367,7 +4407,7 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
4367
4407
|
const cookieItems = await this.#getCookies(page);
|
|
4368
4408
|
const domainSet = new Set(cookieItems.map((c) => c.domain));
|
|
4369
4409
|
if (domainSet.size !== 1) {
|
|
4370
|
-
logwarn(
|
|
4410
|
+
logwarn(`##browser LsdPage domains in clearCookies: ${Array.from(domainSet.values())}`);
|
|
4371
4411
|
}
|
|
4372
4412
|
for (const domain of domainSet.values()) {
|
|
4373
4413
|
await browserContext.clearCookies({ domain });
|
|
@@ -4573,15 +4613,15 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
4573
4613
|
}
|
|
4574
4614
|
const page = this.#page;
|
|
4575
4615
|
const pageId = this.#pageId;
|
|
4576
|
-
page.on("close"
|
|
4577
|
-
loginfo(`##browser
|
|
4616
|
+
page.on("close" /* PAGE_CLOSE */, async () => {
|
|
4617
|
+
loginfo(`##browser page ${pageId} closed @LsdPage`);
|
|
4578
4618
|
if (!page.pageInfo) {
|
|
4579
|
-
logerr(
|
|
4619
|
+
logerr(`##browser LsdPage logic error in page.on("close")`);
|
|
4580
4620
|
}
|
|
4581
|
-
this.emit("pageClose");
|
|
4582
|
-
this.#lsdBrowserContext.emit("pageClose"
|
|
4621
|
+
this.emit("pageClose" /* PAGE_CLOSE */);
|
|
4622
|
+
this.#lsdBrowserContext.emit("pageClose" /* PAGE_CLOSE */, this);
|
|
4583
4623
|
});
|
|
4584
|
-
page.on("popup"
|
|
4624
|
+
page.on("popup" /* PAGE_POUP */, (p) => {
|
|
4585
4625
|
if (p) {
|
|
4586
4626
|
let evtData = null;
|
|
4587
4627
|
const pageInfo = p.pageInfo;
|
|
@@ -4595,12 +4635,12 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
4595
4635
|
pageInfo.relatedId = page.pageInfo.taskId;
|
|
4596
4636
|
}
|
|
4597
4637
|
} else {
|
|
4598
|
-
logerr(`##browser
|
|
4638
|
+
logerr(`##browser page ${pageId} has popup without page.pageInfo @LsdPage`);
|
|
4599
4639
|
}
|
|
4600
|
-
loginfo(`##browser
|
|
4601
|
-
this.emit("pagePopup"
|
|
4640
|
+
loginfo(`##browser page ${pageId} has popup ${popupPageId} @LsdPage`);
|
|
4641
|
+
this.emit("pagePopup" /* PAGE_POPUP */, evtData);
|
|
4602
4642
|
} else {
|
|
4603
|
-
logerr(`##browser ${pageId} has popup page with null page`);
|
|
4643
|
+
logerr(`##browser page ${pageId} has popup page with null page @LsdPage`);
|
|
4604
4644
|
}
|
|
4605
4645
|
});
|
|
4606
4646
|
}
|
|
@@ -4615,13 +4655,14 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
4615
4655
|
const currentTime = getCurrentUnixTime7();
|
|
4616
4656
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
4617
4657
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
4618
|
-
this.#pageId = `
|
|
4658
|
+
this.#pageId = `PatchrightPage-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
4619
4659
|
this.#closeWhenFree = false;
|
|
4620
4660
|
this.#resquestInterceptionOptions = [];
|
|
4621
4661
|
this.#responseInterceptionOptions = [];
|
|
4622
4662
|
this.#client = null;
|
|
4623
4663
|
this.#responseCb = null;
|
|
4624
4664
|
this.#isDebugTask = false;
|
|
4665
|
+
loginfo(`##browser LsdPage ${this.#pageId} ${openType}ed`);
|
|
4625
4666
|
this.#addPageOn();
|
|
4626
4667
|
}
|
|
4627
4668
|
async addPreloadScript(scriptOrFunc, arg) {
|
|
@@ -4702,7 +4743,7 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
4702
4743
|
}
|
|
4703
4744
|
async close() {
|
|
4704
4745
|
if (this.#status === "closed") {
|
|
4705
|
-
logwarn(
|
|
4746
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already closed.`);
|
|
4706
4747
|
return true;
|
|
4707
4748
|
} else if (this.#status === "busy") {
|
|
4708
4749
|
throw new Error(`Page ${this.#pageId} cannot be closed because it is busy.`);
|
|
@@ -4713,6 +4754,7 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
4713
4754
|
await this.#page.close();
|
|
4714
4755
|
this.#page = null;
|
|
4715
4756
|
this.#status = "closed";
|
|
4757
|
+
loginfo(`##browser LsdPage ${this.#pageId} is closed`);
|
|
4716
4758
|
return true;
|
|
4717
4759
|
}
|
|
4718
4760
|
closeWhenFree() {
|
|
@@ -4796,10 +4838,11 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
4796
4838
|
return [];
|
|
4797
4839
|
}
|
|
4798
4840
|
async free() {
|
|
4799
|
-
if (this.#status === "free") {
|
|
4800
|
-
logwarn(
|
|
4841
|
+
if (this.#status === "free" && this.pageInfo().openType !== "popup") {
|
|
4842
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already free.`);
|
|
4801
4843
|
}
|
|
4802
4844
|
this.#status = "free";
|
|
4845
|
+
logdbg(`##browser LsdPage ${this.#pageId} is freed`);
|
|
4803
4846
|
await this.clearRequestInterceptions();
|
|
4804
4847
|
await this.clearResponseInterceptions();
|
|
4805
4848
|
return true;
|
|
@@ -5081,7 +5124,7 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
5081
5124
|
}
|
|
5082
5125
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
5083
5126
|
if (actOptions.length <= 0) {
|
|
5084
|
-
logwarn("
|
|
5127
|
+
logwarn("##browser LsdPage invalid paras in setRequestInterception");
|
|
5085
5128
|
return false;
|
|
5086
5129
|
}
|
|
5087
5130
|
const firstRequestInterception = this.#resquestInterceptionOptions.length <= 0;
|
|
@@ -5104,9 +5147,9 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
5104
5147
|
const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
5105
5148
|
if (this.#isDebugTask) {
|
|
5106
5149
|
if (matchedFlag) {
|
|
5107
|
-
|
|
5150
|
+
loginfo(`##browser matched request ${request.method()} ${request.url()}`);
|
|
5108
5151
|
} else {
|
|
5109
|
-
|
|
5152
|
+
logdbg(`##browser unmatched request ${request.method()} ${request.url()}`);
|
|
5110
5153
|
}
|
|
5111
5154
|
}
|
|
5112
5155
|
if (matchedFlag) {
|
|
@@ -5162,9 +5205,9 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
5162
5205
|
}
|
|
5163
5206
|
if (this.#isDebugTask) {
|
|
5164
5207
|
if (matchedFlag) {
|
|
5165
|
-
|
|
5208
|
+
loginfo(`##browser matched response ${request.method()} ${request.url()}`);
|
|
5166
5209
|
} else {
|
|
5167
|
-
|
|
5210
|
+
logdbg(`##browser unmatched response ${request.method()} ${request.url()}`);
|
|
5168
5211
|
}
|
|
5169
5212
|
}
|
|
5170
5213
|
if (!matchedFlag) {
|
|
@@ -5202,7 +5245,7 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
5202
5245
|
}
|
|
5203
5246
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
5204
5247
|
if (actOptions.length <= 0) {
|
|
5205
|
-
logwarn("
|
|
5248
|
+
logwarn("##browser LsdPage invalid paras in setResponseInterception");
|
|
5206
5249
|
return false;
|
|
5207
5250
|
}
|
|
5208
5251
|
const firstResponseInterception = this.#responseInterceptionOptions.length <= 0;
|
|
@@ -5215,7 +5258,7 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
5215
5258
|
}
|
|
5216
5259
|
if (firstResponseInterception && this.#responseInterceptionOptions.length > 0) {
|
|
5217
5260
|
this.#responseCb = this.#responseListener.bind(this);
|
|
5218
|
-
this.#page.on("response"
|
|
5261
|
+
this.#page.on("response" /* PAGE_RESPONSE */, this.#responseCb);
|
|
5219
5262
|
}
|
|
5220
5263
|
return true;
|
|
5221
5264
|
}
|
|
@@ -5263,6 +5306,7 @@ var PatchrightPage = class extends EventEmitter8 {
|
|
|
5263
5306
|
throw new Error(`Page ${this.#pageId} is already busy!!!`);
|
|
5264
5307
|
}
|
|
5265
5308
|
this.#status = "busy";
|
|
5309
|
+
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
5266
5310
|
return true;
|
|
5267
5311
|
}
|
|
5268
5312
|
async waitForElement(selector, options = {}) {
|
|
@@ -5401,11 +5445,10 @@ var PatchrightBrowserContext = class extends EventEmitter9 {
|
|
|
5401
5445
|
for (const page of pages) {
|
|
5402
5446
|
const pageInfo = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType, openTime: this.#createTime, lastStatusUpdateTime, taskId: 0, relatedId: 0, misc: {} };
|
|
5403
5447
|
const lsdPage = new PatchrightPage(this, page, pageInfo);
|
|
5448
|
+
this.#lsdPages.push(lsdPage);
|
|
5404
5449
|
if (this.#maxViewportOfNewPage) {
|
|
5405
5450
|
await lsdPage.maximizeViewport();
|
|
5406
5451
|
}
|
|
5407
|
-
this.#lsdPages.push(lsdPage);
|
|
5408
|
-
loginfo(`##browser ${lsdPage.id()} ${openType}ed`);
|
|
5409
5452
|
}
|
|
5410
5453
|
}
|
|
5411
5454
|
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, maxViewportOfNewPage = true) {
|
|
@@ -5435,8 +5478,9 @@ var PatchrightBrowserContext = class extends EventEmitter9 {
|
|
|
5435
5478
|
this.#lsdPages = [];
|
|
5436
5479
|
this.#nextPageIdx = 1;
|
|
5437
5480
|
this.#gettingPage = false;
|
|
5481
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} is created`);
|
|
5438
5482
|
this.#initPages();
|
|
5439
|
-
browserContext.on("page"
|
|
5483
|
+
browserContext.on("page" /* BROWSERCONTEXT_PAGE */, async (page) => {
|
|
5440
5484
|
const pageInfo = page.pageInfo;
|
|
5441
5485
|
if (pageInfo) {
|
|
5442
5486
|
const { browserIdx: browserIdx2, browserContextIdx: browserContextIdx2, pageIdx } = pageInfo;
|
|
@@ -5445,27 +5489,26 @@ var PatchrightBrowserContext = class extends EventEmitter9 {
|
|
|
5445
5489
|
const currentTime2 = getCurrentUnixTime8();
|
|
5446
5490
|
const pageInfo2 = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType: "other", openTime: currentTime2, lastStatusUpdateTime: currentTime2, taskId: 0, relatedId: 0, misc: {} };
|
|
5447
5491
|
const lsdPage = new PatchrightPage(this, page, pageInfo2);
|
|
5492
|
+
this.#lsdPages.push(lsdPage);
|
|
5448
5493
|
if (this.#maxViewportOfNewPage) {
|
|
5449
5494
|
await lsdPage.maximizeViewport();
|
|
5450
5495
|
}
|
|
5451
|
-
this.#lsdPages.push(lsdPage);
|
|
5452
|
-
loginfo(`##page ${lsdPage.id()} created`);
|
|
5453
5496
|
}
|
|
5454
5497
|
});
|
|
5455
|
-
browserContext.on("close"
|
|
5498
|
+
browserContext.on("close" /* BROWSERCONTEXT_CLOSE */, (bc) => {
|
|
5456
5499
|
if (browserContext !== bc) {
|
|
5457
|
-
logerr(`##browser different browserContext in browserContext.on("close")`);
|
|
5500
|
+
logerr(`##browser LsdBrowserContext different browserContext in browserContext.on("close")`);
|
|
5458
5501
|
}
|
|
5459
|
-
this.#lsdBrowser.emit("browserContextClose"
|
|
5502
|
+
this.#lsdBrowser.emit("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, this);
|
|
5460
5503
|
});
|
|
5461
|
-
this.on("pageClose"
|
|
5504
|
+
this.on("pageClose" /* PAGE_CLOSE */, (lsdPage) => {
|
|
5462
5505
|
if (!(lsdPage instanceof PatchrightPage)) {
|
|
5463
|
-
logerr(
|
|
5506
|
+
logerr(`##browser LsdBrowserContext invalid data in LsdBrowserContext.on("pageClose)`);
|
|
5464
5507
|
return;
|
|
5465
5508
|
}
|
|
5466
5509
|
const idx = this.#lsdPages.findIndex((p) => p === lsdPage);
|
|
5467
5510
|
if (idx < 0) {
|
|
5468
|
-
logerr(
|
|
5511
|
+
logerr(`##browser LsdBrowserContext invalid lsdPage in LsdBrowserContext.on("pageClose)`);
|
|
5469
5512
|
return;
|
|
5470
5513
|
}
|
|
5471
5514
|
this.#lsdPages.splice(idx, 1);
|
|
@@ -5482,7 +5525,7 @@ var PatchrightBrowserContext = class extends EventEmitter9 {
|
|
|
5482
5525
|
if (this.#browserContext) {
|
|
5483
5526
|
this.#status = "closed";
|
|
5484
5527
|
this.#lastStatusUpdateTime = getCurrentUnixTime8();
|
|
5485
|
-
loginfo(
|
|
5528
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} closed at ${this.#lastStatusUpdateTime}`);
|
|
5486
5529
|
await this.#browserContext.close();
|
|
5487
5530
|
}
|
|
5488
5531
|
return true;
|
|
@@ -5497,12 +5540,12 @@ var PatchrightBrowserContext = class extends EventEmitter9 {
|
|
|
5497
5540
|
await sleep3(200);
|
|
5498
5541
|
}
|
|
5499
5542
|
}
|
|
5500
|
-
logwarn(
|
|
5543
|
+
logwarn(`##browser LsdBrowserContext cannot get the gettingLock.`);
|
|
5501
5544
|
return false;
|
|
5502
5545
|
}
|
|
5503
5546
|
#freeGettingLock() {
|
|
5504
5547
|
if (!this.#gettingPage) {
|
|
5505
|
-
logwarn(
|
|
5548
|
+
logwarn(`##browser LsdBrowserContext gettingLock is already free now.`);
|
|
5506
5549
|
}
|
|
5507
5550
|
this.#gettingPage = false;
|
|
5508
5551
|
}
|
|
@@ -5511,7 +5554,7 @@ var PatchrightBrowserContext = class extends EventEmitter9 {
|
|
|
5511
5554
|
maxPageFreeSeconds = this.#maxPageFreeSeconds;
|
|
5512
5555
|
}
|
|
5513
5556
|
if (maxPageFreeSeconds <= 0) {
|
|
5514
|
-
logwarn(
|
|
5557
|
+
logwarn(`##browser LsdBrowserContext please set valid maxPageFreeSeconds to close free pages`);
|
|
5515
5558
|
return false;
|
|
5516
5559
|
}
|
|
5517
5560
|
const gotLock = await this.#tryToGetGettingLock();
|
|
@@ -5608,7 +5651,7 @@ var PatchrightBrowserContext = class extends EventEmitter9 {
|
|
|
5608
5651
|
}
|
|
5609
5652
|
}
|
|
5610
5653
|
id() {
|
|
5611
|
-
return `
|
|
5654
|
+
return `PatchrightContext-${this.#browserIdx}-${this.#browserContextIdx}`;
|
|
5612
5655
|
}
|
|
5613
5656
|
isFree() {
|
|
5614
5657
|
return this.#status === "free";
|
|
@@ -5742,34 +5785,33 @@ var PatchrightBrowser = class _PatchrightBrowser extends EventEmitter10 {
|
|
|
5742
5785
|
this.#executablePath = executablePath;
|
|
5743
5786
|
this.#nextBrowserContextIdx = 1;
|
|
5744
5787
|
this.#closeFreePagesIntervalId = null;
|
|
5745
|
-
loginfo(`##browser ${this.id()} ${this.#browserCreationMethod}ed
|
|
5788
|
+
loginfo(`##browser LsdBrowser ${this.id()} ${this.#browserCreationMethod}ed}`);
|
|
5746
5789
|
const browserContexts = browser.contexts();
|
|
5747
5790
|
if (browserContexts.length > 0) {
|
|
5748
|
-
logwarn(
|
|
5791
|
+
logwarn(`##browser LsdBrowser there are ${browserContexts.length} new browserContexts when playwright launches new browser`);
|
|
5749
5792
|
}
|
|
5750
5793
|
const incognito = typeof options?.incognito === "boolean" ? options.incognito : true;
|
|
5751
5794
|
for (const browserContext of browserContexts) {
|
|
5752
5795
|
const lsdBrowserContext = new PatchrightBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
5753
5796
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
5754
|
-
loginfo(`##browserContext ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
5755
5797
|
}
|
|
5756
|
-
browser.on("disconnected"
|
|
5798
|
+
browser.on("disconnected" /* BROWSER_DISCONNECTED */, () => {
|
|
5757
5799
|
loginfo(`##browser ${this.id()} disconnected`);
|
|
5758
5800
|
if (this.#lsdBrowserContexts.length > 0) {
|
|
5759
|
-
logerr(
|
|
5801
|
+
logerr(`##browser LsdBrowser ${this.id()} has browserContexts when disconnected`);
|
|
5760
5802
|
}
|
|
5761
5803
|
});
|
|
5762
|
-
this.on("browserContextClose"
|
|
5804
|
+
this.on("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, (lsdBrowserContext) => {
|
|
5763
5805
|
if (!(lsdBrowserContext instanceof PatchrightBrowserContext)) {
|
|
5764
|
-
logerr(
|
|
5806
|
+
logerr(`##browser LsdBrowser invalid data in LsdBrowser.on("browserContextClose)`);
|
|
5765
5807
|
return;
|
|
5766
5808
|
}
|
|
5767
5809
|
const idx = this.#lsdBrowserContexts.findIndex((bc) => bc === lsdBrowserContext);
|
|
5768
5810
|
if (idx < 0) {
|
|
5769
|
-
logerr(
|
|
5811
|
+
logerr(`##browser LsdBrowser invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
5770
5812
|
return;
|
|
5771
5813
|
}
|
|
5772
|
-
loginfo(`##
|
|
5814
|
+
loginfo(`##browser ${lsdBrowserContext.id()} closed
|
|
5773
5815
|
`);
|
|
5774
5816
|
this.#lsdBrowserContexts.splice(idx, 1);
|
|
5775
5817
|
if (this.#lsdBrowserContexts.length === 0) {
|
|
@@ -5790,7 +5832,7 @@ var PatchrightBrowser = class _PatchrightBrowser extends EventEmitter10 {
|
|
|
5790
5832
|
}
|
|
5791
5833
|
async newBrowserContext(options) {
|
|
5792
5834
|
if (this.#lsdBrowserContexts.length >= this.#maxBrowserContextsPerBrowser()) {
|
|
5793
|
-
logwarn(`##browser ${this.id()} can not create more new browserContext`);
|
|
5835
|
+
logwarn(`##browser LsdBrowser ${this.id()} can not create more new browserContext`);
|
|
5794
5836
|
return null;
|
|
5795
5837
|
}
|
|
5796
5838
|
const browserContextOptions = {};
|
|
@@ -5809,7 +5851,6 @@ var PatchrightBrowser = class _PatchrightBrowser extends EventEmitter10 {
|
|
|
5809
5851
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
5810
5852
|
const lsdBrowserContext = new PatchrightBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
5811
5853
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
5812
|
-
loginfo(`##browser ${lsdBrowserContext.id()} created`);
|
|
5813
5854
|
return lsdBrowserContext;
|
|
5814
5855
|
}
|
|
5815
5856
|
async close() {
|
|
@@ -5820,6 +5861,7 @@ var PatchrightBrowser = class _PatchrightBrowser extends EventEmitter10 {
|
|
|
5820
5861
|
await lsdBrowserContext.close();
|
|
5821
5862
|
}
|
|
5822
5863
|
await this.#browser.close();
|
|
5864
|
+
loginfo(`##browser LsdBrowser ${this.id()} is closed`);
|
|
5823
5865
|
return true;
|
|
5824
5866
|
}
|
|
5825
5867
|
browserContexts() {
|
|
@@ -5845,7 +5887,7 @@ var PatchrightBrowser = class _PatchrightBrowser extends EventEmitter10 {
|
|
|
5845
5887
|
return this.#executablePath;
|
|
5846
5888
|
}
|
|
5847
5889
|
id() {
|
|
5848
|
-
return `
|
|
5890
|
+
return `PatchrightBrowser-${this.#browserType}-${this.#browserIdx}`;
|
|
5849
5891
|
}
|
|
5850
5892
|
isConnected() {
|
|
5851
5893
|
return this.#browser.isConnected();
|
|
@@ -6217,7 +6259,7 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
6217
6259
|
const cookieItems = await this.#getCookies(page);
|
|
6218
6260
|
const domainSet = new Set(cookieItems.map((c) => c.domain));
|
|
6219
6261
|
if (domainSet.size !== 1) {
|
|
6220
|
-
logwarn(
|
|
6262
|
+
logwarn(`##browser LsdPage domains in clearCookies: ${Array.from(domainSet.values())}`);
|
|
6221
6263
|
}
|
|
6222
6264
|
for (const domain of domainSet.values()) {
|
|
6223
6265
|
await browserContext.clearCookies({ domain });
|
|
@@ -6423,15 +6465,15 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
6423
6465
|
}
|
|
6424
6466
|
const page = this.#page;
|
|
6425
6467
|
const pageId = this.#pageId;
|
|
6426
|
-
page.on("close"
|
|
6427
|
-
loginfo(`##browser
|
|
6468
|
+
page.on("close" /* PAGE_CLOSE */, async () => {
|
|
6469
|
+
loginfo(`##browser page ${pageId} closed @LsdPage`);
|
|
6428
6470
|
if (!page.pageInfo) {
|
|
6429
|
-
logerr(
|
|
6471
|
+
logerr(`##browser LsdPage logic error in page.on("close")`);
|
|
6430
6472
|
}
|
|
6431
|
-
this.emit("pageClose");
|
|
6432
|
-
this.#lsdBrowserContext.emit("pageClose"
|
|
6473
|
+
this.emit("pageClose" /* PAGE_CLOSE */);
|
|
6474
|
+
this.#lsdBrowserContext.emit("pageClose" /* PAGE_CLOSE */, this);
|
|
6433
6475
|
});
|
|
6434
|
-
page.on("popup"
|
|
6476
|
+
page.on("popup" /* PAGE_POUP */, (p) => {
|
|
6435
6477
|
if (p) {
|
|
6436
6478
|
let evtData = null;
|
|
6437
6479
|
const pageInfo = p.pageInfo;
|
|
@@ -6445,12 +6487,12 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
6445
6487
|
pageInfo.relatedId = page.pageInfo.taskId;
|
|
6446
6488
|
}
|
|
6447
6489
|
} else {
|
|
6448
|
-
logerr(`##browser
|
|
6490
|
+
logerr(`##browser page ${pageId} has popup without page.pageInfo @LsdPage`);
|
|
6449
6491
|
}
|
|
6450
|
-
loginfo(`##browser
|
|
6451
|
-
this.emit("pagePopup"
|
|
6492
|
+
loginfo(`##browser page ${pageId} has popup ${popupPageId} @LsdPage`);
|
|
6493
|
+
this.emit("pagePopup" /* PAGE_POPUP */, evtData);
|
|
6452
6494
|
} else {
|
|
6453
|
-
logerr(`##browser ${pageId} has popup page with null page`);
|
|
6495
|
+
logerr(`##browser page ${pageId} has popup page with null page @LsdPage`);
|
|
6454
6496
|
}
|
|
6455
6497
|
});
|
|
6456
6498
|
}
|
|
@@ -6465,13 +6507,14 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
6465
6507
|
const currentTime = getCurrentUnixTime10();
|
|
6466
6508
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
6467
6509
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
6468
|
-
this.#pageId = `
|
|
6510
|
+
this.#pageId = `CamoufoxPage-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
6469
6511
|
this.#closeWhenFree = false;
|
|
6470
6512
|
this.#resquestInterceptionOptions = [];
|
|
6471
6513
|
this.#responseInterceptionOptions = [];
|
|
6472
6514
|
this.#client = null;
|
|
6473
6515
|
this.#responseCb = null;
|
|
6474
6516
|
this.#isDebugTask = false;
|
|
6517
|
+
loginfo(`##browser LsdPage ${this.#pageId} ${openType}ed`);
|
|
6475
6518
|
this.#addPageOn();
|
|
6476
6519
|
}
|
|
6477
6520
|
async addPreloadScript() {
|
|
@@ -6539,7 +6582,7 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
6539
6582
|
}
|
|
6540
6583
|
async close() {
|
|
6541
6584
|
if (this.#status === "closed") {
|
|
6542
|
-
logwarn(
|
|
6585
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already closed.`);
|
|
6543
6586
|
return true;
|
|
6544
6587
|
} else if (this.#status === "busy") {
|
|
6545
6588
|
throw new Error(`Page ${this.#pageId} cannot be closed because it is busy.`);
|
|
@@ -6550,6 +6593,7 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
6550
6593
|
await this.#page.close();
|
|
6551
6594
|
this.#page = null;
|
|
6552
6595
|
this.#status = "closed";
|
|
6596
|
+
loginfo(`##browser LsdPage ${this.#pageId} is closed`);
|
|
6553
6597
|
return true;
|
|
6554
6598
|
}
|
|
6555
6599
|
closeWhenFree() {
|
|
@@ -6634,10 +6678,11 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
6634
6678
|
return [];
|
|
6635
6679
|
}
|
|
6636
6680
|
async free() {
|
|
6637
|
-
if (this.#status === "free") {
|
|
6638
|
-
logwarn(
|
|
6681
|
+
if (this.#status === "free" && this.pageInfo().openType !== "popup") {
|
|
6682
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already free.`);
|
|
6639
6683
|
}
|
|
6640
6684
|
this.#status = "free";
|
|
6685
|
+
logdbg(`##browser LsdPage ${this.#pageId} is freed`);
|
|
6641
6686
|
await this.clearRequestInterceptions();
|
|
6642
6687
|
await this.clearResponseInterceptions();
|
|
6643
6688
|
return true;
|
|
@@ -6819,23 +6864,8 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
6819
6864
|
);
|
|
6820
6865
|
return true;
|
|
6821
6866
|
}
|
|
6822
|
-
async sendCDPMessage(
|
|
6823
|
-
|
|
6824
|
-
const origContext = this.browserContext()._origBrowserContext();
|
|
6825
|
-
if (!origContext) {
|
|
6826
|
-
throw new Error(`Invalid playwright browserContext`);
|
|
6827
|
-
}
|
|
6828
|
-
this.#client = await origContext.newCDPSession(this.#page);
|
|
6829
|
-
}
|
|
6830
|
-
if (!this.#client) {
|
|
6831
|
-
throw new Error("No valid CDP session to send message");
|
|
6832
|
-
}
|
|
6833
|
-
const response = params ? await this.#client.send(method, params) : await this.#client.send(method);
|
|
6834
|
-
if (detach) {
|
|
6835
|
-
await this.#client.detach();
|
|
6836
|
-
this.#client = null;
|
|
6837
|
-
}
|
|
6838
|
-
return response;
|
|
6867
|
+
async sendCDPMessage(_method, _params = null, _detach = true) {
|
|
6868
|
+
throw new Error("##browser Camoufox does not support sendCDPMessage");
|
|
6839
6869
|
}
|
|
6840
6870
|
setCloseWhenFree(closeWhenFree) {
|
|
6841
6871
|
this.#closeWhenFree = closeWhenFree;
|
|
@@ -6919,7 +6949,7 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
6919
6949
|
}
|
|
6920
6950
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
6921
6951
|
if (actOptions.length <= 0) {
|
|
6922
|
-
logwarn("
|
|
6952
|
+
logwarn("##browser LsdPage invalid paras in setRequestInterception");
|
|
6923
6953
|
return false;
|
|
6924
6954
|
}
|
|
6925
6955
|
const firstRequestInterception = this.#resquestInterceptionOptions.length <= 0;
|
|
@@ -6942,9 +6972,9 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
6942
6972
|
const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
6943
6973
|
if (this.#isDebugTask) {
|
|
6944
6974
|
if (matchedFlag) {
|
|
6945
|
-
|
|
6975
|
+
loginfo(`##browser matched request ${request.method()} ${request.url()}`);
|
|
6946
6976
|
} else {
|
|
6947
|
-
|
|
6977
|
+
logdbg(`##browser unmatched request ${request.method()} ${request.url()}`);
|
|
6948
6978
|
}
|
|
6949
6979
|
}
|
|
6950
6980
|
if (matchedFlag) {
|
|
@@ -7000,9 +7030,9 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
7000
7030
|
}
|
|
7001
7031
|
if (this.#isDebugTask) {
|
|
7002
7032
|
if (matchedFlag) {
|
|
7003
|
-
|
|
7033
|
+
loginfo(`##browser matched response ${request.method()} ${request.url()}`);
|
|
7004
7034
|
} else {
|
|
7005
|
-
|
|
7035
|
+
logdbg(`##browser unmatched response ${request.method()} ${request.url()}`);
|
|
7006
7036
|
}
|
|
7007
7037
|
}
|
|
7008
7038
|
if (!matchedFlag) {
|
|
@@ -7040,7 +7070,7 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
7040
7070
|
}
|
|
7041
7071
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
7042
7072
|
if (actOptions.length <= 0) {
|
|
7043
|
-
logwarn("
|
|
7073
|
+
logwarn("##browser LsdPage invalid paras in setResponseInterception");
|
|
7044
7074
|
return false;
|
|
7045
7075
|
}
|
|
7046
7076
|
const firstResponseInterception = this.#responseInterceptionOptions.length <= 0;
|
|
@@ -7053,7 +7083,7 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
7053
7083
|
}
|
|
7054
7084
|
if (firstResponseInterception && this.#responseInterceptionOptions.length > 0) {
|
|
7055
7085
|
this.#responseCb = this.#responseListener.bind(this);
|
|
7056
|
-
this.#page.on("response"
|
|
7086
|
+
this.#page.on("response" /* PAGE_RESPONSE */, this.#responseCb);
|
|
7057
7087
|
}
|
|
7058
7088
|
return true;
|
|
7059
7089
|
}
|
|
@@ -7101,6 +7131,7 @@ var CamoufoxPage = class extends EventEmitter11 {
|
|
|
7101
7131
|
throw new Error(`Page ${this.#pageId} is already busy!!!`);
|
|
7102
7132
|
}
|
|
7103
7133
|
this.#status = "busy";
|
|
7134
|
+
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
7104
7135
|
return true;
|
|
7105
7136
|
}
|
|
7106
7137
|
async waitForElement(selector, options = {}) {
|
|
@@ -7239,11 +7270,10 @@ var CamoufoxBrowserContext = class extends EventEmitter12 {
|
|
|
7239
7270
|
for (const page of pages) {
|
|
7240
7271
|
const pageInfo = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType, openTime: this.#createTime, lastStatusUpdateTime, taskId: 0, relatedId: 0, misc: {} };
|
|
7241
7272
|
const lsdPage = new CamoufoxPage(this, page, pageInfo);
|
|
7273
|
+
this.#lsdPages.push(lsdPage);
|
|
7242
7274
|
if (this.#maxViewportOfNewPage) {
|
|
7243
7275
|
await lsdPage.maximizeViewport();
|
|
7244
7276
|
}
|
|
7245
|
-
this.#lsdPages.push(lsdPage);
|
|
7246
|
-
loginfo(`##browser ${lsdPage.id()} ${openType}ed`);
|
|
7247
7277
|
}
|
|
7248
7278
|
}
|
|
7249
7279
|
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, maxViewportOfNewPage = true) {
|
|
@@ -7273,8 +7303,9 @@ var CamoufoxBrowserContext = class extends EventEmitter12 {
|
|
|
7273
7303
|
this.#lsdPages = [];
|
|
7274
7304
|
this.#nextPageIdx = 1;
|
|
7275
7305
|
this.#gettingPage = false;
|
|
7306
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} is created`);
|
|
7276
7307
|
this.#initPages();
|
|
7277
|
-
browserContext.on("page"
|
|
7308
|
+
browserContext.on("page" /* BROWSERCONTEXT_PAGE */, async (page) => {
|
|
7278
7309
|
const pageInfo = page.pageInfo;
|
|
7279
7310
|
if (pageInfo) {
|
|
7280
7311
|
const { browserIdx: browserIdx2, browserContextIdx: browserContextIdx2, pageIdx } = pageInfo;
|
|
@@ -7283,27 +7314,26 @@ var CamoufoxBrowserContext = class extends EventEmitter12 {
|
|
|
7283
7314
|
const currentTime2 = getCurrentUnixTime11();
|
|
7284
7315
|
const pageInfo2 = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType: "other", openTime: currentTime2, lastStatusUpdateTime: currentTime2, taskId: 0, relatedId: 0, misc: {} };
|
|
7285
7316
|
const lsdPage = new CamoufoxPage(this, page, pageInfo2);
|
|
7317
|
+
this.#lsdPages.push(lsdPage);
|
|
7286
7318
|
if (this.#maxViewportOfNewPage) {
|
|
7287
7319
|
await lsdPage.maximizeViewport();
|
|
7288
7320
|
}
|
|
7289
|
-
this.#lsdPages.push(lsdPage);
|
|
7290
|
-
loginfo(`##page ${lsdPage.id()} created`);
|
|
7291
7321
|
}
|
|
7292
7322
|
});
|
|
7293
|
-
browserContext.on("close"
|
|
7323
|
+
browserContext.on("close" /* BROWSERCONTEXT_CLOSE */, (bc) => {
|
|
7294
7324
|
if (browserContext !== bc) {
|
|
7295
|
-
logerr(`##browser different browserContext in browserContext.on("close")`);
|
|
7325
|
+
logerr(`##browser LsdBrowserContext different browserContext in browserContext.on("close")`);
|
|
7296
7326
|
}
|
|
7297
|
-
this.#lsdBrowser.emit("browserContextClose"
|
|
7327
|
+
this.#lsdBrowser.emit("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, this);
|
|
7298
7328
|
});
|
|
7299
|
-
this.on("pageClose"
|
|
7329
|
+
this.on("pageClose" /* PAGE_CLOSE */, (lsdPage) => {
|
|
7300
7330
|
if (!(lsdPage instanceof CamoufoxPage)) {
|
|
7301
|
-
logerr(
|
|
7331
|
+
logerr(`##browser LsdBrowserContext invalid data in LsdBrowserContext.on("pageClose)`);
|
|
7302
7332
|
return;
|
|
7303
7333
|
}
|
|
7304
7334
|
const idx = this.#lsdPages.findIndex((p) => p === lsdPage);
|
|
7305
7335
|
if (idx < 0) {
|
|
7306
|
-
logerr(
|
|
7336
|
+
logerr(`##browser LsdBrowserContext invalid lsdPage in LsdBrowserContext.on("pageClose)`);
|
|
7307
7337
|
return;
|
|
7308
7338
|
}
|
|
7309
7339
|
this.#lsdPages.splice(idx, 1);
|
|
@@ -7320,7 +7350,7 @@ var CamoufoxBrowserContext = class extends EventEmitter12 {
|
|
|
7320
7350
|
if (this.#browserContext) {
|
|
7321
7351
|
this.#status = "closed";
|
|
7322
7352
|
this.#lastStatusUpdateTime = getCurrentUnixTime11();
|
|
7323
|
-
loginfo(
|
|
7353
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} closed at ${this.#lastStatusUpdateTime}`);
|
|
7324
7354
|
await this.#browserContext.close();
|
|
7325
7355
|
}
|
|
7326
7356
|
return true;
|
|
@@ -7335,12 +7365,12 @@ var CamoufoxBrowserContext = class extends EventEmitter12 {
|
|
|
7335
7365
|
await sleep4(200);
|
|
7336
7366
|
}
|
|
7337
7367
|
}
|
|
7338
|
-
logwarn(
|
|
7368
|
+
logwarn(`##browser LsdBrowserContext cannot get the gettingLock.`);
|
|
7339
7369
|
return false;
|
|
7340
7370
|
}
|
|
7341
7371
|
#freeGettingLock() {
|
|
7342
7372
|
if (!this.#gettingPage) {
|
|
7343
|
-
logwarn(
|
|
7373
|
+
logwarn(`##browser LsdBrowserContext gettingLock is already free now.`);
|
|
7344
7374
|
}
|
|
7345
7375
|
this.#gettingPage = false;
|
|
7346
7376
|
}
|
|
@@ -7349,7 +7379,7 @@ var CamoufoxBrowserContext = class extends EventEmitter12 {
|
|
|
7349
7379
|
maxPageFreeSeconds = this.#maxPageFreeSeconds;
|
|
7350
7380
|
}
|
|
7351
7381
|
if (maxPageFreeSeconds <= 0) {
|
|
7352
|
-
logwarn(
|
|
7382
|
+
logwarn(`##browser LsdBrowserContext please set valid maxPageFreeSeconds to close free pages`);
|
|
7353
7383
|
return false;
|
|
7354
7384
|
}
|
|
7355
7385
|
const gotLock = await this.#tryToGetGettingLock();
|
|
@@ -7446,7 +7476,7 @@ var CamoufoxBrowserContext = class extends EventEmitter12 {
|
|
|
7446
7476
|
}
|
|
7447
7477
|
}
|
|
7448
7478
|
id() {
|
|
7449
|
-
return `
|
|
7479
|
+
return `CamoufoxContext-${this.#browserIdx}-${this.#browserContextIdx}`;
|
|
7450
7480
|
}
|
|
7451
7481
|
isFree() {
|
|
7452
7482
|
return this.#status === "free";
|
|
@@ -7580,34 +7610,33 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends EventEmitter13 {
|
|
|
7580
7610
|
this.#executablePath = executablePath;
|
|
7581
7611
|
this.#nextBrowserContextIdx = 1;
|
|
7582
7612
|
this.#closeFreePagesIntervalId = null;
|
|
7583
|
-
loginfo(`##browser ${this.id()} ${this.#browserCreationMethod}ed
|
|
7613
|
+
loginfo(`##browser LsdBrowser ${this.id()} ${this.#browserCreationMethod}ed}`);
|
|
7584
7614
|
const browserContexts = browser.contexts();
|
|
7585
7615
|
if (browserContexts.length > 0) {
|
|
7586
|
-
logwarn(
|
|
7616
|
+
logwarn(`##browser LsdBrowser there are ${browserContexts.length} new browserContexts when camoufox launches new browser`);
|
|
7587
7617
|
}
|
|
7588
7618
|
const incognito = typeof options?.incognito === "boolean" ? options.incognito : true;
|
|
7589
7619
|
for (const browserContext of browserContexts) {
|
|
7590
7620
|
const lsdBrowserContext = new CamoufoxBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
7591
7621
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
7592
|
-
loginfo(`##browserContext ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
7593
7622
|
}
|
|
7594
|
-
browser.on("disconnected"
|
|
7623
|
+
browser.on("disconnected" /* BROWSER_DISCONNECTED */, () => {
|
|
7595
7624
|
loginfo(`##browser ${this.id()} disconnected`);
|
|
7596
7625
|
if (this.#lsdBrowserContexts.length > 0) {
|
|
7597
|
-
logerr(
|
|
7626
|
+
logerr(`##browser LsdBrowser ${this.id()} has browserContexts when disconnected`);
|
|
7598
7627
|
}
|
|
7599
7628
|
});
|
|
7600
|
-
this.on("browserContextClose"
|
|
7629
|
+
this.on("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, (lsdBrowserContext) => {
|
|
7601
7630
|
if (!(lsdBrowserContext instanceof CamoufoxBrowserContext)) {
|
|
7602
|
-
logerr(
|
|
7631
|
+
logerr(`##browser LsdBrowser invalid data in LsdBrowser.on("browserContextClose)`);
|
|
7603
7632
|
return;
|
|
7604
7633
|
}
|
|
7605
7634
|
const idx = this.#lsdBrowserContexts.findIndex((bc) => bc === lsdBrowserContext);
|
|
7606
7635
|
if (idx < 0) {
|
|
7607
|
-
logerr(
|
|
7636
|
+
logerr(`##browser LsdBrowser invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
7608
7637
|
return;
|
|
7609
7638
|
}
|
|
7610
|
-
loginfo(`##
|
|
7639
|
+
loginfo(`##browser ${lsdBrowserContext.id()} closed
|
|
7611
7640
|
`);
|
|
7612
7641
|
this.#lsdBrowserContexts.splice(idx, 1);
|
|
7613
7642
|
if (this.#lsdBrowserContexts.length === 0) {
|
|
@@ -7628,7 +7657,7 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends EventEmitter13 {
|
|
|
7628
7657
|
}
|
|
7629
7658
|
async newBrowserContext(options) {
|
|
7630
7659
|
if (this.#lsdBrowserContexts.length >= this.#maxBrowserContextsPerBrowser()) {
|
|
7631
|
-
logwarn(`##browser ${this.id()} can not create more new browserContext`);
|
|
7660
|
+
logwarn(`##browser LsdBrowser ${this.id()} can not create more new browserContext`);
|
|
7632
7661
|
return null;
|
|
7633
7662
|
}
|
|
7634
7663
|
const browserContextOptions = {};
|
|
@@ -7647,7 +7676,6 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends EventEmitter13 {
|
|
|
7647
7676
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
7648
7677
|
const lsdBrowserContext = new CamoufoxBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
7649
7678
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
7650
|
-
loginfo(`##browser ${lsdBrowserContext.id()} created`);
|
|
7651
7679
|
return lsdBrowserContext;
|
|
7652
7680
|
}
|
|
7653
7681
|
async close() {
|
|
@@ -7658,6 +7686,7 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends EventEmitter13 {
|
|
|
7658
7686
|
await lsdBrowserContext.close();
|
|
7659
7687
|
}
|
|
7660
7688
|
await this.#browser.close();
|
|
7689
|
+
loginfo(`##browser LsdBrowser ${this.id()} is closed`);
|
|
7661
7690
|
return true;
|
|
7662
7691
|
}
|
|
7663
7692
|
browserContexts() {
|
|
@@ -7683,7 +7712,7 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends EventEmitter13 {
|
|
|
7683
7712
|
return this.#executablePath;
|
|
7684
7713
|
}
|
|
7685
7714
|
id() {
|
|
7686
|
-
return `
|
|
7715
|
+
return `CamoufoxBrowser-${this.#browserType}-${this.#browserIdx}`;
|
|
7687
7716
|
}
|
|
7688
7717
|
isConnected() {
|
|
7689
7718
|
return this.#browser.isConnected();
|
|
@@ -7845,22 +7874,22 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
7845
7874
|
const actOptions = { closeFreePagesIntervalSeconds, maxBrowserContextsPerBrowser, maxPagesPerBrowserContext, maxPageFreeSeconds, maxViewportOfNewPage, proxy, timeout, args, executablePath, maxWindowSize, headless, minBrowserContexts, incognito, proxyPerBrowserContext, userDataDir, userAgent };
|
|
7846
7875
|
let idx = args.findIndex((arg) => arg.toLowerCase().startsWith("--incoginto"));
|
|
7847
7876
|
if (idx >= 0) {
|
|
7848
|
-
logwarn(
|
|
7877
|
+
logwarn(`##browser controller Please use options.incognito instead when launching new browser.`);
|
|
7849
7878
|
args.splice(idx, 1);
|
|
7850
7879
|
}
|
|
7851
7880
|
idx = args.findIndex((arg) => arg.toLowerCase().startsWith("--proxy-server"));
|
|
7852
7881
|
if (idx >= 0) {
|
|
7853
|
-
logwarn(
|
|
7882
|
+
logwarn(`##browser controller Please use options.proxy instead when launching new browser.`);
|
|
7854
7883
|
args.splice(idx, 1);
|
|
7855
7884
|
}
|
|
7856
7885
|
idx = args.findIndex((arg) => arg.toLowerCase().startsWith("--user-data-dir"));
|
|
7857
7886
|
if (idx >= 0) {
|
|
7858
|
-
logwarn(
|
|
7887
|
+
logwarn(`##browser controller Please use options.userDataDir instead when launching new browser.`);
|
|
7859
7888
|
args.splice(idx, 1);
|
|
7860
7889
|
}
|
|
7861
7890
|
idx = args.findIndex((arg) => arg.toLowerCase().startsWith("--start-maximized"));
|
|
7862
7891
|
if (idx >= 0) {
|
|
7863
|
-
logwarn(
|
|
7892
|
+
logwarn(`##browser controller Please use options.maxWindowSize instead when launching new browser.`);
|
|
7864
7893
|
args.splice(idx, 1);
|
|
7865
7894
|
}
|
|
7866
7895
|
let lsdBrowser;
|
|
@@ -8058,7 +8087,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
8058
8087
|
const pids = await getPidsListeningOnPort(port);
|
|
8059
8088
|
let browserPid = 0;
|
|
8060
8089
|
if (pids.length !== 1) {
|
|
8061
|
-
logerr(`##browser pids.length ${pids.length} is not 1 when trying to connect to browserUrl ${browserUrl}`);
|
|
8090
|
+
logerr(`##browser controller pids.length ${pids.length} is not 1 when trying to connect to browserUrl ${browserUrl}`);
|
|
8062
8091
|
} else {
|
|
8063
8092
|
browserPid = pids[0];
|
|
8064
8093
|
}
|
|
@@ -8102,6 +8131,10 @@ var controller = new LsdBrowserController();
|
|
|
8102
8131
|
export {
|
|
8103
8132
|
CheerioElement,
|
|
8104
8133
|
CheerioPage,
|
|
8134
|
+
ControllerEvent,
|
|
8135
|
+
LsdBrowserContextEvent,
|
|
8136
|
+
LsdBrowserEvent,
|
|
8137
|
+
LsdPageEvent,
|
|
8105
8138
|
PlaywrightBrowser,
|
|
8106
8139
|
PlaywrightBrowserContext,
|
|
8107
8140
|
PlaywrightElement,
|