@letsscrapedata/controller 0.0.32 → 0.0.34
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 +70 -47
- package/dist/index.d.cts +56 -30
- package/dist/index.d.ts +56 -30
- package/dist/index.js +69 -45
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -58,21 +58,10 @@ __export(src_exports, {
|
|
|
58
58
|
PuppeteerBrowserContext: () => PuppeteerBrowserContext,
|
|
59
59
|
PuppeteerElement: () => PuppeteerElement,
|
|
60
60
|
PuppeteerPage: () => PuppeteerPage,
|
|
61
|
-
controller: () => controller
|
|
62
|
-
defaultProxy: () => defaultProxy
|
|
61
|
+
controller: () => controller
|
|
63
62
|
});
|
|
64
63
|
module.exports = __toCommonJS(src_exports);
|
|
65
64
|
|
|
66
|
-
// src/types/types.ts
|
|
67
|
-
var defaultProxy = {
|
|
68
|
-
server: "default",
|
|
69
|
-
proxyIpType: "residential",
|
|
70
|
-
proxyDurationType: "static",
|
|
71
|
-
proxySharedType: "dedicated",
|
|
72
|
-
expireTime: 41024196e5
|
|
73
|
-
// "2100-01-01 01:00:00"
|
|
74
|
-
};
|
|
75
|
-
|
|
76
65
|
// src/playwright/browser.ts
|
|
77
66
|
var import_node_events3 = __toESM(require("events"), 1);
|
|
78
67
|
|
|
@@ -588,7 +577,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
588
577
|
const currentTime = (0, import_utils2.getCurrentUnixTime)();
|
|
589
578
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
590
579
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
591
|
-
this.#pageId = `page
|
|
580
|
+
this.#pageId = `page-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
592
581
|
this.#resquestInterceptionOptions = [];
|
|
593
582
|
this.#responseInterceptionOptions = [];
|
|
594
583
|
this.#client = null;
|
|
@@ -697,6 +686,12 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
697
686
|
const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
|
|
698
687
|
return height;
|
|
699
688
|
}
|
|
689
|
+
async evalute(fun, args) {
|
|
690
|
+
if (!this.#page) {
|
|
691
|
+
throw new Error("No valid page");
|
|
692
|
+
}
|
|
693
|
+
return this.#page.evaluate(fun, args);
|
|
694
|
+
}
|
|
700
695
|
async findElement(selectorOrXpath, iframeOptions = []) {
|
|
701
696
|
if (!this.#page) {
|
|
702
697
|
throw new Error("No valid page");
|
|
@@ -1186,6 +1181,9 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
1186
1181
|
);
|
|
1187
1182
|
return content;
|
|
1188
1183
|
}
|
|
1184
|
+
_origPage() {
|
|
1185
|
+
return this.#page;
|
|
1186
|
+
}
|
|
1189
1187
|
};
|
|
1190
1188
|
|
|
1191
1189
|
// src/playwright/context.ts
|
|
@@ -1234,7 +1232,7 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1234
1232
|
this.#browserContext = browserContext;
|
|
1235
1233
|
this.#createTime = (0, import_utils3.getCurrentUnixTime)();
|
|
1236
1234
|
this.#incognito = incognito === false ? false : true;
|
|
1237
|
-
this.#proxy = proxy?.
|
|
1235
|
+
this.#proxy = proxy?.proxyUrl ? proxy : null;
|
|
1238
1236
|
this.#maxPagesPerBrowserContext = maxPagesPerBrowserContext;
|
|
1239
1237
|
this.#maxPageFreeSeconds = maxPageFreeSeconds;
|
|
1240
1238
|
this.#maxViewportOfNewPage = maxViewportOfNewPage;
|
|
@@ -1255,7 +1253,7 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1255
1253
|
await lsdPage.maximizeViewport();
|
|
1256
1254
|
}
|
|
1257
1255
|
this.#lsdPages.push(lsdPage);
|
|
1258
|
-
(0, import_utils3.loginfo)(`##
|
|
1256
|
+
(0, import_utils3.loginfo)(`##page ${lsdPage.id()} created`);
|
|
1259
1257
|
}
|
|
1260
1258
|
});
|
|
1261
1259
|
browserContext.on("close", (bc) => {
|
|
@@ -1407,12 +1405,16 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1407
1405
|
throw new Error("No valid browserContext");
|
|
1408
1406
|
}
|
|
1409
1407
|
const { cookies, localStorage: localStorageOrigins } = stateData;
|
|
1410
|
-
const page = await this
|
|
1408
|
+
const page = await this.getPage();
|
|
1409
|
+
if (!page) {
|
|
1410
|
+
return false;
|
|
1411
|
+
}
|
|
1412
|
+
const origPage = page._origPage();
|
|
1411
1413
|
if (cookies.length > 0) {
|
|
1412
1414
|
await this.#browserContext.addCookies(cookies);
|
|
1413
1415
|
}
|
|
1414
1416
|
if (localStorageOrigins.length > 0) {
|
|
1415
|
-
await
|
|
1417
|
+
await origPage.route("**/*", async (route) => {
|
|
1416
1418
|
const request = route.request();
|
|
1417
1419
|
await route.fulfill({
|
|
1418
1420
|
status: 200,
|
|
@@ -1422,15 +1424,16 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1422
1424
|
});
|
|
1423
1425
|
for (const localStorageOrigin of localStorageOrigins) {
|
|
1424
1426
|
const { origin, localStorage } = localStorageOrigin;
|
|
1425
|
-
await
|
|
1426
|
-
await
|
|
1427
|
+
await origPage.goto(origin);
|
|
1428
|
+
await origPage.evaluate((localStorageItems) => {
|
|
1427
1429
|
for (const item of localStorageItems) {
|
|
1428
1430
|
window.localStorage.setItem(item.name, item.value);
|
|
1429
1431
|
}
|
|
1430
1432
|
}, localStorage);
|
|
1431
1433
|
}
|
|
1432
1434
|
}
|
|
1433
|
-
await
|
|
1435
|
+
await origPage.unrouteAll();
|
|
1436
|
+
await page.free();
|
|
1434
1437
|
return true;
|
|
1435
1438
|
}
|
|
1436
1439
|
_origBrowserContext() {
|
|
@@ -1485,7 +1488,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1485
1488
|
this.#executablePath = executablePath;
|
|
1486
1489
|
this.#nextBrowserContextIdx = 1;
|
|
1487
1490
|
this.#closeFreePagesIntervalId = null;
|
|
1488
|
-
(0, import_utils4.loginfo)(`##browser
|
|
1491
|
+
(0, import_utils4.loginfo)(`##browser ${this.id()} ${this.#browserCreationMethod}ed by ${this.#browserControllerType}`);
|
|
1489
1492
|
const browserContexts = browser.contexts();
|
|
1490
1493
|
if (browserContexts.length > 0) {
|
|
1491
1494
|
(0, import_utils4.logwarn)(`There are ${browserContexts.length} new browserContexts when playwright launches new browser`);
|
|
@@ -1494,7 +1497,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1494
1497
|
for (const browserContext of browserContexts) {
|
|
1495
1498
|
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, incognito, this.#proxy, this.#browserIdx++, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
1496
1499
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
1497
|
-
(0, import_utils4.loginfo)(`##
|
|
1500
|
+
(0, import_utils4.loginfo)(`##browserContext ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
1498
1501
|
}
|
|
1499
1502
|
browser.on("disconnected", () => {
|
|
1500
1503
|
(0, import_utils4.loginfo)(`##browser ${this.id()} disconnected`);
|
|
@@ -1512,7 +1515,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1512
1515
|
(0, import_utils4.logerr)(`Invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
1513
1516
|
return;
|
|
1514
1517
|
}
|
|
1515
|
-
(0, import_utils4.loginfo)(`##
|
|
1518
|
+
(0, import_utils4.loginfo)(`##browserContext ${lsdBrowserContext.id()} closed
|
|
1516
1519
|
`);
|
|
1517
1520
|
this.#lsdBrowserContexts.splice(idx, 1);
|
|
1518
1521
|
if (this.#lsdBrowserContexts.length === 0) {
|
|
@@ -1543,7 +1546,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1543
1546
|
}
|
|
1544
1547
|
const proxy = options?.proxy ? Object.assign({}, options.proxy) : this.#proxy;
|
|
1545
1548
|
if (proxy) {
|
|
1546
|
-
const { server, username, password } = proxy;
|
|
1549
|
+
const { proxyUrl: server, username, password } = proxy;
|
|
1547
1550
|
browserContextOptions.proxy = { server, username, password };
|
|
1548
1551
|
}
|
|
1549
1552
|
if (options?.userAgent) {
|
|
@@ -1583,7 +1586,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1583
1586
|
return this.#executablePath;
|
|
1584
1587
|
}
|
|
1585
1588
|
id() {
|
|
1586
|
-
return `browser-${this.#browserIdx}`;
|
|
1589
|
+
return `browser-${this.#browserType}-${this.#browserIdx}`;
|
|
1587
1590
|
}
|
|
1588
1591
|
isConnected() {
|
|
1589
1592
|
return this.#browser.isConnected();
|
|
@@ -1598,8 +1601,8 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1598
1601
|
const version = await this.#browser.version();
|
|
1599
1602
|
return version;
|
|
1600
1603
|
}
|
|
1601
|
-
|
|
1602
|
-
return this.#browser
|
|
1604
|
+
_origBrowser() {
|
|
1605
|
+
return this.#browser;
|
|
1603
1606
|
}
|
|
1604
1607
|
};
|
|
1605
1608
|
|
|
@@ -2078,7 +2081,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2078
2081
|
const currentTime = (0, import_utils6.getCurrentUnixTime)();
|
|
2079
2082
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
2080
2083
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
2081
|
-
this.#pageId = `page
|
|
2084
|
+
this.#pageId = `page-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
2082
2085
|
this.#requestInterceptionNum = 0;
|
|
2083
2086
|
this.#responseInterceptionNum = 0;
|
|
2084
2087
|
this.#client = null;
|
|
@@ -2181,6 +2184,12 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2181
2184
|
const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
|
|
2182
2185
|
return height;
|
|
2183
2186
|
}
|
|
2187
|
+
async evalute(fun, args) {
|
|
2188
|
+
if (!this.#page) {
|
|
2189
|
+
throw new Error("No valid page");
|
|
2190
|
+
}
|
|
2191
|
+
return this.#page.evaluate(fun, args);
|
|
2192
|
+
}
|
|
2184
2193
|
async findElement(selectorOrXpath, iframeOptions = []) {
|
|
2185
2194
|
if (!this.#page) {
|
|
2186
2195
|
throw new Error("No valid page");
|
|
@@ -2661,6 +2670,9 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2661
2670
|
);
|
|
2662
2671
|
return content;
|
|
2663
2672
|
}
|
|
2673
|
+
_origPage() {
|
|
2674
|
+
return this.#page;
|
|
2675
|
+
}
|
|
2664
2676
|
};
|
|
2665
2677
|
|
|
2666
2678
|
// src/puppeteer/context.ts
|
|
@@ -2719,7 +2731,7 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
2719
2731
|
this.#userAgent = userAgent;
|
|
2720
2732
|
this.#createTime = (0, import_utils7.getCurrentUnixTime)();
|
|
2721
2733
|
this.#incognito = incognito === false ? false : true;
|
|
2722
|
-
this.#proxy = proxy?.
|
|
2734
|
+
this.#proxy = proxy?.proxyUrl ? proxy : null;
|
|
2723
2735
|
this.#maxPagesPerBrowserContext = maxPagesPerBrowserContext;
|
|
2724
2736
|
this.#maxPageFreeSeconds = maxPageFreeSeconds;
|
|
2725
2737
|
this.#maxViewportOfNewPage = maxViewportOfNewPage;
|
|
@@ -2748,7 +2760,7 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
2748
2760
|
await lsdPage.setUserAgent(this.#userAgent);
|
|
2749
2761
|
}
|
|
2750
2762
|
this.#lsdPages.push(lsdPage);
|
|
2751
|
-
(0, import_utils7.loginfo)(`##
|
|
2763
|
+
(0, import_utils7.loginfo)(`##page ${lsdPage.id()} created`);
|
|
2752
2764
|
}
|
|
2753
2765
|
}
|
|
2754
2766
|
});
|
|
@@ -2900,13 +2912,17 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
2900
2912
|
throw new Error("No valid browserContext");
|
|
2901
2913
|
}
|
|
2902
2914
|
const { cookies, localStorage: localStorageOrigins } = stateData;
|
|
2903
|
-
const page = await this
|
|
2915
|
+
const page = await this.getPage();
|
|
2916
|
+
if (!page) {
|
|
2917
|
+
return false;
|
|
2918
|
+
}
|
|
2919
|
+
const origPage = page._origPage();
|
|
2904
2920
|
if (cookies.length > 0) {
|
|
2905
|
-
await
|
|
2921
|
+
await origPage.setCookie(...cookies);
|
|
2906
2922
|
}
|
|
2907
2923
|
if (localStorageOrigins.length > 0) {
|
|
2908
|
-
await
|
|
2909
|
-
|
|
2924
|
+
await origPage.setRequestInterception(true);
|
|
2925
|
+
origPage.on("request", (request) => {
|
|
2910
2926
|
request.respond({
|
|
2911
2927
|
status: 200,
|
|
2912
2928
|
// contentType: "text/html; charset=utf-8", // "text/plain",
|
|
@@ -2915,15 +2931,16 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
2915
2931
|
});
|
|
2916
2932
|
for (const localStorageOrigin of localStorageOrigins) {
|
|
2917
2933
|
const { origin, localStorage } = localStorageOrigin;
|
|
2918
|
-
await
|
|
2919
|
-
await
|
|
2934
|
+
await origPage.goto(origin);
|
|
2935
|
+
await origPage.evaluate((localStorageItems) => {
|
|
2920
2936
|
for (const item of localStorageItems) {
|
|
2921
2937
|
window.localStorage.setItem(item.name, item.value);
|
|
2922
2938
|
}
|
|
2923
2939
|
}, localStorage);
|
|
2924
2940
|
}
|
|
2925
2941
|
}
|
|
2926
|
-
await
|
|
2942
|
+
await origPage.setRequestInterception(false);
|
|
2943
|
+
await page.free();
|
|
2927
2944
|
return true;
|
|
2928
2945
|
}
|
|
2929
2946
|
_origBrowserContext() {
|
|
@@ -3032,8 +3049,8 @@ var PuppeteerBrowser = class extends import_node_events6.default {
|
|
|
3032
3049
|
}
|
|
3033
3050
|
const browserContextOptions = {};
|
|
3034
3051
|
const proxy = options?.proxy ? Object.assign({}, options.proxy) : this.#proxy;
|
|
3035
|
-
if (proxy?.
|
|
3036
|
-
browserContextOptions.proxyServer = proxy.
|
|
3052
|
+
if (proxy?.proxyUrl) {
|
|
3053
|
+
browserContextOptions.proxyServer = proxy.proxyUrl;
|
|
3037
3054
|
}
|
|
3038
3055
|
const browserContext = await this.#browser.createBrowserContext(browserContextOptions);
|
|
3039
3056
|
const userAgent = options?.userAgent ? options.userAgent : "";
|
|
@@ -3087,8 +3104,8 @@ var PuppeteerBrowser = class extends import_node_events6.default {
|
|
|
3087
3104
|
const version = await this.#browser.version();
|
|
3088
3105
|
return version;
|
|
3089
3106
|
}
|
|
3090
|
-
|
|
3091
|
-
return this.#browser
|
|
3107
|
+
_origBrowser() {
|
|
3108
|
+
return this.#browser;
|
|
3092
3109
|
}
|
|
3093
3110
|
};
|
|
3094
3111
|
|
|
@@ -17076,6 +17093,9 @@ var CheerioPage = class extends import_node_events7.default {
|
|
|
17076
17093
|
this.#document = load(html3, { xml: true }).root();
|
|
17077
17094
|
}
|
|
17078
17095
|
}
|
|
17096
|
+
_origPage() {
|
|
17097
|
+
throw new Error("Method not implemented.");
|
|
17098
|
+
}
|
|
17079
17099
|
apiRequestContext() {
|
|
17080
17100
|
throw new Error("Not supported in CheerioPage.");
|
|
17081
17101
|
}
|
|
@@ -17109,6 +17129,9 @@ var CheerioPage = class extends import_node_events7.default {
|
|
|
17109
17129
|
async cookies() {
|
|
17110
17130
|
throw new Error("Not supported in CheerioPage.");
|
|
17111
17131
|
}
|
|
17132
|
+
async evalute() {
|
|
17133
|
+
throw new Error("Not supported in CheerioPage.");
|
|
17134
|
+
}
|
|
17112
17135
|
#findNodes(selector) {
|
|
17113
17136
|
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
17114
17137
|
throw new Error("Do not support XPath in cheerio.");
|
|
@@ -17390,8 +17413,9 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17390
17413
|
if (maxWindowSize) {
|
|
17391
17414
|
args.push("--start-maximized");
|
|
17392
17415
|
}
|
|
17393
|
-
if (proxy?.
|
|
17394
|
-
|
|
17416
|
+
if (proxy?.proxyUrl && proxy.proxyUrl !== "local") {
|
|
17417
|
+
const { proxyUrl: server, username, password } = proxy;
|
|
17418
|
+
launchOptions.proxy = { server, username, password };
|
|
17395
17419
|
} else if (proxyPerBrowserContext && browserType === "chromium" && this.#osPlatform.startsWith("win")) {
|
|
17396
17420
|
launchOptions.proxy = { server: "proxyPerBrowserContext" };
|
|
17397
17421
|
}
|
|
@@ -17430,8 +17454,8 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17430
17454
|
} else if (userDataDir) {
|
|
17431
17455
|
args.push(`--user-data-dir=${userDataDir}`);
|
|
17432
17456
|
}
|
|
17433
|
-
if (proxy?.
|
|
17434
|
-
args.push(`--proxy-server=${proxy.
|
|
17457
|
+
if (proxy?.proxyUrl && proxy.proxyUrl !== "default") {
|
|
17458
|
+
args.push(`--proxy-server=${proxy.proxyUrl}`);
|
|
17435
17459
|
} else if (proxyPerBrowserContext && browserType === "chromium" && this.#osPlatform.startsWith("win")) {
|
|
17436
17460
|
args.push(`--proxy-server=proxyPerBrowserContext`);
|
|
17437
17461
|
}
|
|
@@ -17504,6 +17528,5 @@ var controller = new LsdBrowserController();
|
|
|
17504
17528
|
PuppeteerBrowserContext,
|
|
17505
17529
|
PuppeteerElement,
|
|
17506
17530
|
PuppeteerPage,
|
|
17507
|
-
controller
|
|
17508
|
-
defaultProxy
|
|
17531
|
+
controller
|
|
17509
17532
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -17,22 +17,11 @@ type AllPage = Page | Page$1;
|
|
|
17
17
|
type AllResponse = Response | HTTPResponse;
|
|
18
18
|
type AllApiRequestContext = APIRequestContext;
|
|
19
19
|
type CheerioNode = cheerio.Cheerio<cheerio.Element>;
|
|
20
|
-
type
|
|
21
|
-
|
|
20
|
+
type ProxyInController = {
|
|
21
|
+
proxyUrl: string;
|
|
22
22
|
username?: string;
|
|
23
23
|
password?: string;
|
|
24
24
|
proxyId?: string;
|
|
25
|
-
host?: string;
|
|
26
|
-
port?: number;
|
|
27
|
-
expireTime?: number;
|
|
28
|
-
proxyIpType?: string;
|
|
29
|
-
proxyDurationType?: string;
|
|
30
|
-
proxySharedType?: string;
|
|
31
|
-
latitude?: number;
|
|
32
|
-
longitude?: number;
|
|
33
|
-
freeable?: boolean;
|
|
34
|
-
interfaceName?: string;
|
|
35
|
-
packageName?: string;
|
|
36
25
|
};
|
|
37
26
|
type BrowserControllerType = "puppeteer" | "playwright";
|
|
38
27
|
type BrowserCreationMethod = "launch" | "connect";
|
|
@@ -45,7 +34,6 @@ interface PlaywrightBrowserTypes {
|
|
|
45
34
|
type BrowserControllerOptions = {
|
|
46
35
|
browserControllerType: BrowserControllerType;
|
|
47
36
|
};
|
|
48
|
-
declare const defaultProxy: Proxy;
|
|
49
37
|
interface BrowserOptions {
|
|
50
38
|
/**
|
|
51
39
|
* Interval between closing free pages (seconds) if greater than 0
|
|
@@ -76,7 +64,7 @@ interface BrowserOptions {
|
|
|
76
64
|
* * this will used as default proxy when creating new browserContexts later
|
|
77
65
|
* @default null
|
|
78
66
|
*/
|
|
79
|
-
proxy?:
|
|
67
|
+
proxy?: ProxyInController | null;
|
|
80
68
|
/**
|
|
81
69
|
* Maximum time in milliseconds to wait for the browser instance to start. Pass 0 to disable timeout.
|
|
82
70
|
* * default 30_000 (30 seconds)
|
|
@@ -143,7 +131,7 @@ interface LsdConnectOptions extends BrowserOptions {
|
|
|
143
131
|
userAgent?: string;
|
|
144
132
|
}
|
|
145
133
|
type LsdBrowserContextOptions = {
|
|
146
|
-
proxy:
|
|
134
|
+
proxy: ProxyInController | null;
|
|
147
135
|
/**
|
|
148
136
|
* @default browser.options.maxViewportOfNewPage
|
|
149
137
|
*/
|
|
@@ -154,7 +142,6 @@ type LsdBrowserContextOptions = {
|
|
|
154
142
|
* * puppeteer: set when creating the new page in the browserContext
|
|
155
143
|
*/
|
|
156
144
|
userAgent?: string;
|
|
157
|
-
fingerPrint: Object;
|
|
158
145
|
};
|
|
159
146
|
type PageStatus = "free" | "busy" | "closed";
|
|
160
147
|
/**
|
|
@@ -784,7 +771,15 @@ interface LsdPage extends EventEmitter {
|
|
|
784
771
|
apiRequestContext(): AllApiRequestContext;
|
|
785
772
|
bringToFront(): Promise<boolean>;
|
|
786
773
|
browserContext(): LsdBrowserContext;
|
|
774
|
+
/**
|
|
775
|
+
* clear the cookies of the current page(url)
|
|
776
|
+
* * Prerequisites: page must has a valid url, such as by calling goto(url)
|
|
777
|
+
*/
|
|
787
778
|
clearCookies(): Promise<boolean>;
|
|
779
|
+
/**
|
|
780
|
+
* clear the localStorage of the current page(url)
|
|
781
|
+
* * Prerequisites: page must has a valid url, such as by calling goto(url)
|
|
782
|
+
*/
|
|
788
783
|
clearLocalStorage(): Promise<boolean>;
|
|
789
784
|
/**
|
|
790
785
|
* Clear all request interceptions on the page
|
|
@@ -794,6 +789,11 @@ interface LsdPage extends EventEmitter {
|
|
|
794
789
|
* Clear all response interceptions on the page
|
|
795
790
|
*/
|
|
796
791
|
clearResponseInterceptions(): Promise<boolean>;
|
|
792
|
+
/**
|
|
793
|
+
* clear the stateData of the current page(url):
|
|
794
|
+
* * stateData: cookies, localStorage, indexedDB
|
|
795
|
+
* * Prerequisites: page must has a valid url, such as by calling goto(url)
|
|
796
|
+
*/
|
|
797
797
|
clearStateData(): Promise<boolean>;
|
|
798
798
|
/**
|
|
799
799
|
* Only free page can be closed!
|
|
@@ -805,6 +805,7 @@ interface LsdPage extends EventEmitter {
|
|
|
805
805
|
*/
|
|
806
806
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
807
807
|
cookies(): Promise<CookieItem[]>;
|
|
808
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
808
809
|
/**
|
|
809
810
|
* @returns the first element matching the given CSS selector or XPath
|
|
810
811
|
* @param selectorOrXpath CSS selector or XPath; if this parameter is an array, each selectorOrXpath in the array will be tried until elements are selected
|
|
@@ -875,6 +876,10 @@ interface LsdPage extends EventEmitter {
|
|
|
875
876
|
* @param stateData
|
|
876
877
|
*/
|
|
877
878
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
879
|
+
/**
|
|
880
|
+
* valid only in puppeteer
|
|
881
|
+
* @param userAgent
|
|
882
|
+
*/
|
|
878
883
|
setUserAgent(userAgent: string): Promise<boolean>;
|
|
879
884
|
setViewportSize(viewPortSize: ViewportSize): Promise<boolean>;
|
|
880
885
|
stateData(): Promise<StateData>;
|
|
@@ -902,6 +907,7 @@ interface LsdPage extends EventEmitter {
|
|
|
902
907
|
* @param keys
|
|
903
908
|
*/
|
|
904
909
|
windowMember(keys: string[]): Promise<string>;
|
|
910
|
+
_origPage(): AllPage;
|
|
905
911
|
}
|
|
906
912
|
interface LsdBrowserContext extends EventEmitter {
|
|
907
913
|
browser(): LsdBrowser;
|
|
@@ -913,37 +919,51 @@ interface LsdBrowserContext extends EventEmitter {
|
|
|
913
919
|
*/
|
|
914
920
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
915
921
|
/**
|
|
916
|
-
*
|
|
917
|
-
* * TBD:需要预留pageQuota给需要capName的TE使用
|
|
922
|
+
* get a free page from current pages or by creating a new page
|
|
918
923
|
*/
|
|
919
924
|
getPage(always?: boolean): Promise<LsdPage | null>;
|
|
920
925
|
/**
|
|
921
|
-
*
|
|
922
|
-
*
|
|
926
|
+
* whether can get a number of free page(s)
|
|
927
|
+
* * refer to getPage()
|
|
928
|
+
* @param pageNum default 1, the number of free pages
|
|
923
929
|
*/
|
|
924
930
|
hasNewPage(pageNum?: number): boolean;
|
|
925
931
|
id(): string;
|
|
926
932
|
isIncognito(): boolean;
|
|
927
933
|
page(pageIdx: number): LsdPage | null;
|
|
928
934
|
pages(): LsdPage[];
|
|
929
|
-
proxy():
|
|
935
|
+
proxy(): ProxyInController | null;
|
|
930
936
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
931
937
|
_origBrowserContext(): AllBrowserContext;
|
|
932
938
|
}
|
|
933
939
|
interface LsdBrowser extends EventEmitter {
|
|
934
940
|
newBrowserContext(options?: LsdBrowserContextOptions): Promise<LsdBrowserContext | null>;
|
|
941
|
+
/**
|
|
942
|
+
* 1. launched: close all browserContexts and this browser
|
|
943
|
+
* 2. connected:
|
|
944
|
+
* * in puppeteer: close all browserContexts and this browser???
|
|
945
|
+
* * in playwright: only browserContexts created by newContext will be closed, browser is disconnected and browser will not be closed
|
|
946
|
+
*/
|
|
935
947
|
close(): Promise<boolean>;
|
|
936
948
|
browserContexts(): LsdBrowserContext[];
|
|
937
949
|
browserControllerType(): BrowserControllerType;
|
|
938
950
|
browserCreationMethod(): BrowserCreationMethod;
|
|
939
951
|
browserType(): LsdBrowserType;
|
|
952
|
+
/**
|
|
953
|
+
* @returns
|
|
954
|
+
* 1. launched: actual executable path
|
|
955
|
+
* 2. connected: exectuablePath in LsdConnectOptions, default ""(unkown)
|
|
956
|
+
*/
|
|
940
957
|
executablePath(): string;
|
|
958
|
+
/**
|
|
959
|
+
* get a free BrowserContext from current free browserContexts or new browserContext
|
|
960
|
+
*/
|
|
941
961
|
id(): string;
|
|
942
962
|
isConnected(): boolean;
|
|
943
963
|
isHeadless(): boolean;
|
|
944
964
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
945
965
|
version(): Promise<string>;
|
|
946
|
-
|
|
966
|
+
_origBrowser(): AllBrowser;
|
|
947
967
|
}
|
|
948
968
|
interface LsdBrowserController$1 {
|
|
949
969
|
/**
|
|
@@ -1018,12 +1038,12 @@ declare class PlaywrightBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1018
1038
|
isHeadless(): boolean;
|
|
1019
1039
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
1020
1040
|
version(): Promise<string>;
|
|
1021
|
-
|
|
1041
|
+
_origBrowser(): AllBrowser;
|
|
1022
1042
|
}
|
|
1023
1043
|
|
|
1024
1044
|
declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
1025
1045
|
#private;
|
|
1026
|
-
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext, incognito?: boolean, proxy?:
|
|
1046
|
+
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext, incognito?: boolean, proxy?: ProxyInController | null, browserIdx?: number, browserContextIdx?: number, maxPagesPerBrowserContext?: number, maxPageFreeSeconds?: number, maxViewportOfNewPage?: boolean);
|
|
1027
1047
|
browser(): LsdBrowser;
|
|
1028
1048
|
close(): Promise<boolean>;
|
|
1029
1049
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
@@ -1033,7 +1053,7 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
|
|
|
1033
1053
|
isIncognito(): boolean;
|
|
1034
1054
|
page(pageIdx: number): LsdPage | null;
|
|
1035
1055
|
pages(): LsdPage[];
|
|
1036
|
-
proxy():
|
|
1056
|
+
proxy(): ProxyInController | null;
|
|
1037
1057
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1038
1058
|
_origBrowserContext(): AllBrowserContext;
|
|
1039
1059
|
}
|
|
@@ -1053,6 +1073,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
1053
1073
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
1054
1074
|
cookies(): Promise<CookieItem[]>;
|
|
1055
1075
|
documentHeight(): Promise<number>;
|
|
1076
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
1056
1077
|
findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
|
|
1057
1078
|
findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
|
|
1058
1079
|
free(): Promise<boolean>;
|
|
@@ -1088,6 +1109,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
1088
1109
|
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
1089
1110
|
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
1090
1111
|
windowMember(keys: string[]): Promise<string>;
|
|
1112
|
+
_origPage(): AllPage;
|
|
1091
1113
|
}
|
|
1092
1114
|
|
|
1093
1115
|
declare class PlaywrightElement implements LsdElement {
|
|
@@ -1127,12 +1149,12 @@ declare class PuppeteerBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1127
1149
|
isHeadless(): boolean;
|
|
1128
1150
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
1129
1151
|
version(): Promise<string>;
|
|
1130
|
-
|
|
1152
|
+
_origBrowser(): AllBrowser;
|
|
1131
1153
|
}
|
|
1132
1154
|
|
|
1133
1155
|
declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
1134
1156
|
#private;
|
|
1135
|
-
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext$1, incognito?: boolean, proxy?:
|
|
1157
|
+
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext$1, incognito?: boolean, proxy?: ProxyInController | null, browserIdx?: number, browserContextIdx?: number, maxPagesPerBrowserContext?: number, maxPageFreeSeconds?: number, userAgent?: string, maxViewportOfNewPage?: boolean);
|
|
1136
1158
|
browser(): LsdBrowser;
|
|
1137
1159
|
close(): Promise<boolean>;
|
|
1138
1160
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
@@ -1142,7 +1164,7 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
|
|
|
1142
1164
|
isIncognito(): boolean;
|
|
1143
1165
|
page(pageIdx: number): LsdPage | null;
|
|
1144
1166
|
pages(): LsdPage[];
|
|
1145
|
-
proxy():
|
|
1167
|
+
proxy(): ProxyInController | null;
|
|
1146
1168
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1147
1169
|
_origBrowserContext(): AllBrowserContext;
|
|
1148
1170
|
}
|
|
@@ -1162,6 +1184,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1162
1184
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
1163
1185
|
cookies(): Promise<CookieItem[]>;
|
|
1164
1186
|
documentHeight(): Promise<number>;
|
|
1187
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
1165
1188
|
findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
|
|
1166
1189
|
findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
|
|
1167
1190
|
free(): Promise<boolean>;
|
|
@@ -1197,6 +1220,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1197
1220
|
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
1198
1221
|
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
1199
1222
|
windowMember(keys: string[]): Promise<string>;
|
|
1223
|
+
_origPage(): AllPage;
|
|
1200
1224
|
}
|
|
1201
1225
|
|
|
1202
1226
|
declare class PuppeteerElement implements LsdElement {
|
|
@@ -1229,6 +1253,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1229
1253
|
* @param isHtml default true
|
|
1230
1254
|
*/
|
|
1231
1255
|
constructor(html?: string, isHtml?: boolean);
|
|
1256
|
+
_origPage(): AllPage;
|
|
1232
1257
|
apiRequestContext(): APIRequestContext;
|
|
1233
1258
|
bringToFront(): Promise<boolean>;
|
|
1234
1259
|
browserContext(): LsdBrowserContext;
|
|
@@ -1240,6 +1265,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1240
1265
|
close(): Promise<boolean>;
|
|
1241
1266
|
content(): Promise<string>;
|
|
1242
1267
|
cookies(): Promise<CookieItem[]>;
|
|
1268
|
+
evalute(): Promise<any>;
|
|
1243
1269
|
findElement(selectorOrXpath: string | string[]): Promise<LsdElement | null>;
|
|
1244
1270
|
findElements(selectorOrXpath: string | string[]): Promise<LsdElement[]>;
|
|
1245
1271
|
free(): Promise<boolean>;
|
|
@@ -1310,4 +1336,4 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
|
1310
1336
|
}
|
|
1311
1337
|
declare const controller: LsdBrowserController;
|
|
1312
1338
|
|
|
1313
|
-
export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, CheerioElement, type CheerioNode, CheerioPage, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type
|
|
1339
|
+
export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, CheerioElement, type CheerioNode, CheerioPage, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type ProxyInController, PuppeteerBrowser, PuppeteerBrowserContext, PuppeteerElement, PuppeteerPage, type RequestInterceptionAction, type RequestInterceptionOption, type RequestMatch, type RequestMethod, type RequestResourceType, type ResponseHandler, type ResponseHandlerOptions, type ResponseInterceptionItem, type ResponseInterceptionOption, type ResponseMatch, type ResponsePageData, type ScreenshotOptions, type SelectOptions, type StateData, type UpdatablePageInfo, type ViewportSize, type WaitElementOptions, type WaitElementState, type WaitNavigationOptions, controller };
|
package/dist/index.d.ts
CHANGED
|
@@ -17,22 +17,11 @@ type AllPage = Page | Page$1;
|
|
|
17
17
|
type AllResponse = Response | HTTPResponse;
|
|
18
18
|
type AllApiRequestContext = APIRequestContext;
|
|
19
19
|
type CheerioNode = cheerio.Cheerio<cheerio.Element>;
|
|
20
|
-
type
|
|
21
|
-
|
|
20
|
+
type ProxyInController = {
|
|
21
|
+
proxyUrl: string;
|
|
22
22
|
username?: string;
|
|
23
23
|
password?: string;
|
|
24
24
|
proxyId?: string;
|
|
25
|
-
host?: string;
|
|
26
|
-
port?: number;
|
|
27
|
-
expireTime?: number;
|
|
28
|
-
proxyIpType?: string;
|
|
29
|
-
proxyDurationType?: string;
|
|
30
|
-
proxySharedType?: string;
|
|
31
|
-
latitude?: number;
|
|
32
|
-
longitude?: number;
|
|
33
|
-
freeable?: boolean;
|
|
34
|
-
interfaceName?: string;
|
|
35
|
-
packageName?: string;
|
|
36
25
|
};
|
|
37
26
|
type BrowserControllerType = "puppeteer" | "playwright";
|
|
38
27
|
type BrowserCreationMethod = "launch" | "connect";
|
|
@@ -45,7 +34,6 @@ interface PlaywrightBrowserTypes {
|
|
|
45
34
|
type BrowserControllerOptions = {
|
|
46
35
|
browserControllerType: BrowserControllerType;
|
|
47
36
|
};
|
|
48
|
-
declare const defaultProxy: Proxy;
|
|
49
37
|
interface BrowserOptions {
|
|
50
38
|
/**
|
|
51
39
|
* Interval between closing free pages (seconds) if greater than 0
|
|
@@ -76,7 +64,7 @@ interface BrowserOptions {
|
|
|
76
64
|
* * this will used as default proxy when creating new browserContexts later
|
|
77
65
|
* @default null
|
|
78
66
|
*/
|
|
79
|
-
proxy?:
|
|
67
|
+
proxy?: ProxyInController | null;
|
|
80
68
|
/**
|
|
81
69
|
* Maximum time in milliseconds to wait for the browser instance to start. Pass 0 to disable timeout.
|
|
82
70
|
* * default 30_000 (30 seconds)
|
|
@@ -143,7 +131,7 @@ interface LsdConnectOptions extends BrowserOptions {
|
|
|
143
131
|
userAgent?: string;
|
|
144
132
|
}
|
|
145
133
|
type LsdBrowserContextOptions = {
|
|
146
|
-
proxy:
|
|
134
|
+
proxy: ProxyInController | null;
|
|
147
135
|
/**
|
|
148
136
|
* @default browser.options.maxViewportOfNewPage
|
|
149
137
|
*/
|
|
@@ -154,7 +142,6 @@ type LsdBrowserContextOptions = {
|
|
|
154
142
|
* * puppeteer: set when creating the new page in the browserContext
|
|
155
143
|
*/
|
|
156
144
|
userAgent?: string;
|
|
157
|
-
fingerPrint: Object;
|
|
158
145
|
};
|
|
159
146
|
type PageStatus = "free" | "busy" | "closed";
|
|
160
147
|
/**
|
|
@@ -784,7 +771,15 @@ interface LsdPage extends EventEmitter {
|
|
|
784
771
|
apiRequestContext(): AllApiRequestContext;
|
|
785
772
|
bringToFront(): Promise<boolean>;
|
|
786
773
|
browserContext(): LsdBrowserContext;
|
|
774
|
+
/**
|
|
775
|
+
* clear the cookies of the current page(url)
|
|
776
|
+
* * Prerequisites: page must has a valid url, such as by calling goto(url)
|
|
777
|
+
*/
|
|
787
778
|
clearCookies(): Promise<boolean>;
|
|
779
|
+
/**
|
|
780
|
+
* clear the localStorage of the current page(url)
|
|
781
|
+
* * Prerequisites: page must has a valid url, such as by calling goto(url)
|
|
782
|
+
*/
|
|
788
783
|
clearLocalStorage(): Promise<boolean>;
|
|
789
784
|
/**
|
|
790
785
|
* Clear all request interceptions on the page
|
|
@@ -794,6 +789,11 @@ interface LsdPage extends EventEmitter {
|
|
|
794
789
|
* Clear all response interceptions on the page
|
|
795
790
|
*/
|
|
796
791
|
clearResponseInterceptions(): Promise<boolean>;
|
|
792
|
+
/**
|
|
793
|
+
* clear the stateData of the current page(url):
|
|
794
|
+
* * stateData: cookies, localStorage, indexedDB
|
|
795
|
+
* * Prerequisites: page must has a valid url, such as by calling goto(url)
|
|
796
|
+
*/
|
|
797
797
|
clearStateData(): Promise<boolean>;
|
|
798
798
|
/**
|
|
799
799
|
* Only free page can be closed!
|
|
@@ -805,6 +805,7 @@ interface LsdPage extends EventEmitter {
|
|
|
805
805
|
*/
|
|
806
806
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
807
807
|
cookies(): Promise<CookieItem[]>;
|
|
808
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
808
809
|
/**
|
|
809
810
|
* @returns the first element matching the given CSS selector or XPath
|
|
810
811
|
* @param selectorOrXpath CSS selector or XPath; if this parameter is an array, each selectorOrXpath in the array will be tried until elements are selected
|
|
@@ -875,6 +876,10 @@ interface LsdPage extends EventEmitter {
|
|
|
875
876
|
* @param stateData
|
|
876
877
|
*/
|
|
877
878
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
879
|
+
/**
|
|
880
|
+
* valid only in puppeteer
|
|
881
|
+
* @param userAgent
|
|
882
|
+
*/
|
|
878
883
|
setUserAgent(userAgent: string): Promise<boolean>;
|
|
879
884
|
setViewportSize(viewPortSize: ViewportSize): Promise<boolean>;
|
|
880
885
|
stateData(): Promise<StateData>;
|
|
@@ -902,6 +907,7 @@ interface LsdPage extends EventEmitter {
|
|
|
902
907
|
* @param keys
|
|
903
908
|
*/
|
|
904
909
|
windowMember(keys: string[]): Promise<string>;
|
|
910
|
+
_origPage(): AllPage;
|
|
905
911
|
}
|
|
906
912
|
interface LsdBrowserContext extends EventEmitter {
|
|
907
913
|
browser(): LsdBrowser;
|
|
@@ -913,37 +919,51 @@ interface LsdBrowserContext extends EventEmitter {
|
|
|
913
919
|
*/
|
|
914
920
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
915
921
|
/**
|
|
916
|
-
*
|
|
917
|
-
* * TBD:需要预留pageQuota给需要capName的TE使用
|
|
922
|
+
* get a free page from current pages or by creating a new page
|
|
918
923
|
*/
|
|
919
924
|
getPage(always?: boolean): Promise<LsdPage | null>;
|
|
920
925
|
/**
|
|
921
|
-
*
|
|
922
|
-
*
|
|
926
|
+
* whether can get a number of free page(s)
|
|
927
|
+
* * refer to getPage()
|
|
928
|
+
* @param pageNum default 1, the number of free pages
|
|
923
929
|
*/
|
|
924
930
|
hasNewPage(pageNum?: number): boolean;
|
|
925
931
|
id(): string;
|
|
926
932
|
isIncognito(): boolean;
|
|
927
933
|
page(pageIdx: number): LsdPage | null;
|
|
928
934
|
pages(): LsdPage[];
|
|
929
|
-
proxy():
|
|
935
|
+
proxy(): ProxyInController | null;
|
|
930
936
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
931
937
|
_origBrowserContext(): AllBrowserContext;
|
|
932
938
|
}
|
|
933
939
|
interface LsdBrowser extends EventEmitter {
|
|
934
940
|
newBrowserContext(options?: LsdBrowserContextOptions): Promise<LsdBrowserContext | null>;
|
|
941
|
+
/**
|
|
942
|
+
* 1. launched: close all browserContexts and this browser
|
|
943
|
+
* 2. connected:
|
|
944
|
+
* * in puppeteer: close all browserContexts and this browser???
|
|
945
|
+
* * in playwright: only browserContexts created by newContext will be closed, browser is disconnected and browser will not be closed
|
|
946
|
+
*/
|
|
935
947
|
close(): Promise<boolean>;
|
|
936
948
|
browserContexts(): LsdBrowserContext[];
|
|
937
949
|
browserControllerType(): BrowserControllerType;
|
|
938
950
|
browserCreationMethod(): BrowserCreationMethod;
|
|
939
951
|
browserType(): LsdBrowserType;
|
|
952
|
+
/**
|
|
953
|
+
* @returns
|
|
954
|
+
* 1. launched: actual executable path
|
|
955
|
+
* 2. connected: exectuablePath in LsdConnectOptions, default ""(unkown)
|
|
956
|
+
*/
|
|
940
957
|
executablePath(): string;
|
|
958
|
+
/**
|
|
959
|
+
* get a free BrowserContext from current free browserContexts or new browserContext
|
|
960
|
+
*/
|
|
941
961
|
id(): string;
|
|
942
962
|
isConnected(): boolean;
|
|
943
963
|
isHeadless(): boolean;
|
|
944
964
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
945
965
|
version(): Promise<string>;
|
|
946
|
-
|
|
966
|
+
_origBrowser(): AllBrowser;
|
|
947
967
|
}
|
|
948
968
|
interface LsdBrowserController$1 {
|
|
949
969
|
/**
|
|
@@ -1018,12 +1038,12 @@ declare class PlaywrightBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1018
1038
|
isHeadless(): boolean;
|
|
1019
1039
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
1020
1040
|
version(): Promise<string>;
|
|
1021
|
-
|
|
1041
|
+
_origBrowser(): AllBrowser;
|
|
1022
1042
|
}
|
|
1023
1043
|
|
|
1024
1044
|
declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
1025
1045
|
#private;
|
|
1026
|
-
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext, incognito?: boolean, proxy?:
|
|
1046
|
+
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext, incognito?: boolean, proxy?: ProxyInController | null, browserIdx?: number, browserContextIdx?: number, maxPagesPerBrowserContext?: number, maxPageFreeSeconds?: number, maxViewportOfNewPage?: boolean);
|
|
1027
1047
|
browser(): LsdBrowser;
|
|
1028
1048
|
close(): Promise<boolean>;
|
|
1029
1049
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
@@ -1033,7 +1053,7 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
|
|
|
1033
1053
|
isIncognito(): boolean;
|
|
1034
1054
|
page(pageIdx: number): LsdPage | null;
|
|
1035
1055
|
pages(): LsdPage[];
|
|
1036
|
-
proxy():
|
|
1056
|
+
proxy(): ProxyInController | null;
|
|
1037
1057
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1038
1058
|
_origBrowserContext(): AllBrowserContext;
|
|
1039
1059
|
}
|
|
@@ -1053,6 +1073,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
1053
1073
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
1054
1074
|
cookies(): Promise<CookieItem[]>;
|
|
1055
1075
|
documentHeight(): Promise<number>;
|
|
1076
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
1056
1077
|
findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
|
|
1057
1078
|
findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
|
|
1058
1079
|
free(): Promise<boolean>;
|
|
@@ -1088,6 +1109,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
1088
1109
|
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
1089
1110
|
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
1090
1111
|
windowMember(keys: string[]): Promise<string>;
|
|
1112
|
+
_origPage(): AllPage;
|
|
1091
1113
|
}
|
|
1092
1114
|
|
|
1093
1115
|
declare class PlaywrightElement implements LsdElement {
|
|
@@ -1127,12 +1149,12 @@ declare class PuppeteerBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1127
1149
|
isHeadless(): boolean;
|
|
1128
1150
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
1129
1151
|
version(): Promise<string>;
|
|
1130
|
-
|
|
1152
|
+
_origBrowser(): AllBrowser;
|
|
1131
1153
|
}
|
|
1132
1154
|
|
|
1133
1155
|
declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
1134
1156
|
#private;
|
|
1135
|
-
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext$1, incognito?: boolean, proxy?:
|
|
1157
|
+
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext$1, incognito?: boolean, proxy?: ProxyInController | null, browserIdx?: number, browserContextIdx?: number, maxPagesPerBrowserContext?: number, maxPageFreeSeconds?: number, userAgent?: string, maxViewportOfNewPage?: boolean);
|
|
1136
1158
|
browser(): LsdBrowser;
|
|
1137
1159
|
close(): Promise<boolean>;
|
|
1138
1160
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
@@ -1142,7 +1164,7 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
|
|
|
1142
1164
|
isIncognito(): boolean;
|
|
1143
1165
|
page(pageIdx: number): LsdPage | null;
|
|
1144
1166
|
pages(): LsdPage[];
|
|
1145
|
-
proxy():
|
|
1167
|
+
proxy(): ProxyInController | null;
|
|
1146
1168
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1147
1169
|
_origBrowserContext(): AllBrowserContext;
|
|
1148
1170
|
}
|
|
@@ -1162,6 +1184,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1162
1184
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
1163
1185
|
cookies(): Promise<CookieItem[]>;
|
|
1164
1186
|
documentHeight(): Promise<number>;
|
|
1187
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
1165
1188
|
findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
|
|
1166
1189
|
findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
|
|
1167
1190
|
free(): Promise<boolean>;
|
|
@@ -1197,6 +1220,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1197
1220
|
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
1198
1221
|
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
1199
1222
|
windowMember(keys: string[]): Promise<string>;
|
|
1223
|
+
_origPage(): AllPage;
|
|
1200
1224
|
}
|
|
1201
1225
|
|
|
1202
1226
|
declare class PuppeteerElement implements LsdElement {
|
|
@@ -1229,6 +1253,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1229
1253
|
* @param isHtml default true
|
|
1230
1254
|
*/
|
|
1231
1255
|
constructor(html?: string, isHtml?: boolean);
|
|
1256
|
+
_origPage(): AllPage;
|
|
1232
1257
|
apiRequestContext(): APIRequestContext;
|
|
1233
1258
|
bringToFront(): Promise<boolean>;
|
|
1234
1259
|
browserContext(): LsdBrowserContext;
|
|
@@ -1240,6 +1265,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1240
1265
|
close(): Promise<boolean>;
|
|
1241
1266
|
content(): Promise<string>;
|
|
1242
1267
|
cookies(): Promise<CookieItem[]>;
|
|
1268
|
+
evalute(): Promise<any>;
|
|
1243
1269
|
findElement(selectorOrXpath: string | string[]): Promise<LsdElement | null>;
|
|
1244
1270
|
findElements(selectorOrXpath: string | string[]): Promise<LsdElement[]>;
|
|
1245
1271
|
free(): Promise<boolean>;
|
|
@@ -1310,4 +1336,4 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
|
1310
1336
|
}
|
|
1311
1337
|
declare const controller: LsdBrowserController;
|
|
1312
1338
|
|
|
1313
|
-
export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, CheerioElement, type CheerioNode, CheerioPage, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type
|
|
1339
|
+
export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, CheerioElement, type CheerioNode, CheerioPage, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type ProxyInController, PuppeteerBrowser, PuppeteerBrowserContext, PuppeteerElement, PuppeteerPage, type RequestInterceptionAction, type RequestInterceptionOption, type RequestMatch, type RequestMethod, type RequestResourceType, type ResponseHandler, type ResponseHandlerOptions, type ResponseInterceptionItem, type ResponseInterceptionOption, type ResponseMatch, type ResponsePageData, type ScreenshotOptions, type SelectOptions, type StateData, type UpdatablePageInfo, type ViewportSize, type WaitElementOptions, type WaitElementState, type WaitNavigationOptions, controller };
|
package/dist/index.js
CHANGED
|
@@ -43,16 +43,6 @@ var require_boolbase = __commonJS({
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
// src/types/types.ts
|
|
47
|
-
var defaultProxy = {
|
|
48
|
-
server: "default",
|
|
49
|
-
proxyIpType: "residential",
|
|
50
|
-
proxyDurationType: "static",
|
|
51
|
-
proxySharedType: "dedicated",
|
|
52
|
-
expireTime: 41024196e5
|
|
53
|
-
// "2100-01-01 01:00:00"
|
|
54
|
-
};
|
|
55
|
-
|
|
56
46
|
// src/playwright/browser.ts
|
|
57
47
|
import EventEmitter3 from "events";
|
|
58
48
|
|
|
@@ -568,7 +558,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
568
558
|
const currentTime = getCurrentUnixTime();
|
|
569
559
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
570
560
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
571
|
-
this.#pageId = `page
|
|
561
|
+
this.#pageId = `page-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
572
562
|
this.#resquestInterceptionOptions = [];
|
|
573
563
|
this.#responseInterceptionOptions = [];
|
|
574
564
|
this.#client = null;
|
|
@@ -677,6 +667,12 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
677
667
|
const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
|
|
678
668
|
return height;
|
|
679
669
|
}
|
|
670
|
+
async evalute(fun, args) {
|
|
671
|
+
if (!this.#page) {
|
|
672
|
+
throw new Error("No valid page");
|
|
673
|
+
}
|
|
674
|
+
return this.#page.evaluate(fun, args);
|
|
675
|
+
}
|
|
680
676
|
async findElement(selectorOrXpath, iframeOptions = []) {
|
|
681
677
|
if (!this.#page) {
|
|
682
678
|
throw new Error("No valid page");
|
|
@@ -1166,6 +1162,9 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
1166
1162
|
);
|
|
1167
1163
|
return content;
|
|
1168
1164
|
}
|
|
1165
|
+
_origPage() {
|
|
1166
|
+
return this.#page;
|
|
1167
|
+
}
|
|
1169
1168
|
};
|
|
1170
1169
|
|
|
1171
1170
|
// src/playwright/context.ts
|
|
@@ -1214,7 +1213,7 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1214
1213
|
this.#browserContext = browserContext;
|
|
1215
1214
|
this.#createTime = getCurrentUnixTime2();
|
|
1216
1215
|
this.#incognito = incognito === false ? false : true;
|
|
1217
|
-
this.#proxy = proxy?.
|
|
1216
|
+
this.#proxy = proxy?.proxyUrl ? proxy : null;
|
|
1218
1217
|
this.#maxPagesPerBrowserContext = maxPagesPerBrowserContext;
|
|
1219
1218
|
this.#maxPageFreeSeconds = maxPageFreeSeconds;
|
|
1220
1219
|
this.#maxViewportOfNewPage = maxViewportOfNewPage;
|
|
@@ -1235,7 +1234,7 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1235
1234
|
await lsdPage.maximizeViewport();
|
|
1236
1235
|
}
|
|
1237
1236
|
this.#lsdPages.push(lsdPage);
|
|
1238
|
-
loginfo3(`##
|
|
1237
|
+
loginfo3(`##page ${lsdPage.id()} created`);
|
|
1239
1238
|
}
|
|
1240
1239
|
});
|
|
1241
1240
|
browserContext.on("close", (bc) => {
|
|
@@ -1387,12 +1386,16 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1387
1386
|
throw new Error("No valid browserContext");
|
|
1388
1387
|
}
|
|
1389
1388
|
const { cookies, localStorage: localStorageOrigins } = stateData;
|
|
1390
|
-
const page = await this
|
|
1389
|
+
const page = await this.getPage();
|
|
1390
|
+
if (!page) {
|
|
1391
|
+
return false;
|
|
1392
|
+
}
|
|
1393
|
+
const origPage = page._origPage();
|
|
1391
1394
|
if (cookies.length > 0) {
|
|
1392
1395
|
await this.#browserContext.addCookies(cookies);
|
|
1393
1396
|
}
|
|
1394
1397
|
if (localStorageOrigins.length > 0) {
|
|
1395
|
-
await
|
|
1398
|
+
await origPage.route("**/*", async (route) => {
|
|
1396
1399
|
const request = route.request();
|
|
1397
1400
|
await route.fulfill({
|
|
1398
1401
|
status: 200,
|
|
@@ -1402,15 +1405,16 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1402
1405
|
});
|
|
1403
1406
|
for (const localStorageOrigin of localStorageOrigins) {
|
|
1404
1407
|
const { origin, localStorage } = localStorageOrigin;
|
|
1405
|
-
await
|
|
1406
|
-
await
|
|
1408
|
+
await origPage.goto(origin);
|
|
1409
|
+
await origPage.evaluate((localStorageItems) => {
|
|
1407
1410
|
for (const item of localStorageItems) {
|
|
1408
1411
|
window.localStorage.setItem(item.name, item.value);
|
|
1409
1412
|
}
|
|
1410
1413
|
}, localStorage);
|
|
1411
1414
|
}
|
|
1412
1415
|
}
|
|
1413
|
-
await
|
|
1416
|
+
await origPage.unrouteAll();
|
|
1417
|
+
await page.free();
|
|
1414
1418
|
return true;
|
|
1415
1419
|
}
|
|
1416
1420
|
_origBrowserContext() {
|
|
@@ -1465,7 +1469,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1465
1469
|
this.#executablePath = executablePath;
|
|
1466
1470
|
this.#nextBrowserContextIdx = 1;
|
|
1467
1471
|
this.#closeFreePagesIntervalId = null;
|
|
1468
|
-
loginfo4(`##browser
|
|
1472
|
+
loginfo4(`##browser ${this.id()} ${this.#browserCreationMethod}ed by ${this.#browserControllerType}`);
|
|
1469
1473
|
const browserContexts = browser.contexts();
|
|
1470
1474
|
if (browserContexts.length > 0) {
|
|
1471
1475
|
logwarn3(`There are ${browserContexts.length} new browserContexts when playwright launches new browser`);
|
|
@@ -1474,7 +1478,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1474
1478
|
for (const browserContext of browserContexts) {
|
|
1475
1479
|
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, incognito, this.#proxy, this.#browserIdx++, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
1476
1480
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
1477
|
-
loginfo4(`##
|
|
1481
|
+
loginfo4(`##browserContext ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
1478
1482
|
}
|
|
1479
1483
|
browser.on("disconnected", () => {
|
|
1480
1484
|
loginfo4(`##browser ${this.id()} disconnected`);
|
|
@@ -1492,7 +1496,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1492
1496
|
logerr3(`Invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
1493
1497
|
return;
|
|
1494
1498
|
}
|
|
1495
|
-
loginfo4(`##
|
|
1499
|
+
loginfo4(`##browserContext ${lsdBrowserContext.id()} closed
|
|
1496
1500
|
`);
|
|
1497
1501
|
this.#lsdBrowserContexts.splice(idx, 1);
|
|
1498
1502
|
if (this.#lsdBrowserContexts.length === 0) {
|
|
@@ -1523,7 +1527,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1523
1527
|
}
|
|
1524
1528
|
const proxy = options?.proxy ? Object.assign({}, options.proxy) : this.#proxy;
|
|
1525
1529
|
if (proxy) {
|
|
1526
|
-
const { server, username, password } = proxy;
|
|
1530
|
+
const { proxyUrl: server, username, password } = proxy;
|
|
1527
1531
|
browserContextOptions.proxy = { server, username, password };
|
|
1528
1532
|
}
|
|
1529
1533
|
if (options?.userAgent) {
|
|
@@ -1563,7 +1567,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1563
1567
|
return this.#executablePath;
|
|
1564
1568
|
}
|
|
1565
1569
|
id() {
|
|
1566
|
-
return `browser-${this.#browserIdx}`;
|
|
1570
|
+
return `browser-${this.#browserType}-${this.#browserIdx}`;
|
|
1567
1571
|
}
|
|
1568
1572
|
isConnected() {
|
|
1569
1573
|
return this.#browser.isConnected();
|
|
@@ -1578,8 +1582,8 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1578
1582
|
const version = await this.#browser.version();
|
|
1579
1583
|
return version;
|
|
1580
1584
|
}
|
|
1581
|
-
|
|
1582
|
-
return this.#browser
|
|
1585
|
+
_origBrowser() {
|
|
1586
|
+
return this.#browser;
|
|
1583
1587
|
}
|
|
1584
1588
|
};
|
|
1585
1589
|
|
|
@@ -2058,7 +2062,7 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2058
2062
|
const currentTime = getCurrentUnixTime3();
|
|
2059
2063
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
2060
2064
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
2061
|
-
this.#pageId = `page
|
|
2065
|
+
this.#pageId = `page-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
2062
2066
|
this.#requestInterceptionNum = 0;
|
|
2063
2067
|
this.#responseInterceptionNum = 0;
|
|
2064
2068
|
this.#client = null;
|
|
@@ -2161,6 +2165,12 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2161
2165
|
const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
|
|
2162
2166
|
return height;
|
|
2163
2167
|
}
|
|
2168
|
+
async evalute(fun, args) {
|
|
2169
|
+
if (!this.#page) {
|
|
2170
|
+
throw new Error("No valid page");
|
|
2171
|
+
}
|
|
2172
|
+
return this.#page.evaluate(fun, args);
|
|
2173
|
+
}
|
|
2164
2174
|
async findElement(selectorOrXpath, iframeOptions = []) {
|
|
2165
2175
|
if (!this.#page) {
|
|
2166
2176
|
throw new Error("No valid page");
|
|
@@ -2641,6 +2651,9 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2641
2651
|
);
|
|
2642
2652
|
return content;
|
|
2643
2653
|
}
|
|
2654
|
+
_origPage() {
|
|
2655
|
+
return this.#page;
|
|
2656
|
+
}
|
|
2644
2657
|
};
|
|
2645
2658
|
|
|
2646
2659
|
// src/puppeteer/context.ts
|
|
@@ -2699,7 +2712,7 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
2699
2712
|
this.#userAgent = userAgent;
|
|
2700
2713
|
this.#createTime = getCurrentUnixTime4();
|
|
2701
2714
|
this.#incognito = incognito === false ? false : true;
|
|
2702
|
-
this.#proxy = proxy?.
|
|
2715
|
+
this.#proxy = proxy?.proxyUrl ? proxy : null;
|
|
2703
2716
|
this.#maxPagesPerBrowserContext = maxPagesPerBrowserContext;
|
|
2704
2717
|
this.#maxPageFreeSeconds = maxPageFreeSeconds;
|
|
2705
2718
|
this.#maxViewportOfNewPage = maxViewportOfNewPage;
|
|
@@ -2728,7 +2741,7 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
2728
2741
|
await lsdPage.setUserAgent(this.#userAgent);
|
|
2729
2742
|
}
|
|
2730
2743
|
this.#lsdPages.push(lsdPage);
|
|
2731
|
-
loginfo6(`##
|
|
2744
|
+
loginfo6(`##page ${lsdPage.id()} created`);
|
|
2732
2745
|
}
|
|
2733
2746
|
}
|
|
2734
2747
|
});
|
|
@@ -2880,13 +2893,17 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
2880
2893
|
throw new Error("No valid browserContext");
|
|
2881
2894
|
}
|
|
2882
2895
|
const { cookies, localStorage: localStorageOrigins } = stateData;
|
|
2883
|
-
const page = await this
|
|
2896
|
+
const page = await this.getPage();
|
|
2897
|
+
if (!page) {
|
|
2898
|
+
return false;
|
|
2899
|
+
}
|
|
2900
|
+
const origPage = page._origPage();
|
|
2884
2901
|
if (cookies.length > 0) {
|
|
2885
|
-
await
|
|
2902
|
+
await origPage.setCookie(...cookies);
|
|
2886
2903
|
}
|
|
2887
2904
|
if (localStorageOrigins.length > 0) {
|
|
2888
|
-
await
|
|
2889
|
-
|
|
2905
|
+
await origPage.setRequestInterception(true);
|
|
2906
|
+
origPage.on("request", (request) => {
|
|
2890
2907
|
request.respond({
|
|
2891
2908
|
status: 200,
|
|
2892
2909
|
// contentType: "text/html; charset=utf-8", // "text/plain",
|
|
@@ -2895,15 +2912,16 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
2895
2912
|
});
|
|
2896
2913
|
for (const localStorageOrigin of localStorageOrigins) {
|
|
2897
2914
|
const { origin, localStorage } = localStorageOrigin;
|
|
2898
|
-
await
|
|
2899
|
-
await
|
|
2915
|
+
await origPage.goto(origin);
|
|
2916
|
+
await origPage.evaluate((localStorageItems) => {
|
|
2900
2917
|
for (const item of localStorageItems) {
|
|
2901
2918
|
window.localStorage.setItem(item.name, item.value);
|
|
2902
2919
|
}
|
|
2903
2920
|
}, localStorage);
|
|
2904
2921
|
}
|
|
2905
2922
|
}
|
|
2906
|
-
await
|
|
2923
|
+
await origPage.setRequestInterception(false);
|
|
2924
|
+
await page.free();
|
|
2907
2925
|
return true;
|
|
2908
2926
|
}
|
|
2909
2927
|
_origBrowserContext() {
|
|
@@ -3012,8 +3030,8 @@ var PuppeteerBrowser = class extends EventEmitter6 {
|
|
|
3012
3030
|
}
|
|
3013
3031
|
const browserContextOptions = {};
|
|
3014
3032
|
const proxy = options?.proxy ? Object.assign({}, options.proxy) : this.#proxy;
|
|
3015
|
-
if (proxy?.
|
|
3016
|
-
browserContextOptions.proxyServer = proxy.
|
|
3033
|
+
if (proxy?.proxyUrl) {
|
|
3034
|
+
browserContextOptions.proxyServer = proxy.proxyUrl;
|
|
3017
3035
|
}
|
|
3018
3036
|
const browserContext = await this.#browser.createBrowserContext(browserContextOptions);
|
|
3019
3037
|
const userAgent = options?.userAgent ? options.userAgent : "";
|
|
@@ -3067,8 +3085,8 @@ var PuppeteerBrowser = class extends EventEmitter6 {
|
|
|
3067
3085
|
const version = await this.#browser.version();
|
|
3068
3086
|
return version;
|
|
3069
3087
|
}
|
|
3070
|
-
|
|
3071
|
-
return this.#browser
|
|
3088
|
+
_origBrowser() {
|
|
3089
|
+
return this.#browser;
|
|
3072
3090
|
}
|
|
3073
3091
|
};
|
|
3074
3092
|
|
|
@@ -17056,6 +17074,9 @@ var CheerioPage = class extends EventEmitter7 {
|
|
|
17056
17074
|
this.#document = load(html3, { xml: true }).root();
|
|
17057
17075
|
}
|
|
17058
17076
|
}
|
|
17077
|
+
_origPage() {
|
|
17078
|
+
throw new Error("Method not implemented.");
|
|
17079
|
+
}
|
|
17059
17080
|
apiRequestContext() {
|
|
17060
17081
|
throw new Error("Not supported in CheerioPage.");
|
|
17061
17082
|
}
|
|
@@ -17089,6 +17110,9 @@ var CheerioPage = class extends EventEmitter7 {
|
|
|
17089
17110
|
async cookies() {
|
|
17090
17111
|
throw new Error("Not supported in CheerioPage.");
|
|
17091
17112
|
}
|
|
17113
|
+
async evalute() {
|
|
17114
|
+
throw new Error("Not supported in CheerioPage.");
|
|
17115
|
+
}
|
|
17092
17116
|
#findNodes(selector) {
|
|
17093
17117
|
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
17094
17118
|
throw new Error("Do not support XPath in cheerio.");
|
|
@@ -17370,8 +17394,9 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17370
17394
|
if (maxWindowSize) {
|
|
17371
17395
|
args.push("--start-maximized");
|
|
17372
17396
|
}
|
|
17373
|
-
if (proxy?.
|
|
17374
|
-
|
|
17397
|
+
if (proxy?.proxyUrl && proxy.proxyUrl !== "local") {
|
|
17398
|
+
const { proxyUrl: server, username, password } = proxy;
|
|
17399
|
+
launchOptions.proxy = { server, username, password };
|
|
17375
17400
|
} else if (proxyPerBrowserContext && browserType === "chromium" && this.#osPlatform.startsWith("win")) {
|
|
17376
17401
|
launchOptions.proxy = { server: "proxyPerBrowserContext" };
|
|
17377
17402
|
}
|
|
@@ -17410,8 +17435,8 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17410
17435
|
} else if (userDataDir) {
|
|
17411
17436
|
args.push(`--user-data-dir=${userDataDir}`);
|
|
17412
17437
|
}
|
|
17413
|
-
if (proxy?.
|
|
17414
|
-
args.push(`--proxy-server=${proxy.
|
|
17438
|
+
if (proxy?.proxyUrl && proxy.proxyUrl !== "default") {
|
|
17439
|
+
args.push(`--proxy-server=${proxy.proxyUrl}`);
|
|
17415
17440
|
} else if (proxyPerBrowserContext && browserType === "chromium" && this.#osPlatform.startsWith("win")) {
|
|
17416
17441
|
args.push(`--proxy-server=proxyPerBrowserContext`);
|
|
17417
17442
|
}
|
|
@@ -17483,6 +17508,5 @@ export {
|
|
|
17483
17508
|
PuppeteerBrowserContext,
|
|
17484
17509
|
PuppeteerElement,
|
|
17485
17510
|
PuppeteerPage,
|
|
17486
|
-
controller
|
|
17487
|
-
defaultProxy
|
|
17511
|
+
controller
|
|
17488
17512
|
};
|
package/package.json
CHANGED