@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.cjs
CHANGED
|
@@ -32,6 +32,10 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
CheerioElement: () => CheerioElement,
|
|
34
34
|
CheerioPage: () => CheerioPage,
|
|
35
|
+
ControllerEvent: () => ControllerEvent,
|
|
36
|
+
LsdBrowserContextEvent: () => LsdBrowserContextEvent,
|
|
37
|
+
LsdBrowserEvent: () => LsdBrowserEvent,
|
|
38
|
+
LsdPageEvent: () => LsdPageEvent,
|
|
35
39
|
PlaywrightBrowser: () => PlaywrightBrowser,
|
|
36
40
|
PlaywrightBrowserContext: () => PlaywrightBrowserContext,
|
|
37
41
|
PlaywrightElement: () => PlaywrightElement,
|
|
@@ -45,6 +49,32 @@ __export(src_exports, {
|
|
|
45
49
|
});
|
|
46
50
|
module.exports = __toCommonJS(src_exports);
|
|
47
51
|
|
|
52
|
+
// src/types/types.ts
|
|
53
|
+
var ControllerEvent = /* @__PURE__ */ ((ControllerEvent2) => {
|
|
54
|
+
ControllerEvent2["BROWSERCONTEXT_CLOSE"] = "close";
|
|
55
|
+
ControllerEvent2["BROWSERCONTEXT_PAGE"] = "page";
|
|
56
|
+
ControllerEvent2["BROWSERCONTEXT_TARGETCREATED"] = "targetcreated";
|
|
57
|
+
ControllerEvent2["BROWSER_DISCONNECTED"] = "disconnected";
|
|
58
|
+
ControllerEvent2["PAGE_CLOSE"] = "close";
|
|
59
|
+
ControllerEvent2["PAGE_POUP"] = "popup";
|
|
60
|
+
ControllerEvent2["PAGE_REQUEST"] = "request";
|
|
61
|
+
ControllerEvent2["PAGE_RESPONSE"] = "response";
|
|
62
|
+
return ControllerEvent2;
|
|
63
|
+
})(ControllerEvent || {});
|
|
64
|
+
var LsdPageEvent = /* @__PURE__ */ ((LsdPageEvent2) => {
|
|
65
|
+
LsdPageEvent2["PAGE_CLOSE"] = "pageClose";
|
|
66
|
+
LsdPageEvent2["PAGE_POPUP"] = "pagePopup";
|
|
67
|
+
return LsdPageEvent2;
|
|
68
|
+
})(LsdPageEvent || {});
|
|
69
|
+
var LsdBrowserContextEvent = /* @__PURE__ */ ((LsdBrowserContextEvent2) => {
|
|
70
|
+
LsdBrowserContextEvent2["PAGE_CLOSE"] = "pageClose";
|
|
71
|
+
return LsdBrowserContextEvent2;
|
|
72
|
+
})(LsdBrowserContextEvent || {});
|
|
73
|
+
var LsdBrowserEvent = /* @__PURE__ */ ((LsdBrowserEvent2) => {
|
|
74
|
+
LsdBrowserEvent2["BROWSER_CONTEXT_CLOSE"] = "browserContextClose";
|
|
75
|
+
return LsdBrowserEvent2;
|
|
76
|
+
})(LsdBrowserEvent || {});
|
|
77
|
+
|
|
48
78
|
// src/utils/log.ts
|
|
49
79
|
var import_utils = require("@letsscrapedata/utils");
|
|
50
80
|
var pkgLog = import_utils.log;
|
|
@@ -56,6 +86,9 @@ function setControllerLogFun(logFun) {
|
|
|
56
86
|
return false;
|
|
57
87
|
}
|
|
58
88
|
}
|
|
89
|
+
async function logdbg(...args) {
|
|
90
|
+
await pkgLog(import_utils.LogLevel.DBG, ...args);
|
|
91
|
+
}
|
|
59
92
|
async function loginfo(...args) {
|
|
60
93
|
await pkgLog(import_utils.LogLevel.INF, ...args);
|
|
61
94
|
}
|
|
@@ -419,7 +452,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
419
452
|
const cookieItems = await this.#getCookies(page);
|
|
420
453
|
const domainSet = new Set(cookieItems.map((c) => c.domain));
|
|
421
454
|
if (domainSet.size !== 1) {
|
|
422
|
-
logwarn(
|
|
455
|
+
logwarn(`##browser LsdPage domains in clearCookies: ${Array.from(domainSet.values())}`);
|
|
423
456
|
}
|
|
424
457
|
for (const domain of domainSet.values()) {
|
|
425
458
|
await browserContext.clearCookies({ domain });
|
|
@@ -625,15 +658,15 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
625
658
|
}
|
|
626
659
|
const page = this.#page;
|
|
627
660
|
const pageId = this.#pageId;
|
|
628
|
-
page.on("close"
|
|
629
|
-
loginfo(`##browser
|
|
661
|
+
page.on("close" /* PAGE_CLOSE */, async () => {
|
|
662
|
+
loginfo(`##browser page ${pageId} closed @LsdPage`);
|
|
630
663
|
if (!page.pageInfo) {
|
|
631
|
-
logerr(
|
|
664
|
+
logerr(`##browser LsdPage logic error in page.on("close")`);
|
|
632
665
|
}
|
|
633
|
-
this.emit("pageClose");
|
|
634
|
-
this.#lsdBrowserContext.emit("pageClose"
|
|
666
|
+
this.emit("pageClose" /* PAGE_CLOSE */);
|
|
667
|
+
this.#lsdBrowserContext.emit("pageClose" /* PAGE_CLOSE */, this);
|
|
635
668
|
});
|
|
636
|
-
page.on("popup"
|
|
669
|
+
page.on("popup" /* PAGE_POUP */, (p) => {
|
|
637
670
|
if (p) {
|
|
638
671
|
let evtData = null;
|
|
639
672
|
const pageInfo = p.pageInfo;
|
|
@@ -647,12 +680,12 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
647
680
|
pageInfo.relatedId = page.pageInfo.taskId;
|
|
648
681
|
}
|
|
649
682
|
} else {
|
|
650
|
-
logerr(`##browser
|
|
683
|
+
logerr(`##browser page ${pageId} has popup without page.pageInfo @LsdPage`);
|
|
651
684
|
}
|
|
652
|
-
loginfo(`##browser
|
|
653
|
-
this.emit("pagePopup"
|
|
685
|
+
loginfo(`##browser page ${pageId} has popup ${popupPageId} @LsdPage`);
|
|
686
|
+
this.emit("pagePopup" /* PAGE_POPUP */, evtData);
|
|
654
687
|
} else {
|
|
655
|
-
logerr(`##browser ${pageId} has popup page with null page`);
|
|
688
|
+
logerr(`##browser page ${pageId} has popup page with null page @LsdPage`);
|
|
656
689
|
}
|
|
657
690
|
});
|
|
658
691
|
}
|
|
@@ -667,13 +700,14 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
667
700
|
const currentTime = (0, import_utils3.getCurrentUnixTime)();
|
|
668
701
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
669
702
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
670
|
-
this.#pageId = `
|
|
703
|
+
this.#pageId = `PlaywrightPage-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
671
704
|
this.#closeWhenFree = false;
|
|
672
705
|
this.#resquestInterceptionOptions = [];
|
|
673
706
|
this.#responseInterceptionOptions = [];
|
|
674
707
|
this.#client = null;
|
|
675
708
|
this.#responseCb = null;
|
|
676
709
|
this.#isDebugTask = false;
|
|
710
|
+
loginfo(`##browser LsdPage ${this.#pageId} ${openType}ed`);
|
|
677
711
|
this.#addPageOn();
|
|
678
712
|
}
|
|
679
713
|
async addPreloadScript(scriptOrFunc, arg) {
|
|
@@ -754,7 +788,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
754
788
|
}
|
|
755
789
|
async close() {
|
|
756
790
|
if (this.#status === "closed") {
|
|
757
|
-
logwarn(
|
|
791
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already closed.`);
|
|
758
792
|
return true;
|
|
759
793
|
} else if (this.#status === "busy") {
|
|
760
794
|
throw new Error(`Page ${this.#pageId} cannot be closed because it is busy.`);
|
|
@@ -765,6 +799,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
765
799
|
await this.#page.close();
|
|
766
800
|
this.#page = null;
|
|
767
801
|
this.#status = "closed";
|
|
802
|
+
loginfo(`##browser LsdPage ${this.#pageId} is closed`);
|
|
768
803
|
return true;
|
|
769
804
|
}
|
|
770
805
|
closeWhenFree() {
|
|
@@ -849,10 +884,11 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
849
884
|
return [];
|
|
850
885
|
}
|
|
851
886
|
async free() {
|
|
852
|
-
if (this.#status === "free") {
|
|
853
|
-
logwarn(
|
|
887
|
+
if (this.#status === "free" && this.pageInfo().openType !== "popup") {
|
|
888
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already free.`);
|
|
854
889
|
}
|
|
855
890
|
this.#status = "free";
|
|
891
|
+
logdbg(`##browser LsdPage ${this.#pageId} is freed`);
|
|
856
892
|
await this.clearRequestInterceptions();
|
|
857
893
|
await this.clearResponseInterceptions();
|
|
858
894
|
return true;
|
|
@@ -1134,7 +1170,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
1134
1170
|
}
|
|
1135
1171
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
1136
1172
|
if (actOptions.length <= 0) {
|
|
1137
|
-
logwarn("
|
|
1173
|
+
logwarn("##browser LsdPage invalid paras in setRequestInterception");
|
|
1138
1174
|
return false;
|
|
1139
1175
|
}
|
|
1140
1176
|
const firstRequestInterception = this.#resquestInterceptionOptions.length <= 0;
|
|
@@ -1157,9 +1193,9 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
1157
1193
|
const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
1158
1194
|
if (this.#isDebugTask) {
|
|
1159
1195
|
if (matchedFlag) {
|
|
1160
|
-
|
|
1196
|
+
loginfo(`##browser matched request ${request.method()} ${request.url()}`);
|
|
1161
1197
|
} else {
|
|
1162
|
-
|
|
1198
|
+
logdbg(`##browser unmatched request ${request.method()} ${request.url()}`);
|
|
1163
1199
|
}
|
|
1164
1200
|
}
|
|
1165
1201
|
if (matchedFlag) {
|
|
@@ -1215,9 +1251,9 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
1215
1251
|
}
|
|
1216
1252
|
if (this.#isDebugTask) {
|
|
1217
1253
|
if (matchedFlag) {
|
|
1218
|
-
|
|
1254
|
+
loginfo(`##browser matched response ${request.method()} ${request.url()}`);
|
|
1219
1255
|
} else {
|
|
1220
|
-
|
|
1256
|
+
logdbg(`##browser unmatched response ${request.method()} ${request.url()}`);
|
|
1221
1257
|
}
|
|
1222
1258
|
}
|
|
1223
1259
|
if (!matchedFlag) {
|
|
@@ -1255,7 +1291,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
1255
1291
|
}
|
|
1256
1292
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
1257
1293
|
if (actOptions.length <= 0) {
|
|
1258
|
-
logwarn("
|
|
1294
|
+
logwarn("##browser LsdPage invalid paras in setResponseInterception");
|
|
1259
1295
|
return false;
|
|
1260
1296
|
}
|
|
1261
1297
|
const firstResponseInterception = this.#responseInterceptionOptions.length <= 0;
|
|
@@ -1268,7 +1304,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
1268
1304
|
}
|
|
1269
1305
|
if (firstResponseInterception && this.#responseInterceptionOptions.length > 0) {
|
|
1270
1306
|
this.#responseCb = this.#responseListener.bind(this);
|
|
1271
|
-
this.#page.on("response"
|
|
1307
|
+
this.#page.on("response" /* PAGE_RESPONSE */, this.#responseCb);
|
|
1272
1308
|
}
|
|
1273
1309
|
return true;
|
|
1274
1310
|
}
|
|
@@ -1316,6 +1352,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
1316
1352
|
throw new Error(`Page ${this.#pageId} is already busy!!!`);
|
|
1317
1353
|
}
|
|
1318
1354
|
this.#status = "busy";
|
|
1355
|
+
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
1319
1356
|
return true;
|
|
1320
1357
|
}
|
|
1321
1358
|
async waitForElement(selector, options = {}) {
|
|
@@ -1454,11 +1491,10 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1454
1491
|
for (const page of pages) {
|
|
1455
1492
|
const pageInfo = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType, openTime: this.#createTime, lastStatusUpdateTime, taskId: 0, relatedId: 0, misc: {} };
|
|
1456
1493
|
const lsdPage = new PlaywrightPage(this, page, pageInfo);
|
|
1494
|
+
this.#lsdPages.push(lsdPage);
|
|
1457
1495
|
if (this.#maxViewportOfNewPage) {
|
|
1458
1496
|
await lsdPage.maximizeViewport();
|
|
1459
1497
|
}
|
|
1460
|
-
this.#lsdPages.push(lsdPage);
|
|
1461
|
-
loginfo(`##browser ${lsdPage.id()} ${openType}ed`);
|
|
1462
1498
|
}
|
|
1463
1499
|
}
|
|
1464
1500
|
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, maxViewportOfNewPage = true) {
|
|
@@ -1488,8 +1524,9 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1488
1524
|
this.#lsdPages = [];
|
|
1489
1525
|
this.#nextPageIdx = 1;
|
|
1490
1526
|
this.#gettingPage = false;
|
|
1527
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} is created`);
|
|
1491
1528
|
this.#initPages();
|
|
1492
|
-
browserContext.on("page"
|
|
1529
|
+
browserContext.on("page" /* BROWSERCONTEXT_PAGE */, async (page) => {
|
|
1493
1530
|
const pageInfo = page.pageInfo;
|
|
1494
1531
|
if (pageInfo) {
|
|
1495
1532
|
const { browserIdx: browserIdx2, browserContextIdx: browserContextIdx2, pageIdx } = pageInfo;
|
|
@@ -1498,27 +1535,26 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1498
1535
|
const currentTime2 = (0, import_utils4.getCurrentUnixTime)();
|
|
1499
1536
|
const pageInfo2 = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType: "other", openTime: currentTime2, lastStatusUpdateTime: currentTime2, taskId: 0, relatedId: 0, misc: {} };
|
|
1500
1537
|
const lsdPage = new PlaywrightPage(this, page, pageInfo2);
|
|
1538
|
+
this.#lsdPages.push(lsdPage);
|
|
1501
1539
|
if (this.#maxViewportOfNewPage) {
|
|
1502
1540
|
await lsdPage.maximizeViewport();
|
|
1503
1541
|
}
|
|
1504
|
-
this.#lsdPages.push(lsdPage);
|
|
1505
|
-
loginfo(`##page ${lsdPage.id()} created`);
|
|
1506
1542
|
}
|
|
1507
1543
|
});
|
|
1508
|
-
browserContext.on("close"
|
|
1544
|
+
browserContext.on("close" /* BROWSERCONTEXT_CLOSE */, (bc) => {
|
|
1509
1545
|
if (browserContext !== bc) {
|
|
1510
1546
|
logerr(`##browser different browserContext in browserContext.on("close")`);
|
|
1511
1547
|
}
|
|
1512
|
-
this.#lsdBrowser.emit("browserContextClose"
|
|
1548
|
+
this.#lsdBrowser.emit("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, this);
|
|
1513
1549
|
});
|
|
1514
|
-
this.on("pageClose"
|
|
1550
|
+
this.on("pageClose" /* PAGE_CLOSE */, (lsdPage) => {
|
|
1515
1551
|
if (!(lsdPage instanceof PlaywrightPage)) {
|
|
1516
|
-
logerr(
|
|
1552
|
+
logerr(`##browser LsdBrowserContext invalid data in LsdBrowserContext.on("pageClose)`);
|
|
1517
1553
|
return;
|
|
1518
1554
|
}
|
|
1519
1555
|
const idx = this.#lsdPages.findIndex((p) => p === lsdPage);
|
|
1520
1556
|
if (idx < 0) {
|
|
1521
|
-
logerr(
|
|
1557
|
+
logerr(`##browser LsdBrowserContext invalid lsdPage in LsdBrowserContext.on("pageClose)`);
|
|
1522
1558
|
return;
|
|
1523
1559
|
}
|
|
1524
1560
|
this.#lsdPages.splice(idx, 1);
|
|
@@ -1535,7 +1571,7 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1535
1571
|
if (this.#browserContext) {
|
|
1536
1572
|
this.#status = "closed";
|
|
1537
1573
|
this.#lastStatusUpdateTime = (0, import_utils4.getCurrentUnixTime)();
|
|
1538
|
-
loginfo(
|
|
1574
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} closed at ${this.#lastStatusUpdateTime}`);
|
|
1539
1575
|
await this.#browserContext.close();
|
|
1540
1576
|
}
|
|
1541
1577
|
return true;
|
|
@@ -1550,12 +1586,12 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1550
1586
|
await (0, import_utils4.sleep)(200);
|
|
1551
1587
|
}
|
|
1552
1588
|
}
|
|
1553
|
-
logwarn(
|
|
1589
|
+
logwarn(`##browser LsdBrowserContext cannot get the gettingLock.`);
|
|
1554
1590
|
return false;
|
|
1555
1591
|
}
|
|
1556
1592
|
#freeGettingLock() {
|
|
1557
1593
|
if (!this.#gettingPage) {
|
|
1558
|
-
logwarn(
|
|
1594
|
+
logwarn(`##browser LsdBrowserContext gettingLock is already free now.`);
|
|
1559
1595
|
}
|
|
1560
1596
|
this.#gettingPage = false;
|
|
1561
1597
|
}
|
|
@@ -1564,7 +1600,7 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1564
1600
|
maxPageFreeSeconds = this.#maxPageFreeSeconds;
|
|
1565
1601
|
}
|
|
1566
1602
|
if (maxPageFreeSeconds <= 0) {
|
|
1567
|
-
logwarn(
|
|
1603
|
+
logwarn(`##browser LsdBrowserContext please set valid maxPageFreeSeconds to close free pages`);
|
|
1568
1604
|
return false;
|
|
1569
1605
|
}
|
|
1570
1606
|
const gotLock = await this.#tryToGetGettingLock();
|
|
@@ -1661,7 +1697,7 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1661
1697
|
}
|
|
1662
1698
|
}
|
|
1663
1699
|
id() {
|
|
1664
|
-
return `
|
|
1700
|
+
return `PlaywrightContext-${this.#browserIdx}-${this.#browserContextIdx}`;
|
|
1665
1701
|
}
|
|
1666
1702
|
isFree() {
|
|
1667
1703
|
return this.#status === "free";
|
|
@@ -1795,34 +1831,33 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends import_node_events3.def
|
|
|
1795
1831
|
this.#executablePath = executablePath;
|
|
1796
1832
|
this.#nextBrowserContextIdx = 1;
|
|
1797
1833
|
this.#closeFreePagesIntervalId = null;
|
|
1798
|
-
loginfo(`##browser ${this.id()} ${this.#browserCreationMethod}ed
|
|
1834
|
+
loginfo(`##browser LsdBrowser ${this.id()} ${this.#browserCreationMethod}ed}`);
|
|
1799
1835
|
const browserContexts = browser.contexts();
|
|
1800
1836
|
if (browserContexts.length > 0) {
|
|
1801
|
-
logwarn(
|
|
1837
|
+
logwarn(`##browser LsdBrowser there are ${browserContexts.length} new browserContexts when playwright launches new browser`);
|
|
1802
1838
|
}
|
|
1803
1839
|
const incognito = typeof options?.incognito === "boolean" ? options.incognito : true;
|
|
1804
1840
|
for (const browserContext of browserContexts) {
|
|
1805
1841
|
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
1806
1842
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
1807
|
-
loginfo(`##browserContext ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
1808
1843
|
}
|
|
1809
|
-
browser.on("disconnected"
|
|
1844
|
+
browser.on("disconnected" /* BROWSER_DISCONNECTED */, () => {
|
|
1810
1845
|
loginfo(`##browser ${this.id()} disconnected`);
|
|
1811
1846
|
if (this.#lsdBrowserContexts.length > 0) {
|
|
1812
|
-
logerr(
|
|
1847
|
+
logerr(`##browser LsdBrowser ${this.id()} has browserContexts when disconnected`);
|
|
1813
1848
|
}
|
|
1814
1849
|
});
|
|
1815
|
-
this.on("browserContextClose"
|
|
1850
|
+
this.on("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, (lsdBrowserContext) => {
|
|
1816
1851
|
if (!(lsdBrowserContext instanceof PlaywrightBrowserContext)) {
|
|
1817
|
-
logerr(
|
|
1852
|
+
logerr(`##browser LsdBrowser invalid data in LsdBrowser.on("browserContextClose)`);
|
|
1818
1853
|
return;
|
|
1819
1854
|
}
|
|
1820
1855
|
const idx = this.#lsdBrowserContexts.findIndex((bc) => bc === lsdBrowserContext);
|
|
1821
1856
|
if (idx < 0) {
|
|
1822
|
-
logerr(
|
|
1857
|
+
logerr(`##browser LsdBrowser invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
1823
1858
|
return;
|
|
1824
1859
|
}
|
|
1825
|
-
loginfo(`##
|
|
1860
|
+
loginfo(`##browser ${lsdBrowserContext.id()} closed
|
|
1826
1861
|
`);
|
|
1827
1862
|
this.#lsdBrowserContexts.splice(idx, 1);
|
|
1828
1863
|
if (this.#lsdBrowserContexts.length === 0) {
|
|
@@ -1843,7 +1878,7 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends import_node_events3.def
|
|
|
1843
1878
|
}
|
|
1844
1879
|
async newBrowserContext(options) {
|
|
1845
1880
|
if (this.#lsdBrowserContexts.length >= this.#maxBrowserContextsPerBrowser()) {
|
|
1846
|
-
logwarn(`##browser ${this.id()} can not create more new browserContext`);
|
|
1881
|
+
logwarn(`##browser LsdBrowser ${this.id()} can not create more new browserContext`);
|
|
1847
1882
|
return null;
|
|
1848
1883
|
}
|
|
1849
1884
|
const browserContextOptions = {};
|
|
@@ -1862,7 +1897,6 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends import_node_events3.def
|
|
|
1862
1897
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
1863
1898
|
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
1864
1899
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
1865
|
-
loginfo(`##browser ${lsdBrowserContext.id()} created`);
|
|
1866
1900
|
return lsdBrowserContext;
|
|
1867
1901
|
}
|
|
1868
1902
|
async close() {
|
|
@@ -1873,6 +1907,7 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends import_node_events3.def
|
|
|
1873
1907
|
await lsdBrowserContext.close();
|
|
1874
1908
|
}
|
|
1875
1909
|
await this.#browser.close();
|
|
1910
|
+
loginfo(`##browser LsdBrowser ${this.id()} is closed`);
|
|
1876
1911
|
return true;
|
|
1877
1912
|
}
|
|
1878
1913
|
browserContexts() {
|
|
@@ -1898,7 +1933,7 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends import_node_events3.def
|
|
|
1898
1933
|
return this.#executablePath;
|
|
1899
1934
|
}
|
|
1900
1935
|
id() {
|
|
1901
|
-
return `
|
|
1936
|
+
return `PlaywrightBrowser-${this.#browserType}-${this.#browserIdx}`;
|
|
1902
1937
|
}
|
|
1903
1938
|
isConnected() {
|
|
1904
1939
|
return this.#browser.isConnected();
|
|
@@ -2131,7 +2166,6 @@ var PuppeteerElement = class _PuppeteerElement {
|
|
|
2131
2166
|
await this.#$ele.click(actOptions);
|
|
2132
2167
|
} else if (clickType === "evaluate") {
|
|
2133
2168
|
await this.#frame.evaluate(async (ev) => await ev.click(), this.#$ele);
|
|
2134
|
-
await this.#$ele.click(actOptions);
|
|
2135
2169
|
} else {
|
|
2136
2170
|
(0, import_utils6.unreachable)(clickType);
|
|
2137
2171
|
}
|
|
@@ -2434,15 +2468,15 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2434
2468
|
}
|
|
2435
2469
|
const page = this.#page;
|
|
2436
2470
|
const pageId = this.#pageId;
|
|
2437
|
-
page.on("close"
|
|
2438
|
-
loginfo(`##browser
|
|
2471
|
+
page.on("close" /* PAGE_CLOSE */, async () => {
|
|
2472
|
+
loginfo(`##browser page ${pageId} closed @LsdPage`);
|
|
2439
2473
|
if (!page.pageInfo) {
|
|
2440
|
-
logerr(
|
|
2474
|
+
logerr(`##browser LsdPage logic error in page.on("close")`);
|
|
2441
2475
|
}
|
|
2442
|
-
this.emit("pageClose");
|
|
2443
|
-
this.#lsdBrowserContext.emit("pageClose"
|
|
2476
|
+
this.emit("pageClose" /* PAGE_CLOSE */);
|
|
2477
|
+
this.#lsdBrowserContext.emit("pageClose" /* PAGE_CLOSE */, this);
|
|
2444
2478
|
});
|
|
2445
|
-
page.on("popup"
|
|
2479
|
+
page.on("popup" /* PAGE_POUP */, (p) => {
|
|
2446
2480
|
if (p) {
|
|
2447
2481
|
let evtData = null;
|
|
2448
2482
|
const pageInfo = p.pageInfo;
|
|
@@ -2456,12 +2490,12 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2456
2490
|
pageInfo.relatedId = page.pageInfo.taskId;
|
|
2457
2491
|
}
|
|
2458
2492
|
} else {
|
|
2459
|
-
logerr(`##browser
|
|
2493
|
+
logerr(`##browser page ${pageId} has popup without page.pageInfo @LsdPage`);
|
|
2460
2494
|
}
|
|
2461
|
-
loginfo(`##browser
|
|
2462
|
-
this.emit("pagePopup"
|
|
2495
|
+
loginfo(`##browser page ${pageId} has popup ${popupPageId} @LsdPage`);
|
|
2496
|
+
this.emit("pagePopup" /* PAGE_POPUP */, evtData);
|
|
2463
2497
|
} else {
|
|
2464
|
-
logerr(`##browser ${pageId} has popup page with null page`);
|
|
2498
|
+
logerr(`##browser page ${pageId} has popup page with null page @LsdPage`);
|
|
2465
2499
|
}
|
|
2466
2500
|
});
|
|
2467
2501
|
}
|
|
@@ -2476,12 +2510,13 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2476
2510
|
const currentTime = (0, import_utils7.getCurrentUnixTime)();
|
|
2477
2511
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
2478
2512
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
2479
|
-
this.#pageId = `
|
|
2513
|
+
this.#pageId = `PuppeteerPage-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
2480
2514
|
this.#closeWhenFree = false;
|
|
2481
2515
|
this.#requestInterceptionNum = 0;
|
|
2482
2516
|
this.#responseInterceptionNum = 0;
|
|
2483
2517
|
this.#client = null;
|
|
2484
2518
|
this.#isDebugTask = false;
|
|
2519
|
+
loginfo(`##browser LsdPage ${this.#pageId} ${openType}ed`);
|
|
2485
2520
|
this.#addPageOn();
|
|
2486
2521
|
}
|
|
2487
2522
|
async addPreloadScript(scriptOrFunc, arg) {
|
|
@@ -2559,7 +2594,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2559
2594
|
}
|
|
2560
2595
|
async close() {
|
|
2561
2596
|
if (this.#status === "closed") {
|
|
2562
|
-
logwarn(
|
|
2597
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already closed.`);
|
|
2563
2598
|
return true;
|
|
2564
2599
|
} else if (this.#status === "busy") {
|
|
2565
2600
|
throw new Error(`Page ${this.#pageId} cannot be closed because it is busy.`);
|
|
@@ -2570,6 +2605,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2570
2605
|
await this.#page.close();
|
|
2571
2606
|
this.#page = null;
|
|
2572
2607
|
this.#status = "closed";
|
|
2608
|
+
loginfo(`##browser LsdPage ${this.#pageId} is closed`);
|
|
2573
2609
|
return true;
|
|
2574
2610
|
}
|
|
2575
2611
|
closeWhenFree() {
|
|
@@ -2654,10 +2690,11 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2654
2690
|
return [];
|
|
2655
2691
|
}
|
|
2656
2692
|
async free() {
|
|
2657
|
-
if (this.#status === "free") {
|
|
2658
|
-
logwarn(
|
|
2693
|
+
if (this.#status === "free" && this.pageInfo().openType !== "popup") {
|
|
2694
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already free.`);
|
|
2659
2695
|
}
|
|
2660
2696
|
this.#status = "free";
|
|
2697
|
+
logdbg(`##browser LsdPage ${this.#pageId} is freed`);
|
|
2661
2698
|
await this.clearRequestInterceptions();
|
|
2662
2699
|
await this.clearResponseInterceptions();
|
|
2663
2700
|
return true;
|
|
@@ -2941,7 +2978,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2941
2978
|
}
|
|
2942
2979
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
2943
2980
|
if (actOptions.length <= 0) {
|
|
2944
|
-
logwarn("
|
|
2981
|
+
logwarn("##browser LsdPage invalid paras in setRequestInterception");
|
|
2945
2982
|
return false;
|
|
2946
2983
|
}
|
|
2947
2984
|
if (this.#requestInterceptionNum <= 0) {
|
|
@@ -2950,16 +2987,16 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2950
2987
|
} else {
|
|
2951
2988
|
this.#requestInterceptionNum++;
|
|
2952
2989
|
}
|
|
2953
|
-
this.#page.on("request"
|
|
2990
|
+
this.#page.on("request" /* PAGE_REQUEST */, async (request) => {
|
|
2954
2991
|
try {
|
|
2955
2992
|
for (const option of actOptions) {
|
|
2956
2993
|
const { requestMatch, action, fulfill } = option;
|
|
2957
2994
|
const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
2958
2995
|
if (this.#isDebugTask) {
|
|
2959
2996
|
if (matchedFlag) {
|
|
2960
|
-
|
|
2997
|
+
loginfo(`##browser matched request ${request.method()} ${request.url()}`);
|
|
2961
2998
|
} else {
|
|
2962
|
-
|
|
2999
|
+
logdbg(`##browser unmatched request ${request.method()} ${request.url()}`);
|
|
2963
3000
|
}
|
|
2964
3001
|
}
|
|
2965
3002
|
if (matchedFlag) {
|
|
@@ -2996,11 +3033,11 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2996
3033
|
}
|
|
2997
3034
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
2998
3035
|
if (actOptions.length <= 0) {
|
|
2999
|
-
logwarn("
|
|
3036
|
+
logwarn("##browser LsdPage invalid paras in setResponseInterception");
|
|
3000
3037
|
return false;
|
|
3001
3038
|
}
|
|
3002
3039
|
this.#responseInterceptionNum++;
|
|
3003
|
-
this.#page.on("response"
|
|
3040
|
+
this.#page.on("response" /* PAGE_RESPONSE */, async (response) => {
|
|
3004
3041
|
try {
|
|
3005
3042
|
if (!response.ok() || !this.#page) {
|
|
3006
3043
|
return false;
|
|
@@ -3023,9 +3060,9 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
3023
3060
|
}
|
|
3024
3061
|
if (this.#isDebugTask) {
|
|
3025
3062
|
if (matchedFlag) {
|
|
3026
|
-
|
|
3063
|
+
loginfo(`##browser matched response ${request.method()} ${request.url()}`);
|
|
3027
3064
|
} else {
|
|
3028
|
-
|
|
3065
|
+
logdbg(`##browser unmatched response ${request.method()} ${request.url()}`);
|
|
3029
3066
|
}
|
|
3030
3067
|
}
|
|
3031
3068
|
if (!matchedFlag) {
|
|
@@ -3044,6 +3081,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
3044
3081
|
requestData,
|
|
3045
3082
|
responseData
|
|
3046
3083
|
});
|
|
3084
|
+
loginfo(`##browser cache matched response: ${requestUrl}`);
|
|
3047
3085
|
}
|
|
3048
3086
|
if (typeof handler === "function") {
|
|
3049
3087
|
const pageData = { pageUrl, cookies: "" };
|
|
@@ -3109,6 +3147,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
3109
3147
|
throw new Error(`Page ${this.#pageId} is already busy!!!`);
|
|
3110
3148
|
}
|
|
3111
3149
|
this.#status = "busy";
|
|
3150
|
+
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
3112
3151
|
return true;
|
|
3113
3152
|
}
|
|
3114
3153
|
async waitForElement(selector, options = {}) {
|
|
@@ -3219,14 +3258,13 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3219
3258
|
for (const page of pages) {
|
|
3220
3259
|
const pageInfo = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType, openTime: this.#createTime, lastStatusUpdateTime, taskId: 0, relatedId: 0, misc: {} };
|
|
3221
3260
|
const lsdPage = new PuppeteerPage(this, page, pageInfo);
|
|
3261
|
+
this.#lsdPages.push(lsdPage);
|
|
3222
3262
|
if (this.#maxViewportOfNewPage) {
|
|
3223
3263
|
await lsdPage.maximizeViewport();
|
|
3224
3264
|
}
|
|
3225
3265
|
if (this.#userAgent) {
|
|
3226
3266
|
await lsdPage.setUserAgent(this.#userAgent);
|
|
3227
3267
|
}
|
|
3228
|
-
this.#lsdPages.push(lsdPage);
|
|
3229
|
-
loginfo(`##browser ${lsdPage.id()} ${openType}ed`);
|
|
3230
3268
|
}
|
|
3231
3269
|
}
|
|
3232
3270
|
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, userAgent = "", maxViewportOfNewPage = true) {
|
|
@@ -3255,8 +3293,9 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3255
3293
|
this.#lsdPages = [];
|
|
3256
3294
|
this.#nextPageIdx = 1;
|
|
3257
3295
|
this.#gettingPage = false;
|
|
3296
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} is created`);
|
|
3258
3297
|
this.#initPages();
|
|
3259
|
-
browserContext.on("targetcreated"
|
|
3298
|
+
browserContext.on("targetcreated" /* BROWSERCONTEXT_TARGETCREATED */, async (p) => {
|
|
3260
3299
|
if (p.type() === "page") {
|
|
3261
3300
|
const page = await p.page();
|
|
3262
3301
|
if (!page) {
|
|
@@ -3270,30 +3309,36 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3270
3309
|
const currentTime2 = (0, import_utils8.getCurrentUnixTime)();
|
|
3271
3310
|
const pageInfo2 = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType: "other", openTime: currentTime2, lastStatusUpdateTime: currentTime2, taskId: 0, relatedId: 0, misc: {} };
|
|
3272
3311
|
const lsdPage = new PuppeteerPage(this, page, pageInfo2);
|
|
3273
|
-
|
|
3274
|
-
await lsdPage.maximizeViewport();
|
|
3275
|
-
}
|
|
3312
|
+
this.#lsdPages.push(lsdPage);
|
|
3276
3313
|
if (this.#userAgent) {
|
|
3277
3314
|
await lsdPage.setUserAgent(this.#userAgent);
|
|
3278
3315
|
}
|
|
3279
|
-
this.#
|
|
3280
|
-
|
|
3316
|
+
if (this.#maxViewportOfNewPage) {
|
|
3317
|
+
await lsdPage.maximizeViewport();
|
|
3318
|
+
}
|
|
3281
3319
|
}
|
|
3282
3320
|
}
|
|
3283
3321
|
});
|
|
3284
|
-
|
|
3322
|
+
browserContext.on("close" /* BROWSERCONTEXT_CLOSE */, (bc) => {
|
|
3323
|
+
logerr(`##browser LsdBrowserContext puppeteer BrowserContext receives close event`);
|
|
3324
|
+
if (browserContext !== bc) {
|
|
3325
|
+
logerr(`##browser LsdBrowserContext different browserContext in browserContext.on("close")`);
|
|
3326
|
+
}
|
|
3327
|
+
this.#lsdBrowser.emit("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, this);
|
|
3328
|
+
});
|
|
3329
|
+
this.on("pageClose" /* PAGE_CLOSE */, (lsdPage) => {
|
|
3285
3330
|
if (!(lsdPage instanceof PuppeteerPage)) {
|
|
3286
|
-
logerr(
|
|
3331
|
+
logerr(`##browser LsdBrowserContext invalid data in LsdBrowserContext.on("pageClose)`);
|
|
3287
3332
|
return;
|
|
3288
3333
|
}
|
|
3289
3334
|
const idx = this.#lsdPages.findIndex((p) => p === lsdPage);
|
|
3290
3335
|
if (idx < 0) {
|
|
3291
|
-
logerr(
|
|
3336
|
+
logerr(`##browser LsdBrowserContext invalid lsdPage in LsdBrowserContext.on("pageClose)`);
|
|
3292
3337
|
return;
|
|
3293
3338
|
}
|
|
3294
3339
|
this.#lsdPages.splice(idx, 1);
|
|
3295
3340
|
if (this.#lsdPages.length === 0) {
|
|
3296
|
-
this.#lsdBrowser.emit("browserContextClose"
|
|
3341
|
+
this.#lsdBrowser.emit("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, this);
|
|
3297
3342
|
}
|
|
3298
3343
|
return;
|
|
3299
3344
|
});
|
|
@@ -3308,7 +3353,7 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3308
3353
|
if (this.#browserContext) {
|
|
3309
3354
|
this.#status = "closed";
|
|
3310
3355
|
this.#lastStatusUpdateTime = (0, import_utils8.getCurrentUnixTime)();
|
|
3311
|
-
loginfo(
|
|
3356
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} closed at ${this.#lastStatusUpdateTime}`);
|
|
3312
3357
|
if (this.#browserContextCreationMethod !== "launch") {
|
|
3313
3358
|
await this.#browserContext.close();
|
|
3314
3359
|
}
|
|
@@ -3325,12 +3370,12 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3325
3370
|
await (0, import_utils8.sleep)(200);
|
|
3326
3371
|
}
|
|
3327
3372
|
}
|
|
3328
|
-
logwarn(
|
|
3373
|
+
logwarn(`##browser LsdBrowserContext cannot get the gettingLock.`);
|
|
3329
3374
|
return false;
|
|
3330
3375
|
}
|
|
3331
3376
|
#freeGettingLock() {
|
|
3332
3377
|
if (!this.#gettingPage) {
|
|
3333
|
-
logwarn(
|
|
3378
|
+
logwarn(`##browser LsdBrowserContext gettingLock is already free now.`);
|
|
3334
3379
|
}
|
|
3335
3380
|
this.#gettingPage = false;
|
|
3336
3381
|
}
|
|
@@ -3339,7 +3384,7 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3339
3384
|
maxPageFreeSeconds = this.#maxPageFreeSeconds;
|
|
3340
3385
|
}
|
|
3341
3386
|
if (maxPageFreeSeconds <= 0) {
|
|
3342
|
-
logwarn(
|
|
3387
|
+
logwarn(`##browser LsdBrowserContext please set valid maxPageFreeSeconds to close free pages`);
|
|
3343
3388
|
return false;
|
|
3344
3389
|
}
|
|
3345
3390
|
const gotLock = await this.#tryToGetGettingLock();
|
|
@@ -3438,7 +3483,7 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3438
3483
|
}
|
|
3439
3484
|
}
|
|
3440
3485
|
id() {
|
|
3441
|
-
return `
|
|
3486
|
+
return `PuppeteerContext-${this.#browserIdx}-${this.#browserContextIdx}`;
|
|
3442
3487
|
}
|
|
3443
3488
|
isIncognito() {
|
|
3444
3489
|
return this.#incognito;
|
|
@@ -3472,7 +3517,7 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3472
3517
|
}
|
|
3473
3518
|
if (localStorageOrigins.length > 0) {
|
|
3474
3519
|
await origPage.setRequestInterception(true);
|
|
3475
|
-
origPage.on("request"
|
|
3520
|
+
origPage.on("request" /* PAGE_REQUEST */, (request) => {
|
|
3476
3521
|
request.respond({
|
|
3477
3522
|
status: 200,
|
|
3478
3523
|
// contentType: "text/html; charset=utf-8", // "text/plain",
|
|
@@ -3575,28 +3620,27 @@ var PuppeteerBrowser = class _PuppeteerBrowser extends import_node_events6.defau
|
|
|
3575
3620
|
this.#executablePath = executablePath;
|
|
3576
3621
|
this.#nextBrowserContextIdx = 1;
|
|
3577
3622
|
this.#closeFreePagesIntervalId = null;
|
|
3578
|
-
loginfo(`##browser
|
|
3623
|
+
loginfo(`##browser LsdBrowser ${this.id()} ${this.#browserCreationMethod}ed}`);
|
|
3579
3624
|
const browserContexts = browser.browserContexts();
|
|
3580
3625
|
const incognito = typeof options?.incognito === "boolean" ? options.incognito : false;
|
|
3581
3626
|
for (const browserContext of browserContexts) {
|
|
3582
3627
|
const lsdBrowserContext = new PuppeteerBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), this.#userAgent(), maxViewportOfNewPage);
|
|
3583
3628
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
3584
|
-
loginfo(`##browser ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
3585
3629
|
}
|
|
3586
|
-
browser.on("disconnected"
|
|
3630
|
+
browser.on("disconnected" /* BROWSER_DISCONNECTED */, () => {
|
|
3587
3631
|
loginfo(`##browser ${this.id()} disconnected`);
|
|
3588
3632
|
if (this.#lsdBrowserContexts.length > 0) {
|
|
3589
|
-
logerr(
|
|
3633
|
+
logerr(`##browser LsdBrowser ${this.id()} has browserContexts when disconnected`);
|
|
3590
3634
|
}
|
|
3591
3635
|
});
|
|
3592
|
-
this.on("browserContextClose"
|
|
3636
|
+
this.on("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, (lsdBrowserContext) => {
|
|
3593
3637
|
if (!(lsdBrowserContext instanceof PuppeteerBrowserContext)) {
|
|
3594
|
-
logerr(
|
|
3638
|
+
logerr(`##browser LsdBrowser invalid data in LsdBrowser.on("browserContextClose)`);
|
|
3595
3639
|
return;
|
|
3596
3640
|
}
|
|
3597
3641
|
const idx = this.#lsdBrowserContexts.findIndex((bc) => bc === lsdBrowserContext);
|
|
3598
3642
|
if (idx < 0) {
|
|
3599
|
-
logerr(
|
|
3643
|
+
logerr(`##browser LsdBrowser invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
3600
3644
|
return;
|
|
3601
3645
|
}
|
|
3602
3646
|
loginfo(`##browser ${lsdBrowserContext.id()} closed
|
|
@@ -3620,7 +3664,7 @@ var PuppeteerBrowser = class _PuppeteerBrowser extends import_node_events6.defau
|
|
|
3620
3664
|
}
|
|
3621
3665
|
async newBrowserContext(options) {
|
|
3622
3666
|
if (this.#lsdBrowserContexts.length >= this.#maxBrowserContextsPerBrowser()) {
|
|
3623
|
-
logwarn(`##browser ${this.id()} can not create more new browserContext`);
|
|
3667
|
+
logwarn(`##browser LsdBrowser ${this.id()} can not create more new browserContext`);
|
|
3624
3668
|
return null;
|
|
3625
3669
|
}
|
|
3626
3670
|
const browserContextOptions = {};
|
|
@@ -3633,7 +3677,6 @@ var PuppeteerBrowser = class _PuppeteerBrowser extends import_node_events6.defau
|
|
|
3633
3677
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
3634
3678
|
const lsdBrowserContext = new PuppeteerBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), userAgent, maxViewportOfNewPage);
|
|
3635
3679
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
3636
|
-
loginfo(`##browser ${lsdBrowserContext.id()} created`);
|
|
3637
3680
|
return lsdBrowserContext;
|
|
3638
3681
|
}
|
|
3639
3682
|
async close() {
|
|
@@ -3644,6 +3687,7 @@ var PuppeteerBrowser = class _PuppeteerBrowser extends import_node_events6.defau
|
|
|
3644
3687
|
await lsdBrowserContext.close();
|
|
3645
3688
|
}
|
|
3646
3689
|
await this.#browser.close();
|
|
3690
|
+
loginfo(`##browser LsdBrowser ${this.id()} is closed`);
|
|
3647
3691
|
return true;
|
|
3648
3692
|
}
|
|
3649
3693
|
browserContexts() {
|
|
@@ -3669,7 +3713,7 @@ var PuppeteerBrowser = class _PuppeteerBrowser extends import_node_events6.defau
|
|
|
3669
3713
|
return this.#executablePath;
|
|
3670
3714
|
}
|
|
3671
3715
|
id() {
|
|
3672
|
-
return `
|
|
3716
|
+
return `PuppeteerBrowser-${this.#browserIdx}`;
|
|
3673
3717
|
}
|
|
3674
3718
|
isConnected() {
|
|
3675
3719
|
return this.#browser.connected;
|
|
@@ -4414,7 +4458,7 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
4414
4458
|
const cookieItems = await this.#getCookies(page);
|
|
4415
4459
|
const domainSet = new Set(cookieItems.map((c) => c.domain));
|
|
4416
4460
|
if (domainSet.size !== 1) {
|
|
4417
|
-
logwarn(
|
|
4461
|
+
logwarn(`##browser LsdPage domains in clearCookies: ${Array.from(domainSet.values())}`);
|
|
4418
4462
|
}
|
|
4419
4463
|
for (const domain of domainSet.values()) {
|
|
4420
4464
|
await browserContext.clearCookies({ domain });
|
|
@@ -4620,15 +4664,15 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
4620
4664
|
}
|
|
4621
4665
|
const page = this.#page;
|
|
4622
4666
|
const pageId = this.#pageId;
|
|
4623
|
-
page.on("close"
|
|
4624
|
-
loginfo(`##browser
|
|
4667
|
+
page.on("close" /* PAGE_CLOSE */, async () => {
|
|
4668
|
+
loginfo(`##browser page ${pageId} closed @LsdPage`);
|
|
4625
4669
|
if (!page.pageInfo) {
|
|
4626
|
-
logerr(
|
|
4670
|
+
logerr(`##browser LsdPage logic error in page.on("close")`);
|
|
4627
4671
|
}
|
|
4628
|
-
this.emit("pageClose");
|
|
4629
|
-
this.#lsdBrowserContext.emit("pageClose"
|
|
4672
|
+
this.emit("pageClose" /* PAGE_CLOSE */);
|
|
4673
|
+
this.#lsdBrowserContext.emit("pageClose" /* PAGE_CLOSE */, this);
|
|
4630
4674
|
});
|
|
4631
|
-
page.on("popup"
|
|
4675
|
+
page.on("popup" /* PAGE_POUP */, (p) => {
|
|
4632
4676
|
if (p) {
|
|
4633
4677
|
let evtData = null;
|
|
4634
4678
|
const pageInfo = p.pageInfo;
|
|
@@ -4642,12 +4686,12 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
4642
4686
|
pageInfo.relatedId = page.pageInfo.taskId;
|
|
4643
4687
|
}
|
|
4644
4688
|
} else {
|
|
4645
|
-
logerr(`##browser
|
|
4689
|
+
logerr(`##browser page ${pageId} has popup without page.pageInfo @LsdPage`);
|
|
4646
4690
|
}
|
|
4647
|
-
loginfo(`##browser
|
|
4648
|
-
this.emit("pagePopup"
|
|
4691
|
+
loginfo(`##browser page ${pageId} has popup ${popupPageId} @LsdPage`);
|
|
4692
|
+
this.emit("pagePopup" /* PAGE_POPUP */, evtData);
|
|
4649
4693
|
} else {
|
|
4650
|
-
logerr(`##browser ${pageId} has popup page with null page`);
|
|
4694
|
+
logerr(`##browser page ${pageId} has popup page with null page @LsdPage`);
|
|
4651
4695
|
}
|
|
4652
4696
|
});
|
|
4653
4697
|
}
|
|
@@ -4662,13 +4706,14 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
4662
4706
|
const currentTime = (0, import_utils11.getCurrentUnixTime)();
|
|
4663
4707
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
4664
4708
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
4665
|
-
this.#pageId = `
|
|
4709
|
+
this.#pageId = `PatchrightPage-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
4666
4710
|
this.#closeWhenFree = false;
|
|
4667
4711
|
this.#resquestInterceptionOptions = [];
|
|
4668
4712
|
this.#responseInterceptionOptions = [];
|
|
4669
4713
|
this.#client = null;
|
|
4670
4714
|
this.#responseCb = null;
|
|
4671
4715
|
this.#isDebugTask = false;
|
|
4716
|
+
loginfo(`##browser LsdPage ${this.#pageId} ${openType}ed`);
|
|
4672
4717
|
this.#addPageOn();
|
|
4673
4718
|
}
|
|
4674
4719
|
async addPreloadScript(scriptOrFunc, arg) {
|
|
@@ -4749,7 +4794,7 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
4749
4794
|
}
|
|
4750
4795
|
async close() {
|
|
4751
4796
|
if (this.#status === "closed") {
|
|
4752
|
-
logwarn(
|
|
4797
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already closed.`);
|
|
4753
4798
|
return true;
|
|
4754
4799
|
} else if (this.#status === "busy") {
|
|
4755
4800
|
throw new Error(`Page ${this.#pageId} cannot be closed because it is busy.`);
|
|
@@ -4760,6 +4805,7 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
4760
4805
|
await this.#page.close();
|
|
4761
4806
|
this.#page = null;
|
|
4762
4807
|
this.#status = "closed";
|
|
4808
|
+
loginfo(`##browser LsdPage ${this.#pageId} is closed`);
|
|
4763
4809
|
return true;
|
|
4764
4810
|
}
|
|
4765
4811
|
closeWhenFree() {
|
|
@@ -4843,10 +4889,11 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
4843
4889
|
return [];
|
|
4844
4890
|
}
|
|
4845
4891
|
async free() {
|
|
4846
|
-
if (this.#status === "free") {
|
|
4847
|
-
logwarn(
|
|
4892
|
+
if (this.#status === "free" && this.pageInfo().openType !== "popup") {
|
|
4893
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already free.`);
|
|
4848
4894
|
}
|
|
4849
4895
|
this.#status = "free";
|
|
4896
|
+
logdbg(`##browser LsdPage ${this.#pageId} is freed`);
|
|
4850
4897
|
await this.clearRequestInterceptions();
|
|
4851
4898
|
await this.clearResponseInterceptions();
|
|
4852
4899
|
return true;
|
|
@@ -5128,7 +5175,7 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
5128
5175
|
}
|
|
5129
5176
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
5130
5177
|
if (actOptions.length <= 0) {
|
|
5131
|
-
logwarn("
|
|
5178
|
+
logwarn("##browser LsdPage invalid paras in setRequestInterception");
|
|
5132
5179
|
return false;
|
|
5133
5180
|
}
|
|
5134
5181
|
const firstRequestInterception = this.#resquestInterceptionOptions.length <= 0;
|
|
@@ -5151,9 +5198,9 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
5151
5198
|
const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
5152
5199
|
if (this.#isDebugTask) {
|
|
5153
5200
|
if (matchedFlag) {
|
|
5154
|
-
|
|
5201
|
+
loginfo(`##browser matched request ${request.method()} ${request.url()}`);
|
|
5155
5202
|
} else {
|
|
5156
|
-
|
|
5203
|
+
logdbg(`##browser unmatched request ${request.method()} ${request.url()}`);
|
|
5157
5204
|
}
|
|
5158
5205
|
}
|
|
5159
5206
|
if (matchedFlag) {
|
|
@@ -5209,9 +5256,9 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
5209
5256
|
}
|
|
5210
5257
|
if (this.#isDebugTask) {
|
|
5211
5258
|
if (matchedFlag) {
|
|
5212
|
-
|
|
5259
|
+
loginfo(`##browser matched response ${request.method()} ${request.url()}`);
|
|
5213
5260
|
} else {
|
|
5214
|
-
|
|
5261
|
+
logdbg(`##browser unmatched response ${request.method()} ${request.url()}`);
|
|
5215
5262
|
}
|
|
5216
5263
|
}
|
|
5217
5264
|
if (!matchedFlag) {
|
|
@@ -5249,7 +5296,7 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
5249
5296
|
}
|
|
5250
5297
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
5251
5298
|
if (actOptions.length <= 0) {
|
|
5252
|
-
logwarn("
|
|
5299
|
+
logwarn("##browser LsdPage invalid paras in setResponseInterception");
|
|
5253
5300
|
return false;
|
|
5254
5301
|
}
|
|
5255
5302
|
const firstResponseInterception = this.#responseInterceptionOptions.length <= 0;
|
|
@@ -5262,7 +5309,7 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
5262
5309
|
}
|
|
5263
5310
|
if (firstResponseInterception && this.#responseInterceptionOptions.length > 0) {
|
|
5264
5311
|
this.#responseCb = this.#responseListener.bind(this);
|
|
5265
|
-
this.#page.on("response"
|
|
5312
|
+
this.#page.on("response" /* PAGE_RESPONSE */, this.#responseCb);
|
|
5266
5313
|
}
|
|
5267
5314
|
return true;
|
|
5268
5315
|
}
|
|
@@ -5310,6 +5357,7 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
5310
5357
|
throw new Error(`Page ${this.#pageId} is already busy!!!`);
|
|
5311
5358
|
}
|
|
5312
5359
|
this.#status = "busy";
|
|
5360
|
+
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
5313
5361
|
return true;
|
|
5314
5362
|
}
|
|
5315
5363
|
async waitForElement(selector, options = {}) {
|
|
@@ -5448,11 +5496,10 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5448
5496
|
for (const page of pages) {
|
|
5449
5497
|
const pageInfo = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType, openTime: this.#createTime, lastStatusUpdateTime, taskId: 0, relatedId: 0, misc: {} };
|
|
5450
5498
|
const lsdPage = new PatchrightPage(this, page, pageInfo);
|
|
5499
|
+
this.#lsdPages.push(lsdPage);
|
|
5451
5500
|
if (this.#maxViewportOfNewPage) {
|
|
5452
5501
|
await lsdPage.maximizeViewport();
|
|
5453
5502
|
}
|
|
5454
|
-
this.#lsdPages.push(lsdPage);
|
|
5455
|
-
loginfo(`##browser ${lsdPage.id()} ${openType}ed`);
|
|
5456
5503
|
}
|
|
5457
5504
|
}
|
|
5458
5505
|
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, maxViewportOfNewPage = true) {
|
|
@@ -5482,8 +5529,9 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5482
5529
|
this.#lsdPages = [];
|
|
5483
5530
|
this.#nextPageIdx = 1;
|
|
5484
5531
|
this.#gettingPage = false;
|
|
5532
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} is created`);
|
|
5485
5533
|
this.#initPages();
|
|
5486
|
-
browserContext.on("page"
|
|
5534
|
+
browserContext.on("page" /* BROWSERCONTEXT_PAGE */, async (page) => {
|
|
5487
5535
|
const pageInfo = page.pageInfo;
|
|
5488
5536
|
if (pageInfo) {
|
|
5489
5537
|
const { browserIdx: browserIdx2, browserContextIdx: browserContextIdx2, pageIdx } = pageInfo;
|
|
@@ -5492,27 +5540,26 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5492
5540
|
const currentTime2 = (0, import_utils12.getCurrentUnixTime)();
|
|
5493
5541
|
const pageInfo2 = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType: "other", openTime: currentTime2, lastStatusUpdateTime: currentTime2, taskId: 0, relatedId: 0, misc: {} };
|
|
5494
5542
|
const lsdPage = new PatchrightPage(this, page, pageInfo2);
|
|
5543
|
+
this.#lsdPages.push(lsdPage);
|
|
5495
5544
|
if (this.#maxViewportOfNewPage) {
|
|
5496
5545
|
await lsdPage.maximizeViewport();
|
|
5497
5546
|
}
|
|
5498
|
-
this.#lsdPages.push(lsdPage);
|
|
5499
|
-
loginfo(`##page ${lsdPage.id()} created`);
|
|
5500
5547
|
}
|
|
5501
5548
|
});
|
|
5502
|
-
browserContext.on("close"
|
|
5549
|
+
browserContext.on("close" /* BROWSERCONTEXT_CLOSE */, (bc) => {
|
|
5503
5550
|
if (browserContext !== bc) {
|
|
5504
|
-
logerr(`##browser different browserContext in browserContext.on("close")`);
|
|
5551
|
+
logerr(`##browser LsdBrowserContext different browserContext in browserContext.on("close")`);
|
|
5505
5552
|
}
|
|
5506
|
-
this.#lsdBrowser.emit("browserContextClose"
|
|
5553
|
+
this.#lsdBrowser.emit("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, this);
|
|
5507
5554
|
});
|
|
5508
|
-
this.on("pageClose"
|
|
5555
|
+
this.on("pageClose" /* PAGE_CLOSE */, (lsdPage) => {
|
|
5509
5556
|
if (!(lsdPage instanceof PatchrightPage)) {
|
|
5510
|
-
logerr(
|
|
5557
|
+
logerr(`##browser LsdBrowserContext invalid data in LsdBrowserContext.on("pageClose)`);
|
|
5511
5558
|
return;
|
|
5512
5559
|
}
|
|
5513
5560
|
const idx = this.#lsdPages.findIndex((p) => p === lsdPage);
|
|
5514
5561
|
if (idx < 0) {
|
|
5515
|
-
logerr(
|
|
5562
|
+
logerr(`##browser LsdBrowserContext invalid lsdPage in LsdBrowserContext.on("pageClose)`);
|
|
5516
5563
|
return;
|
|
5517
5564
|
}
|
|
5518
5565
|
this.#lsdPages.splice(idx, 1);
|
|
@@ -5529,7 +5576,7 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5529
5576
|
if (this.#browserContext) {
|
|
5530
5577
|
this.#status = "closed";
|
|
5531
5578
|
this.#lastStatusUpdateTime = (0, import_utils12.getCurrentUnixTime)();
|
|
5532
|
-
loginfo(
|
|
5579
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} closed at ${this.#lastStatusUpdateTime}`);
|
|
5533
5580
|
await this.#browserContext.close();
|
|
5534
5581
|
}
|
|
5535
5582
|
return true;
|
|
@@ -5544,12 +5591,12 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5544
5591
|
await (0, import_utils12.sleep)(200);
|
|
5545
5592
|
}
|
|
5546
5593
|
}
|
|
5547
|
-
logwarn(
|
|
5594
|
+
logwarn(`##browser LsdBrowserContext cannot get the gettingLock.`);
|
|
5548
5595
|
return false;
|
|
5549
5596
|
}
|
|
5550
5597
|
#freeGettingLock() {
|
|
5551
5598
|
if (!this.#gettingPage) {
|
|
5552
|
-
logwarn(
|
|
5599
|
+
logwarn(`##browser LsdBrowserContext gettingLock is already free now.`);
|
|
5553
5600
|
}
|
|
5554
5601
|
this.#gettingPage = false;
|
|
5555
5602
|
}
|
|
@@ -5558,7 +5605,7 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5558
5605
|
maxPageFreeSeconds = this.#maxPageFreeSeconds;
|
|
5559
5606
|
}
|
|
5560
5607
|
if (maxPageFreeSeconds <= 0) {
|
|
5561
|
-
logwarn(
|
|
5608
|
+
logwarn(`##browser LsdBrowserContext please set valid maxPageFreeSeconds to close free pages`);
|
|
5562
5609
|
return false;
|
|
5563
5610
|
}
|
|
5564
5611
|
const gotLock = await this.#tryToGetGettingLock();
|
|
@@ -5655,7 +5702,7 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5655
5702
|
}
|
|
5656
5703
|
}
|
|
5657
5704
|
id() {
|
|
5658
|
-
return `
|
|
5705
|
+
return `PatchrightContext-${this.#browserIdx}-${this.#browserContextIdx}`;
|
|
5659
5706
|
}
|
|
5660
5707
|
isFree() {
|
|
5661
5708
|
return this.#status === "free";
|
|
@@ -5789,34 +5836,33 @@ var PatchrightBrowser = class _PatchrightBrowser extends import_node_events10.de
|
|
|
5789
5836
|
this.#executablePath = executablePath;
|
|
5790
5837
|
this.#nextBrowserContextIdx = 1;
|
|
5791
5838
|
this.#closeFreePagesIntervalId = null;
|
|
5792
|
-
loginfo(`##browser ${this.id()} ${this.#browserCreationMethod}ed
|
|
5839
|
+
loginfo(`##browser LsdBrowser ${this.id()} ${this.#browserCreationMethod}ed}`);
|
|
5793
5840
|
const browserContexts = browser.contexts();
|
|
5794
5841
|
if (browserContexts.length > 0) {
|
|
5795
|
-
logwarn(
|
|
5842
|
+
logwarn(`##browser LsdBrowser there are ${browserContexts.length} new browserContexts when playwright launches new browser`);
|
|
5796
5843
|
}
|
|
5797
5844
|
const incognito = typeof options?.incognito === "boolean" ? options.incognito : true;
|
|
5798
5845
|
for (const browserContext of browserContexts) {
|
|
5799
5846
|
const lsdBrowserContext = new PatchrightBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
5800
5847
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
5801
|
-
loginfo(`##browserContext ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
5802
5848
|
}
|
|
5803
|
-
browser.on("disconnected"
|
|
5849
|
+
browser.on("disconnected" /* BROWSER_DISCONNECTED */, () => {
|
|
5804
5850
|
loginfo(`##browser ${this.id()} disconnected`);
|
|
5805
5851
|
if (this.#lsdBrowserContexts.length > 0) {
|
|
5806
|
-
logerr(
|
|
5852
|
+
logerr(`##browser LsdBrowser ${this.id()} has browserContexts when disconnected`);
|
|
5807
5853
|
}
|
|
5808
5854
|
});
|
|
5809
|
-
this.on("browserContextClose"
|
|
5855
|
+
this.on("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, (lsdBrowserContext) => {
|
|
5810
5856
|
if (!(lsdBrowserContext instanceof PatchrightBrowserContext)) {
|
|
5811
|
-
logerr(
|
|
5857
|
+
logerr(`##browser LsdBrowser invalid data in LsdBrowser.on("browserContextClose)`);
|
|
5812
5858
|
return;
|
|
5813
5859
|
}
|
|
5814
5860
|
const idx = this.#lsdBrowserContexts.findIndex((bc) => bc === lsdBrowserContext);
|
|
5815
5861
|
if (idx < 0) {
|
|
5816
|
-
logerr(
|
|
5862
|
+
logerr(`##browser LsdBrowser invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
5817
5863
|
return;
|
|
5818
5864
|
}
|
|
5819
|
-
loginfo(`##
|
|
5865
|
+
loginfo(`##browser ${lsdBrowserContext.id()} closed
|
|
5820
5866
|
`);
|
|
5821
5867
|
this.#lsdBrowserContexts.splice(idx, 1);
|
|
5822
5868
|
if (this.#lsdBrowserContexts.length === 0) {
|
|
@@ -5837,7 +5883,7 @@ var PatchrightBrowser = class _PatchrightBrowser extends import_node_events10.de
|
|
|
5837
5883
|
}
|
|
5838
5884
|
async newBrowserContext(options) {
|
|
5839
5885
|
if (this.#lsdBrowserContexts.length >= this.#maxBrowserContextsPerBrowser()) {
|
|
5840
|
-
logwarn(`##browser ${this.id()} can not create more new browserContext`);
|
|
5886
|
+
logwarn(`##browser LsdBrowser ${this.id()} can not create more new browserContext`);
|
|
5841
5887
|
return null;
|
|
5842
5888
|
}
|
|
5843
5889
|
const browserContextOptions = {};
|
|
@@ -5856,7 +5902,6 @@ var PatchrightBrowser = class _PatchrightBrowser extends import_node_events10.de
|
|
|
5856
5902
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
5857
5903
|
const lsdBrowserContext = new PatchrightBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
5858
5904
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
5859
|
-
loginfo(`##browser ${lsdBrowserContext.id()} created`);
|
|
5860
5905
|
return lsdBrowserContext;
|
|
5861
5906
|
}
|
|
5862
5907
|
async close() {
|
|
@@ -5867,6 +5912,7 @@ var PatchrightBrowser = class _PatchrightBrowser extends import_node_events10.de
|
|
|
5867
5912
|
await lsdBrowserContext.close();
|
|
5868
5913
|
}
|
|
5869
5914
|
await this.#browser.close();
|
|
5915
|
+
loginfo(`##browser LsdBrowser ${this.id()} is closed`);
|
|
5870
5916
|
return true;
|
|
5871
5917
|
}
|
|
5872
5918
|
browserContexts() {
|
|
@@ -5892,7 +5938,7 @@ var PatchrightBrowser = class _PatchrightBrowser extends import_node_events10.de
|
|
|
5892
5938
|
return this.#executablePath;
|
|
5893
5939
|
}
|
|
5894
5940
|
id() {
|
|
5895
|
-
return `
|
|
5941
|
+
return `PatchrightBrowser-${this.#browserType}-${this.#browserIdx}`;
|
|
5896
5942
|
}
|
|
5897
5943
|
isConnected() {
|
|
5898
5944
|
return this.#browser.isConnected();
|
|
@@ -6264,7 +6310,7 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
6264
6310
|
const cookieItems = await this.#getCookies(page);
|
|
6265
6311
|
const domainSet = new Set(cookieItems.map((c) => c.domain));
|
|
6266
6312
|
if (domainSet.size !== 1) {
|
|
6267
|
-
logwarn(
|
|
6313
|
+
logwarn(`##browser LsdPage domains in clearCookies: ${Array.from(domainSet.values())}`);
|
|
6268
6314
|
}
|
|
6269
6315
|
for (const domain of domainSet.values()) {
|
|
6270
6316
|
await browserContext.clearCookies({ domain });
|
|
@@ -6470,15 +6516,15 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
6470
6516
|
}
|
|
6471
6517
|
const page = this.#page;
|
|
6472
6518
|
const pageId = this.#pageId;
|
|
6473
|
-
page.on("close"
|
|
6474
|
-
loginfo(`##browser
|
|
6519
|
+
page.on("close" /* PAGE_CLOSE */, async () => {
|
|
6520
|
+
loginfo(`##browser page ${pageId} closed @LsdPage`);
|
|
6475
6521
|
if (!page.pageInfo) {
|
|
6476
|
-
logerr(
|
|
6522
|
+
logerr(`##browser LsdPage logic error in page.on("close")`);
|
|
6477
6523
|
}
|
|
6478
|
-
this.emit("pageClose");
|
|
6479
|
-
this.#lsdBrowserContext.emit("pageClose"
|
|
6524
|
+
this.emit("pageClose" /* PAGE_CLOSE */);
|
|
6525
|
+
this.#lsdBrowserContext.emit("pageClose" /* PAGE_CLOSE */, this);
|
|
6480
6526
|
});
|
|
6481
|
-
page.on("popup"
|
|
6527
|
+
page.on("popup" /* PAGE_POUP */, (p) => {
|
|
6482
6528
|
if (p) {
|
|
6483
6529
|
let evtData = null;
|
|
6484
6530
|
const pageInfo = p.pageInfo;
|
|
@@ -6492,12 +6538,12 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
6492
6538
|
pageInfo.relatedId = page.pageInfo.taskId;
|
|
6493
6539
|
}
|
|
6494
6540
|
} else {
|
|
6495
|
-
logerr(`##browser
|
|
6541
|
+
logerr(`##browser page ${pageId} has popup without page.pageInfo @LsdPage`);
|
|
6496
6542
|
}
|
|
6497
|
-
loginfo(`##browser
|
|
6498
|
-
this.emit("pagePopup"
|
|
6543
|
+
loginfo(`##browser page ${pageId} has popup ${popupPageId} @LsdPage`);
|
|
6544
|
+
this.emit("pagePopup" /* PAGE_POPUP */, evtData);
|
|
6499
6545
|
} else {
|
|
6500
|
-
logerr(`##browser ${pageId} has popup page with null page`);
|
|
6546
|
+
logerr(`##browser page ${pageId} has popup page with null page @LsdPage`);
|
|
6501
6547
|
}
|
|
6502
6548
|
});
|
|
6503
6549
|
}
|
|
@@ -6512,13 +6558,14 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
6512
6558
|
const currentTime = (0, import_utils15.getCurrentUnixTime)();
|
|
6513
6559
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
6514
6560
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
6515
|
-
this.#pageId = `
|
|
6561
|
+
this.#pageId = `CamoufoxPage-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
6516
6562
|
this.#closeWhenFree = false;
|
|
6517
6563
|
this.#resquestInterceptionOptions = [];
|
|
6518
6564
|
this.#responseInterceptionOptions = [];
|
|
6519
6565
|
this.#client = null;
|
|
6520
6566
|
this.#responseCb = null;
|
|
6521
6567
|
this.#isDebugTask = false;
|
|
6568
|
+
loginfo(`##browser LsdPage ${this.#pageId} ${openType}ed`);
|
|
6522
6569
|
this.#addPageOn();
|
|
6523
6570
|
}
|
|
6524
6571
|
async addPreloadScript() {
|
|
@@ -6586,7 +6633,7 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
6586
6633
|
}
|
|
6587
6634
|
async close() {
|
|
6588
6635
|
if (this.#status === "closed") {
|
|
6589
|
-
logwarn(
|
|
6636
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already closed.`);
|
|
6590
6637
|
return true;
|
|
6591
6638
|
} else if (this.#status === "busy") {
|
|
6592
6639
|
throw new Error(`Page ${this.#pageId} cannot be closed because it is busy.`);
|
|
@@ -6597,6 +6644,7 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
6597
6644
|
await this.#page.close();
|
|
6598
6645
|
this.#page = null;
|
|
6599
6646
|
this.#status = "closed";
|
|
6647
|
+
loginfo(`##browser LsdPage ${this.#pageId} is closed`);
|
|
6600
6648
|
return true;
|
|
6601
6649
|
}
|
|
6602
6650
|
closeWhenFree() {
|
|
@@ -6681,10 +6729,11 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
6681
6729
|
return [];
|
|
6682
6730
|
}
|
|
6683
6731
|
async free() {
|
|
6684
|
-
if (this.#status === "free") {
|
|
6685
|
-
logwarn(
|
|
6732
|
+
if (this.#status === "free" && this.pageInfo().openType !== "popup") {
|
|
6733
|
+
logwarn(`##browser LsdPage ${this.#pageId} is already free.`);
|
|
6686
6734
|
}
|
|
6687
6735
|
this.#status = "free";
|
|
6736
|
+
logdbg(`##browser LsdPage ${this.#pageId} is freed`);
|
|
6688
6737
|
await this.clearRequestInterceptions();
|
|
6689
6738
|
await this.clearResponseInterceptions();
|
|
6690
6739
|
return true;
|
|
@@ -6866,23 +6915,8 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
6866
6915
|
);
|
|
6867
6916
|
return true;
|
|
6868
6917
|
}
|
|
6869
|
-
async sendCDPMessage(
|
|
6870
|
-
|
|
6871
|
-
const origContext = this.browserContext()._origBrowserContext();
|
|
6872
|
-
if (!origContext) {
|
|
6873
|
-
throw new Error(`Invalid playwright browserContext`);
|
|
6874
|
-
}
|
|
6875
|
-
this.#client = await origContext.newCDPSession(this.#page);
|
|
6876
|
-
}
|
|
6877
|
-
if (!this.#client) {
|
|
6878
|
-
throw new Error("No valid CDP session to send message");
|
|
6879
|
-
}
|
|
6880
|
-
const response = params ? await this.#client.send(method, params) : await this.#client.send(method);
|
|
6881
|
-
if (detach) {
|
|
6882
|
-
await this.#client.detach();
|
|
6883
|
-
this.#client = null;
|
|
6884
|
-
}
|
|
6885
|
-
return response;
|
|
6918
|
+
async sendCDPMessage(_method, _params = null, _detach = true) {
|
|
6919
|
+
throw new Error("##browser Camoufox does not support sendCDPMessage");
|
|
6886
6920
|
}
|
|
6887
6921
|
setCloseWhenFree(closeWhenFree) {
|
|
6888
6922
|
this.#closeWhenFree = closeWhenFree;
|
|
@@ -6966,7 +7000,7 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
6966
7000
|
}
|
|
6967
7001
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
6968
7002
|
if (actOptions.length <= 0) {
|
|
6969
|
-
logwarn("
|
|
7003
|
+
logwarn("##browser LsdPage invalid paras in setRequestInterception");
|
|
6970
7004
|
return false;
|
|
6971
7005
|
}
|
|
6972
7006
|
const firstRequestInterception = this.#resquestInterceptionOptions.length <= 0;
|
|
@@ -6989,9 +7023,9 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
6989
7023
|
const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
6990
7024
|
if (this.#isDebugTask) {
|
|
6991
7025
|
if (matchedFlag) {
|
|
6992
|
-
|
|
7026
|
+
loginfo(`##browser matched request ${request.method()} ${request.url()}`);
|
|
6993
7027
|
} else {
|
|
6994
|
-
|
|
7028
|
+
logdbg(`##browser unmatched request ${request.method()} ${request.url()}`);
|
|
6995
7029
|
}
|
|
6996
7030
|
}
|
|
6997
7031
|
if (matchedFlag) {
|
|
@@ -7047,9 +7081,9 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
7047
7081
|
}
|
|
7048
7082
|
if (this.#isDebugTask) {
|
|
7049
7083
|
if (matchedFlag) {
|
|
7050
|
-
|
|
7084
|
+
loginfo(`##browser matched response ${request.method()} ${request.url()}`);
|
|
7051
7085
|
} else {
|
|
7052
|
-
|
|
7086
|
+
logdbg(`##browser unmatched response ${request.method()} ${request.url()}`);
|
|
7053
7087
|
}
|
|
7054
7088
|
}
|
|
7055
7089
|
if (!matchedFlag) {
|
|
@@ -7087,7 +7121,7 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
7087
7121
|
}
|
|
7088
7122
|
const actOptions = Array.isArray(options) ? options : [options];
|
|
7089
7123
|
if (actOptions.length <= 0) {
|
|
7090
|
-
logwarn("
|
|
7124
|
+
logwarn("##browser LsdPage invalid paras in setResponseInterception");
|
|
7091
7125
|
return false;
|
|
7092
7126
|
}
|
|
7093
7127
|
const firstResponseInterception = this.#responseInterceptionOptions.length <= 0;
|
|
@@ -7100,7 +7134,7 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
7100
7134
|
}
|
|
7101
7135
|
if (firstResponseInterception && this.#responseInterceptionOptions.length > 0) {
|
|
7102
7136
|
this.#responseCb = this.#responseListener.bind(this);
|
|
7103
|
-
this.#page.on("response"
|
|
7137
|
+
this.#page.on("response" /* PAGE_RESPONSE */, this.#responseCb);
|
|
7104
7138
|
}
|
|
7105
7139
|
return true;
|
|
7106
7140
|
}
|
|
@@ -7148,6 +7182,7 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
7148
7182
|
throw new Error(`Page ${this.#pageId} is already busy!!!`);
|
|
7149
7183
|
}
|
|
7150
7184
|
this.#status = "busy";
|
|
7185
|
+
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
7151
7186
|
return true;
|
|
7152
7187
|
}
|
|
7153
7188
|
async waitForElement(selector, options = {}) {
|
|
@@ -7286,11 +7321,10 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7286
7321
|
for (const page of pages) {
|
|
7287
7322
|
const pageInfo = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType, openTime: this.#createTime, lastStatusUpdateTime, taskId: 0, relatedId: 0, misc: {} };
|
|
7288
7323
|
const lsdPage = new CamoufoxPage(this, page, pageInfo);
|
|
7324
|
+
this.#lsdPages.push(lsdPage);
|
|
7289
7325
|
if (this.#maxViewportOfNewPage) {
|
|
7290
7326
|
await lsdPage.maximizeViewport();
|
|
7291
7327
|
}
|
|
7292
|
-
this.#lsdPages.push(lsdPage);
|
|
7293
|
-
loginfo(`##browser ${lsdPage.id()} ${openType}ed`);
|
|
7294
7328
|
}
|
|
7295
7329
|
}
|
|
7296
7330
|
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, maxViewportOfNewPage = true) {
|
|
@@ -7320,8 +7354,9 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7320
7354
|
this.#lsdPages = [];
|
|
7321
7355
|
this.#nextPageIdx = 1;
|
|
7322
7356
|
this.#gettingPage = false;
|
|
7357
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} is created`);
|
|
7323
7358
|
this.#initPages();
|
|
7324
|
-
browserContext.on("page"
|
|
7359
|
+
browserContext.on("page" /* BROWSERCONTEXT_PAGE */, async (page) => {
|
|
7325
7360
|
const pageInfo = page.pageInfo;
|
|
7326
7361
|
if (pageInfo) {
|
|
7327
7362
|
const { browserIdx: browserIdx2, browserContextIdx: browserContextIdx2, pageIdx } = pageInfo;
|
|
@@ -7330,27 +7365,26 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7330
7365
|
const currentTime2 = (0, import_utils16.getCurrentUnixTime)();
|
|
7331
7366
|
const pageInfo2 = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType: "other", openTime: currentTime2, lastStatusUpdateTime: currentTime2, taskId: 0, relatedId: 0, misc: {} };
|
|
7332
7367
|
const lsdPage = new CamoufoxPage(this, page, pageInfo2);
|
|
7368
|
+
this.#lsdPages.push(lsdPage);
|
|
7333
7369
|
if (this.#maxViewportOfNewPage) {
|
|
7334
7370
|
await lsdPage.maximizeViewport();
|
|
7335
7371
|
}
|
|
7336
|
-
this.#lsdPages.push(lsdPage);
|
|
7337
|
-
loginfo(`##page ${lsdPage.id()} created`);
|
|
7338
7372
|
}
|
|
7339
7373
|
});
|
|
7340
|
-
browserContext.on("close"
|
|
7374
|
+
browserContext.on("close" /* BROWSERCONTEXT_CLOSE */, (bc) => {
|
|
7341
7375
|
if (browserContext !== bc) {
|
|
7342
|
-
logerr(`##browser different browserContext in browserContext.on("close")`);
|
|
7376
|
+
logerr(`##browser LsdBrowserContext different browserContext in browserContext.on("close")`);
|
|
7343
7377
|
}
|
|
7344
|
-
this.#lsdBrowser.emit("browserContextClose"
|
|
7378
|
+
this.#lsdBrowser.emit("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, this);
|
|
7345
7379
|
});
|
|
7346
|
-
this.on("pageClose"
|
|
7380
|
+
this.on("pageClose" /* PAGE_CLOSE */, (lsdPage) => {
|
|
7347
7381
|
if (!(lsdPage instanceof CamoufoxPage)) {
|
|
7348
|
-
logerr(
|
|
7382
|
+
logerr(`##browser LsdBrowserContext invalid data in LsdBrowserContext.on("pageClose)`);
|
|
7349
7383
|
return;
|
|
7350
7384
|
}
|
|
7351
7385
|
const idx = this.#lsdPages.findIndex((p) => p === lsdPage);
|
|
7352
7386
|
if (idx < 0) {
|
|
7353
|
-
logerr(
|
|
7387
|
+
logerr(`##browser LsdBrowserContext invalid lsdPage in LsdBrowserContext.on("pageClose)`);
|
|
7354
7388
|
return;
|
|
7355
7389
|
}
|
|
7356
7390
|
this.#lsdPages.splice(idx, 1);
|
|
@@ -7367,7 +7401,7 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7367
7401
|
if (this.#browserContext) {
|
|
7368
7402
|
this.#status = "closed";
|
|
7369
7403
|
this.#lastStatusUpdateTime = (0, import_utils16.getCurrentUnixTime)();
|
|
7370
|
-
loginfo(
|
|
7404
|
+
loginfo(`##browser LsdBrowserContext ${this.id()} closed at ${this.#lastStatusUpdateTime}`);
|
|
7371
7405
|
await this.#browserContext.close();
|
|
7372
7406
|
}
|
|
7373
7407
|
return true;
|
|
@@ -7382,12 +7416,12 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7382
7416
|
await (0, import_utils16.sleep)(200);
|
|
7383
7417
|
}
|
|
7384
7418
|
}
|
|
7385
|
-
logwarn(
|
|
7419
|
+
logwarn(`##browser LsdBrowserContext cannot get the gettingLock.`);
|
|
7386
7420
|
return false;
|
|
7387
7421
|
}
|
|
7388
7422
|
#freeGettingLock() {
|
|
7389
7423
|
if (!this.#gettingPage) {
|
|
7390
|
-
logwarn(
|
|
7424
|
+
logwarn(`##browser LsdBrowserContext gettingLock is already free now.`);
|
|
7391
7425
|
}
|
|
7392
7426
|
this.#gettingPage = false;
|
|
7393
7427
|
}
|
|
@@ -7396,7 +7430,7 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7396
7430
|
maxPageFreeSeconds = this.#maxPageFreeSeconds;
|
|
7397
7431
|
}
|
|
7398
7432
|
if (maxPageFreeSeconds <= 0) {
|
|
7399
|
-
logwarn(
|
|
7433
|
+
logwarn(`##browser LsdBrowserContext please set valid maxPageFreeSeconds to close free pages`);
|
|
7400
7434
|
return false;
|
|
7401
7435
|
}
|
|
7402
7436
|
const gotLock = await this.#tryToGetGettingLock();
|
|
@@ -7493,7 +7527,7 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7493
7527
|
}
|
|
7494
7528
|
}
|
|
7495
7529
|
id() {
|
|
7496
|
-
return `
|
|
7530
|
+
return `CamoufoxContext-${this.#browserIdx}-${this.#browserContextIdx}`;
|
|
7497
7531
|
}
|
|
7498
7532
|
isFree() {
|
|
7499
7533
|
return this.#status === "free";
|
|
@@ -7627,34 +7661,33 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends import_node_events13.defaul
|
|
|
7627
7661
|
this.#executablePath = executablePath;
|
|
7628
7662
|
this.#nextBrowserContextIdx = 1;
|
|
7629
7663
|
this.#closeFreePagesIntervalId = null;
|
|
7630
|
-
loginfo(`##browser ${this.id()} ${this.#browserCreationMethod}ed
|
|
7664
|
+
loginfo(`##browser LsdBrowser ${this.id()} ${this.#browserCreationMethod}ed}`);
|
|
7631
7665
|
const browserContexts = browser.contexts();
|
|
7632
7666
|
if (browserContexts.length > 0) {
|
|
7633
|
-
logwarn(
|
|
7667
|
+
logwarn(`##browser LsdBrowser there are ${browserContexts.length} new browserContexts when camoufox launches new browser`);
|
|
7634
7668
|
}
|
|
7635
7669
|
const incognito = typeof options?.incognito === "boolean" ? options.incognito : true;
|
|
7636
7670
|
for (const browserContext of browserContexts) {
|
|
7637
7671
|
const lsdBrowserContext = new CamoufoxBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
7638
7672
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
7639
|
-
loginfo(`##browserContext ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
7640
7673
|
}
|
|
7641
|
-
browser.on("disconnected"
|
|
7674
|
+
browser.on("disconnected" /* BROWSER_DISCONNECTED */, () => {
|
|
7642
7675
|
loginfo(`##browser ${this.id()} disconnected`);
|
|
7643
7676
|
if (this.#lsdBrowserContexts.length > 0) {
|
|
7644
|
-
logerr(
|
|
7677
|
+
logerr(`##browser LsdBrowser ${this.id()} has browserContexts when disconnected`);
|
|
7645
7678
|
}
|
|
7646
7679
|
});
|
|
7647
|
-
this.on("browserContextClose"
|
|
7680
|
+
this.on("browserContextClose" /* BROWSER_CONTEXT_CLOSE */, (lsdBrowserContext) => {
|
|
7648
7681
|
if (!(lsdBrowserContext instanceof CamoufoxBrowserContext)) {
|
|
7649
|
-
logerr(
|
|
7682
|
+
logerr(`##browser LsdBrowser invalid data in LsdBrowser.on("browserContextClose)`);
|
|
7650
7683
|
return;
|
|
7651
7684
|
}
|
|
7652
7685
|
const idx = this.#lsdBrowserContexts.findIndex((bc) => bc === lsdBrowserContext);
|
|
7653
7686
|
if (idx < 0) {
|
|
7654
|
-
logerr(
|
|
7687
|
+
logerr(`##browser LsdBrowser invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
7655
7688
|
return;
|
|
7656
7689
|
}
|
|
7657
|
-
loginfo(`##
|
|
7690
|
+
loginfo(`##browser ${lsdBrowserContext.id()} closed
|
|
7658
7691
|
`);
|
|
7659
7692
|
this.#lsdBrowserContexts.splice(idx, 1);
|
|
7660
7693
|
if (this.#lsdBrowserContexts.length === 0) {
|
|
@@ -7675,7 +7708,7 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends import_node_events13.defaul
|
|
|
7675
7708
|
}
|
|
7676
7709
|
async newBrowserContext(options) {
|
|
7677
7710
|
if (this.#lsdBrowserContexts.length >= this.#maxBrowserContextsPerBrowser()) {
|
|
7678
|
-
logwarn(`##browser ${this.id()} can not create more new browserContext`);
|
|
7711
|
+
logwarn(`##browser LsdBrowser ${this.id()} can not create more new browserContext`);
|
|
7679
7712
|
return null;
|
|
7680
7713
|
}
|
|
7681
7714
|
const browserContextOptions = {};
|
|
@@ -7694,7 +7727,6 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends import_node_events13.defaul
|
|
|
7694
7727
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
7695
7728
|
const lsdBrowserContext = new CamoufoxBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
7696
7729
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
7697
|
-
loginfo(`##browser ${lsdBrowserContext.id()} created`);
|
|
7698
7730
|
return lsdBrowserContext;
|
|
7699
7731
|
}
|
|
7700
7732
|
async close() {
|
|
@@ -7705,6 +7737,7 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends import_node_events13.defaul
|
|
|
7705
7737
|
await lsdBrowserContext.close();
|
|
7706
7738
|
}
|
|
7707
7739
|
await this.#browser.close();
|
|
7740
|
+
loginfo(`##browser LsdBrowser ${this.id()} is closed`);
|
|
7708
7741
|
return true;
|
|
7709
7742
|
}
|
|
7710
7743
|
browserContexts() {
|
|
@@ -7730,7 +7763,7 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends import_node_events13.defaul
|
|
|
7730
7763
|
return this.#executablePath;
|
|
7731
7764
|
}
|
|
7732
7765
|
id() {
|
|
7733
|
-
return `
|
|
7766
|
+
return `CamoufoxBrowser-${this.#browserType}-${this.#browserIdx}`;
|
|
7734
7767
|
}
|
|
7735
7768
|
isConnected() {
|
|
7736
7769
|
return this.#browser.isConnected();
|
|
@@ -7892,22 +7925,22 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
7892
7925
|
const actOptions = { closeFreePagesIntervalSeconds, maxBrowserContextsPerBrowser, maxPagesPerBrowserContext, maxPageFreeSeconds, maxViewportOfNewPage, proxy, timeout, args, executablePath, maxWindowSize, headless, minBrowserContexts, incognito, proxyPerBrowserContext, userDataDir, userAgent };
|
|
7893
7926
|
let idx = args.findIndex((arg) => arg.toLowerCase().startsWith("--incoginto"));
|
|
7894
7927
|
if (idx >= 0) {
|
|
7895
|
-
logwarn(
|
|
7928
|
+
logwarn(`##browser controller Please use options.incognito instead when launching new browser.`);
|
|
7896
7929
|
args.splice(idx, 1);
|
|
7897
7930
|
}
|
|
7898
7931
|
idx = args.findIndex((arg) => arg.toLowerCase().startsWith("--proxy-server"));
|
|
7899
7932
|
if (idx >= 0) {
|
|
7900
|
-
logwarn(
|
|
7933
|
+
logwarn(`##browser controller Please use options.proxy instead when launching new browser.`);
|
|
7901
7934
|
args.splice(idx, 1);
|
|
7902
7935
|
}
|
|
7903
7936
|
idx = args.findIndex((arg) => arg.toLowerCase().startsWith("--user-data-dir"));
|
|
7904
7937
|
if (idx >= 0) {
|
|
7905
|
-
logwarn(
|
|
7938
|
+
logwarn(`##browser controller Please use options.userDataDir instead when launching new browser.`);
|
|
7906
7939
|
args.splice(idx, 1);
|
|
7907
7940
|
}
|
|
7908
7941
|
idx = args.findIndex((arg) => arg.toLowerCase().startsWith("--start-maximized"));
|
|
7909
7942
|
if (idx >= 0) {
|
|
7910
|
-
logwarn(
|
|
7943
|
+
logwarn(`##browser controller Please use options.maxWindowSize instead when launching new browser.`);
|
|
7911
7944
|
args.splice(idx, 1);
|
|
7912
7945
|
}
|
|
7913
7946
|
let lsdBrowser;
|
|
@@ -8105,7 +8138,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
8105
8138
|
const pids = await (0, import_utils18.getPidsListeningOnPort)(port);
|
|
8106
8139
|
let browserPid = 0;
|
|
8107
8140
|
if (pids.length !== 1) {
|
|
8108
|
-
logerr(`##browser pids.length ${pids.length} is not 1 when trying to connect to browserUrl ${browserUrl}`);
|
|
8141
|
+
logerr(`##browser controller pids.length ${pids.length} is not 1 when trying to connect to browserUrl ${browserUrl}`);
|
|
8109
8142
|
} else {
|
|
8110
8143
|
browserPid = pids[0];
|
|
8111
8144
|
}
|
|
@@ -8150,6 +8183,10 @@ var controller = new LsdBrowserController();
|
|
|
8150
8183
|
0 && (module.exports = {
|
|
8151
8184
|
CheerioElement,
|
|
8152
8185
|
CheerioPage,
|
|
8186
|
+
ControllerEvent,
|
|
8187
|
+
LsdBrowserContextEvent,
|
|
8188
|
+
LsdBrowserEvent,
|
|
8189
|
+
LsdPageEvent,
|
|
8153
8190
|
PlaywrightBrowser,
|
|
8154
8191
|
PlaywrightBrowserContext,
|
|
8155
8192
|
PlaywrightElement,
|