@letsscrapedata/controller 0.0.33 → 0.0.35
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 +58 -24
- package/dist/index.d.cts +39 -15
- package/dist/index.d.ts +39 -15
- package/dist/index.js +58 -24
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -577,7 +577,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
577
577
|
const currentTime = (0, import_utils2.getCurrentUnixTime)();
|
|
578
578
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
579
579
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
580
|
-
this.#pageId = `page
|
|
580
|
+
this.#pageId = `page-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
581
581
|
this.#resquestInterceptionOptions = [];
|
|
582
582
|
this.#responseInterceptionOptions = [];
|
|
583
583
|
this.#client = null;
|
|
@@ -686,6 +686,12 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
686
686
|
const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
|
|
687
687
|
return height;
|
|
688
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
|
+
}
|
|
689
695
|
async findElement(selectorOrXpath, iframeOptions = []) {
|
|
690
696
|
if (!this.#page) {
|
|
691
697
|
throw new Error("No valid page");
|
|
@@ -1175,6 +1181,9 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
1175
1181
|
);
|
|
1176
1182
|
return content;
|
|
1177
1183
|
}
|
|
1184
|
+
_origPage() {
|
|
1185
|
+
return this.#page;
|
|
1186
|
+
}
|
|
1178
1187
|
};
|
|
1179
1188
|
|
|
1180
1189
|
// src/playwright/context.ts
|
|
@@ -1244,7 +1253,7 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1244
1253
|
await lsdPage.maximizeViewport();
|
|
1245
1254
|
}
|
|
1246
1255
|
this.#lsdPages.push(lsdPage);
|
|
1247
|
-
(0, import_utils3.loginfo)(`##
|
|
1256
|
+
(0, import_utils3.loginfo)(`##page ${lsdPage.id()} created`);
|
|
1248
1257
|
}
|
|
1249
1258
|
});
|
|
1250
1259
|
browserContext.on("close", (bc) => {
|
|
@@ -1396,12 +1405,16 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1396
1405
|
throw new Error("No valid browserContext");
|
|
1397
1406
|
}
|
|
1398
1407
|
const { cookies, localStorage: localStorageOrigins } = stateData;
|
|
1399
|
-
const page = await this
|
|
1408
|
+
const page = await this.getPage();
|
|
1409
|
+
if (!page) {
|
|
1410
|
+
return false;
|
|
1411
|
+
}
|
|
1412
|
+
const origPage = page._origPage();
|
|
1400
1413
|
if (cookies.length > 0) {
|
|
1401
1414
|
await this.#browserContext.addCookies(cookies);
|
|
1402
1415
|
}
|
|
1403
1416
|
if (localStorageOrigins.length > 0) {
|
|
1404
|
-
await
|
|
1417
|
+
await origPage.route("**/*", async (route) => {
|
|
1405
1418
|
const request = route.request();
|
|
1406
1419
|
await route.fulfill({
|
|
1407
1420
|
status: 200,
|
|
@@ -1411,15 +1424,16 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1411
1424
|
});
|
|
1412
1425
|
for (const localStorageOrigin of localStorageOrigins) {
|
|
1413
1426
|
const { origin, localStorage } = localStorageOrigin;
|
|
1414
|
-
await
|
|
1415
|
-
await
|
|
1427
|
+
await origPage.goto(origin);
|
|
1428
|
+
await origPage.evaluate((localStorageItems) => {
|
|
1416
1429
|
for (const item of localStorageItems) {
|
|
1417
1430
|
window.localStorage.setItem(item.name, item.value);
|
|
1418
1431
|
}
|
|
1419
1432
|
}, localStorage);
|
|
1420
1433
|
}
|
|
1421
1434
|
}
|
|
1422
|
-
await
|
|
1435
|
+
await origPage.unrouteAll();
|
|
1436
|
+
await page.free();
|
|
1423
1437
|
return true;
|
|
1424
1438
|
}
|
|
1425
1439
|
_origBrowserContext() {
|
|
@@ -1474,7 +1488,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1474
1488
|
this.#executablePath = executablePath;
|
|
1475
1489
|
this.#nextBrowserContextIdx = 1;
|
|
1476
1490
|
this.#closeFreePagesIntervalId = null;
|
|
1477
|
-
(0, import_utils4.loginfo)(`##browser
|
|
1491
|
+
(0, import_utils4.loginfo)(`##browser ${this.id()} ${this.#browserCreationMethod}ed by ${this.#browserControllerType}`);
|
|
1478
1492
|
const browserContexts = browser.contexts();
|
|
1479
1493
|
if (browserContexts.length > 0) {
|
|
1480
1494
|
(0, import_utils4.logwarn)(`There are ${browserContexts.length} new browserContexts when playwright launches new browser`);
|
|
@@ -1483,7 +1497,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1483
1497
|
for (const browserContext of browserContexts) {
|
|
1484
1498
|
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, incognito, this.#proxy, this.#browserIdx++, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
1485
1499
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
1486
|
-
(0, import_utils4.loginfo)(`##
|
|
1500
|
+
(0, import_utils4.loginfo)(`##browserContext ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
1487
1501
|
}
|
|
1488
1502
|
browser.on("disconnected", () => {
|
|
1489
1503
|
(0, import_utils4.loginfo)(`##browser ${this.id()} disconnected`);
|
|
@@ -1501,7 +1515,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1501
1515
|
(0, import_utils4.logerr)(`Invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
1502
1516
|
return;
|
|
1503
1517
|
}
|
|
1504
|
-
(0, import_utils4.loginfo)(`##
|
|
1518
|
+
(0, import_utils4.loginfo)(`##browserContext ${lsdBrowserContext.id()} closed
|
|
1505
1519
|
`);
|
|
1506
1520
|
this.#lsdBrowserContexts.splice(idx, 1);
|
|
1507
1521
|
if (this.#lsdBrowserContexts.length === 0) {
|
|
@@ -1572,7 +1586,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1572
1586
|
return this.#executablePath;
|
|
1573
1587
|
}
|
|
1574
1588
|
id() {
|
|
1575
|
-
return `browser-${this.#browserIdx}`;
|
|
1589
|
+
return `browser-${this.#browserType}-${this.#browserIdx}`;
|
|
1576
1590
|
}
|
|
1577
1591
|
isConnected() {
|
|
1578
1592
|
return this.#browser.isConnected();
|
|
@@ -1587,8 +1601,8 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1587
1601
|
const version = await this.#browser.version();
|
|
1588
1602
|
return version;
|
|
1589
1603
|
}
|
|
1590
|
-
|
|
1591
|
-
return this.#browser
|
|
1604
|
+
_origBrowser() {
|
|
1605
|
+
return this.#browser;
|
|
1592
1606
|
}
|
|
1593
1607
|
};
|
|
1594
1608
|
|
|
@@ -2067,7 +2081,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2067
2081
|
const currentTime = (0, import_utils6.getCurrentUnixTime)();
|
|
2068
2082
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
2069
2083
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
2070
|
-
this.#pageId = `page
|
|
2084
|
+
this.#pageId = `page-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
2071
2085
|
this.#requestInterceptionNum = 0;
|
|
2072
2086
|
this.#responseInterceptionNum = 0;
|
|
2073
2087
|
this.#client = null;
|
|
@@ -2170,6 +2184,12 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2170
2184
|
const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
|
|
2171
2185
|
return height;
|
|
2172
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
|
+
}
|
|
2173
2193
|
async findElement(selectorOrXpath, iframeOptions = []) {
|
|
2174
2194
|
if (!this.#page) {
|
|
2175
2195
|
throw new Error("No valid page");
|
|
@@ -2650,6 +2670,9 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2650
2670
|
);
|
|
2651
2671
|
return content;
|
|
2652
2672
|
}
|
|
2673
|
+
_origPage() {
|
|
2674
|
+
return this.#page;
|
|
2675
|
+
}
|
|
2653
2676
|
};
|
|
2654
2677
|
|
|
2655
2678
|
// src/puppeteer/context.ts
|
|
@@ -2737,7 +2760,7 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
2737
2760
|
await lsdPage.setUserAgent(this.#userAgent);
|
|
2738
2761
|
}
|
|
2739
2762
|
this.#lsdPages.push(lsdPage);
|
|
2740
|
-
(0, import_utils7.loginfo)(`##
|
|
2763
|
+
(0, import_utils7.loginfo)(`##page ${lsdPage.id()} created`);
|
|
2741
2764
|
}
|
|
2742
2765
|
}
|
|
2743
2766
|
});
|
|
@@ -2889,13 +2912,17 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
2889
2912
|
throw new Error("No valid browserContext");
|
|
2890
2913
|
}
|
|
2891
2914
|
const { cookies, localStorage: localStorageOrigins } = stateData;
|
|
2892
|
-
const page = await this
|
|
2915
|
+
const page = await this.getPage();
|
|
2916
|
+
if (!page) {
|
|
2917
|
+
return false;
|
|
2918
|
+
}
|
|
2919
|
+
const origPage = page._origPage();
|
|
2893
2920
|
if (cookies.length > 0) {
|
|
2894
|
-
await
|
|
2921
|
+
await origPage.setCookie(...cookies);
|
|
2895
2922
|
}
|
|
2896
2923
|
if (localStorageOrigins.length > 0) {
|
|
2897
|
-
await
|
|
2898
|
-
|
|
2924
|
+
await origPage.setRequestInterception(true);
|
|
2925
|
+
origPage.on("request", (request) => {
|
|
2899
2926
|
request.respond({
|
|
2900
2927
|
status: 200,
|
|
2901
2928
|
// contentType: "text/html; charset=utf-8", // "text/plain",
|
|
@@ -2904,15 +2931,16 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
2904
2931
|
});
|
|
2905
2932
|
for (const localStorageOrigin of localStorageOrigins) {
|
|
2906
2933
|
const { origin, localStorage } = localStorageOrigin;
|
|
2907
|
-
await
|
|
2908
|
-
await
|
|
2934
|
+
await origPage.goto(origin);
|
|
2935
|
+
await origPage.evaluate((localStorageItems) => {
|
|
2909
2936
|
for (const item of localStorageItems) {
|
|
2910
2937
|
window.localStorage.setItem(item.name, item.value);
|
|
2911
2938
|
}
|
|
2912
2939
|
}, localStorage);
|
|
2913
2940
|
}
|
|
2914
2941
|
}
|
|
2915
|
-
await
|
|
2942
|
+
await origPage.setRequestInterception(false);
|
|
2943
|
+
await page.free();
|
|
2916
2944
|
return true;
|
|
2917
2945
|
}
|
|
2918
2946
|
_origBrowserContext() {
|
|
@@ -3076,8 +3104,8 @@ var PuppeteerBrowser = class extends import_node_events6.default {
|
|
|
3076
3104
|
const version = await this.#browser.version();
|
|
3077
3105
|
return version;
|
|
3078
3106
|
}
|
|
3079
|
-
|
|
3080
|
-
return this.#browser
|
|
3107
|
+
_origBrowser() {
|
|
3108
|
+
return this.#browser;
|
|
3081
3109
|
}
|
|
3082
3110
|
};
|
|
3083
3111
|
|
|
@@ -17065,6 +17093,9 @@ var CheerioPage = class extends import_node_events7.default {
|
|
|
17065
17093
|
this.#document = load(html3, { xml: true }).root();
|
|
17066
17094
|
}
|
|
17067
17095
|
}
|
|
17096
|
+
_origPage() {
|
|
17097
|
+
throw new Error("Method not implemented.");
|
|
17098
|
+
}
|
|
17068
17099
|
apiRequestContext() {
|
|
17069
17100
|
throw new Error("Not supported in CheerioPage.");
|
|
17070
17101
|
}
|
|
@@ -17098,6 +17129,9 @@ var CheerioPage = class extends import_node_events7.default {
|
|
|
17098
17129
|
async cookies() {
|
|
17099
17130
|
throw new Error("Not supported in CheerioPage.");
|
|
17100
17131
|
}
|
|
17132
|
+
async evalute() {
|
|
17133
|
+
throw new Error("Not supported in CheerioPage.");
|
|
17134
|
+
}
|
|
17101
17135
|
#findNodes(selector) {
|
|
17102
17136
|
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
17103
17137
|
throw new Error("Do not support XPath in cheerio.");
|
package/dist/index.d.cts
CHANGED
|
@@ -419,7 +419,7 @@ interface LocalStorageOrigin {
|
|
|
419
419
|
origin: string;
|
|
420
420
|
localStorage: LocalStorageItem[];
|
|
421
421
|
}
|
|
422
|
-
interface
|
|
422
|
+
interface BrowserStateData {
|
|
423
423
|
cookies: CookieItem[];
|
|
424
424
|
localStorage: LocalStorageOrigin[];
|
|
425
425
|
}
|
|
@@ -771,7 +771,15 @@ interface LsdPage extends EventEmitter {
|
|
|
771
771
|
apiRequestContext(): AllApiRequestContext;
|
|
772
772
|
bringToFront(): Promise<boolean>;
|
|
773
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
|
+
*/
|
|
774
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
|
+
*/
|
|
775
783
|
clearLocalStorage(): Promise<boolean>;
|
|
776
784
|
/**
|
|
777
785
|
* Clear all request interceptions on the page
|
|
@@ -781,6 +789,11 @@ interface LsdPage extends EventEmitter {
|
|
|
781
789
|
* Clear all response interceptions on the page
|
|
782
790
|
*/
|
|
783
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
|
+
*/
|
|
784
797
|
clearStateData(): Promise<boolean>;
|
|
785
798
|
/**
|
|
786
799
|
* Only free page can be closed!
|
|
@@ -792,6 +805,7 @@ interface LsdPage extends EventEmitter {
|
|
|
792
805
|
*/
|
|
793
806
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
794
807
|
cookies(): Promise<CookieItem[]>;
|
|
808
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
795
809
|
/**
|
|
796
810
|
* @returns the first element matching the given CSS selector or XPath
|
|
797
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
|
|
@@ -861,14 +875,14 @@ interface LsdPage extends EventEmitter {
|
|
|
861
875
|
* Shortcut for LsdPage.browserContext().setStateData(stateData)
|
|
862
876
|
* @param stateData
|
|
863
877
|
*/
|
|
864
|
-
setStateData(stateData:
|
|
878
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
865
879
|
/**
|
|
866
880
|
* valid only in puppeteer
|
|
867
881
|
* @param userAgent
|
|
868
882
|
*/
|
|
869
883
|
setUserAgent(userAgent: string): Promise<boolean>;
|
|
870
884
|
setViewportSize(viewPortSize: ViewportSize): Promise<boolean>;
|
|
871
|
-
stateData(): Promise<
|
|
885
|
+
stateData(): Promise<BrowserStateData>;
|
|
872
886
|
status(): PageStatus;
|
|
873
887
|
title(): Promise<string>;
|
|
874
888
|
url(): string;
|
|
@@ -893,6 +907,7 @@ interface LsdPage extends EventEmitter {
|
|
|
893
907
|
* @param keys
|
|
894
908
|
*/
|
|
895
909
|
windowMember(keys: string[]): Promise<string>;
|
|
910
|
+
_origPage(): AllPage;
|
|
896
911
|
}
|
|
897
912
|
interface LsdBrowserContext extends EventEmitter {
|
|
898
913
|
browser(): LsdBrowser;
|
|
@@ -918,7 +933,7 @@ interface LsdBrowserContext extends EventEmitter {
|
|
|
918
933
|
page(pageIdx: number): LsdPage | null;
|
|
919
934
|
pages(): LsdPage[];
|
|
920
935
|
proxy(): ProxyInController | null;
|
|
921
|
-
setStateData(stateData:
|
|
936
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
922
937
|
_origBrowserContext(): AllBrowserContext;
|
|
923
938
|
}
|
|
924
939
|
interface LsdBrowser extends EventEmitter {
|
|
@@ -940,12 +955,15 @@ interface LsdBrowser extends EventEmitter {
|
|
|
940
955
|
* 2. connected: exectuablePath in LsdConnectOptions, default ""(unkown)
|
|
941
956
|
*/
|
|
942
957
|
executablePath(): string;
|
|
958
|
+
/**
|
|
959
|
+
* get a free BrowserContext from current free browserContexts or new browserContext
|
|
960
|
+
*/
|
|
943
961
|
id(): string;
|
|
944
962
|
isConnected(): boolean;
|
|
945
963
|
isHeadless(): boolean;
|
|
946
964
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
947
965
|
version(): Promise<string>;
|
|
948
|
-
|
|
966
|
+
_origBrowser(): AllBrowser;
|
|
949
967
|
}
|
|
950
968
|
interface LsdBrowserController$1 {
|
|
951
969
|
/**
|
|
@@ -1020,7 +1038,7 @@ declare class PlaywrightBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1020
1038
|
isHeadless(): boolean;
|
|
1021
1039
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
1022
1040
|
version(): Promise<string>;
|
|
1023
|
-
|
|
1041
|
+
_origBrowser(): AllBrowser;
|
|
1024
1042
|
}
|
|
1025
1043
|
|
|
1026
1044
|
declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
@@ -1036,7 +1054,7 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
|
|
|
1036
1054
|
page(pageIdx: number): LsdPage | null;
|
|
1037
1055
|
pages(): LsdPage[];
|
|
1038
1056
|
proxy(): ProxyInController | null;
|
|
1039
|
-
setStateData(stateData:
|
|
1057
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
1040
1058
|
_origBrowserContext(): AllBrowserContext;
|
|
1041
1059
|
}
|
|
1042
1060
|
|
|
@@ -1055,6 +1073,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
1055
1073
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
1056
1074
|
cookies(): Promise<CookieItem[]>;
|
|
1057
1075
|
documentHeight(): Promise<number>;
|
|
1076
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
1058
1077
|
findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
|
|
1059
1078
|
findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
|
|
1060
1079
|
free(): Promise<boolean>;
|
|
@@ -1079,10 +1098,10 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
1079
1098
|
setPageInfo(pageInfo: UpdatablePageInfo): boolean;
|
|
1080
1099
|
setRequestInterception(options: RequestInterceptionOption | RequestInterceptionOption[]): Promise<boolean>;
|
|
1081
1100
|
setResponseInterception(options: ResponseInterceptionOption | ResponseInterceptionOption[]): Promise<boolean>;
|
|
1082
|
-
setStateData(stateData:
|
|
1101
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
1083
1102
|
setUserAgent(userAgent: string): Promise<boolean>;
|
|
1084
1103
|
setViewportSize(viewPortSize: ViewportSize): Promise<boolean>;
|
|
1085
|
-
stateData(): Promise<
|
|
1104
|
+
stateData(): Promise<BrowserStateData>;
|
|
1086
1105
|
status(): PageStatus;
|
|
1087
1106
|
title(): Promise<string>;
|
|
1088
1107
|
url(): string;
|
|
@@ -1090,6 +1109,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
1090
1109
|
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
1091
1110
|
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
1092
1111
|
windowMember(keys: string[]): Promise<string>;
|
|
1112
|
+
_origPage(): AllPage;
|
|
1093
1113
|
}
|
|
1094
1114
|
|
|
1095
1115
|
declare class PlaywrightElement implements LsdElement {
|
|
@@ -1129,7 +1149,7 @@ declare class PuppeteerBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1129
1149
|
isHeadless(): boolean;
|
|
1130
1150
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
1131
1151
|
version(): Promise<string>;
|
|
1132
|
-
|
|
1152
|
+
_origBrowser(): AllBrowser;
|
|
1133
1153
|
}
|
|
1134
1154
|
|
|
1135
1155
|
declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
@@ -1145,7 +1165,7 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
|
|
|
1145
1165
|
page(pageIdx: number): LsdPage | null;
|
|
1146
1166
|
pages(): LsdPage[];
|
|
1147
1167
|
proxy(): ProxyInController | null;
|
|
1148
|
-
setStateData(stateData:
|
|
1168
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
1149
1169
|
_origBrowserContext(): AllBrowserContext;
|
|
1150
1170
|
}
|
|
1151
1171
|
|
|
@@ -1164,6 +1184,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1164
1184
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
1165
1185
|
cookies(): Promise<CookieItem[]>;
|
|
1166
1186
|
documentHeight(): Promise<number>;
|
|
1187
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
1167
1188
|
findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
|
|
1168
1189
|
findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
|
|
1169
1190
|
free(): Promise<boolean>;
|
|
@@ -1188,10 +1209,10 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1188
1209
|
setPageInfo(pageInfo: UpdatablePageInfo): boolean;
|
|
1189
1210
|
setRequestInterception(options: RequestInterceptionOption | RequestInterceptionOption[]): Promise<boolean>;
|
|
1190
1211
|
setResponseInterception(options: ResponseInterceptionOption | ResponseInterceptionOption[]): Promise<boolean>;
|
|
1191
|
-
setStateData(stateData:
|
|
1212
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
1192
1213
|
setUserAgent(userAgent: string): Promise<boolean>;
|
|
1193
1214
|
setViewportSize(viewPortSize: ViewportSize): Promise<boolean>;
|
|
1194
|
-
stateData(): Promise<
|
|
1215
|
+
stateData(): Promise<BrowserStateData>;
|
|
1195
1216
|
status(): PageStatus;
|
|
1196
1217
|
title(): Promise<string>;
|
|
1197
1218
|
url(): string;
|
|
@@ -1199,6 +1220,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1199
1220
|
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
1200
1221
|
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
1201
1222
|
windowMember(keys: string[]): Promise<string>;
|
|
1223
|
+
_origPage(): AllPage;
|
|
1202
1224
|
}
|
|
1203
1225
|
|
|
1204
1226
|
declare class PuppeteerElement implements LsdElement {
|
|
@@ -1231,6 +1253,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1231
1253
|
* @param isHtml default true
|
|
1232
1254
|
*/
|
|
1233
1255
|
constructor(html?: string, isHtml?: boolean);
|
|
1256
|
+
_origPage(): AllPage;
|
|
1234
1257
|
apiRequestContext(): APIRequestContext;
|
|
1235
1258
|
bringToFront(): Promise<boolean>;
|
|
1236
1259
|
browserContext(): LsdBrowserContext;
|
|
@@ -1242,6 +1265,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1242
1265
|
close(): Promise<boolean>;
|
|
1243
1266
|
content(): Promise<string>;
|
|
1244
1267
|
cookies(): Promise<CookieItem[]>;
|
|
1268
|
+
evalute(): Promise<any>;
|
|
1245
1269
|
findElement(selectorOrXpath: string | string[]): Promise<LsdElement | null>;
|
|
1246
1270
|
findElements(selectorOrXpath: string | string[]): Promise<LsdElement[]>;
|
|
1247
1271
|
free(): Promise<boolean>;
|
|
@@ -1269,7 +1293,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1269
1293
|
setStateData(): Promise<boolean>;
|
|
1270
1294
|
setUserAgent(): Promise<boolean>;
|
|
1271
1295
|
setViewportSize(): Promise<boolean>;
|
|
1272
|
-
stateData(): Promise<
|
|
1296
|
+
stateData(): Promise<BrowserStateData>;
|
|
1273
1297
|
status(): PageStatus;
|
|
1274
1298
|
title(): Promise<string>;
|
|
1275
1299
|
url(): string;
|
|
@@ -1312,4 +1336,4 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
|
1312
1336
|
}
|
|
1313
1337
|
declare const controller: LsdBrowserController;
|
|
1314
1338
|
|
|
1315
|
-
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
|
|
1339
|
+
export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, type BrowserStateData, 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 UpdatablePageInfo, type ViewportSize, type WaitElementOptions, type WaitElementState, type WaitNavigationOptions, controller };
|
package/dist/index.d.ts
CHANGED
|
@@ -419,7 +419,7 @@ interface LocalStorageOrigin {
|
|
|
419
419
|
origin: string;
|
|
420
420
|
localStorage: LocalStorageItem[];
|
|
421
421
|
}
|
|
422
|
-
interface
|
|
422
|
+
interface BrowserStateData {
|
|
423
423
|
cookies: CookieItem[];
|
|
424
424
|
localStorage: LocalStorageOrigin[];
|
|
425
425
|
}
|
|
@@ -771,7 +771,15 @@ interface LsdPage extends EventEmitter {
|
|
|
771
771
|
apiRequestContext(): AllApiRequestContext;
|
|
772
772
|
bringToFront(): Promise<boolean>;
|
|
773
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
|
+
*/
|
|
774
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
|
+
*/
|
|
775
783
|
clearLocalStorage(): Promise<boolean>;
|
|
776
784
|
/**
|
|
777
785
|
* Clear all request interceptions on the page
|
|
@@ -781,6 +789,11 @@ interface LsdPage extends EventEmitter {
|
|
|
781
789
|
* Clear all response interceptions on the page
|
|
782
790
|
*/
|
|
783
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
|
+
*/
|
|
784
797
|
clearStateData(): Promise<boolean>;
|
|
785
798
|
/**
|
|
786
799
|
* Only free page can be closed!
|
|
@@ -792,6 +805,7 @@ interface LsdPage extends EventEmitter {
|
|
|
792
805
|
*/
|
|
793
806
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
794
807
|
cookies(): Promise<CookieItem[]>;
|
|
808
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
795
809
|
/**
|
|
796
810
|
* @returns the first element matching the given CSS selector or XPath
|
|
797
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
|
|
@@ -861,14 +875,14 @@ interface LsdPage extends EventEmitter {
|
|
|
861
875
|
* Shortcut for LsdPage.browserContext().setStateData(stateData)
|
|
862
876
|
* @param stateData
|
|
863
877
|
*/
|
|
864
|
-
setStateData(stateData:
|
|
878
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
865
879
|
/**
|
|
866
880
|
* valid only in puppeteer
|
|
867
881
|
* @param userAgent
|
|
868
882
|
*/
|
|
869
883
|
setUserAgent(userAgent: string): Promise<boolean>;
|
|
870
884
|
setViewportSize(viewPortSize: ViewportSize): Promise<boolean>;
|
|
871
|
-
stateData(): Promise<
|
|
885
|
+
stateData(): Promise<BrowserStateData>;
|
|
872
886
|
status(): PageStatus;
|
|
873
887
|
title(): Promise<string>;
|
|
874
888
|
url(): string;
|
|
@@ -893,6 +907,7 @@ interface LsdPage extends EventEmitter {
|
|
|
893
907
|
* @param keys
|
|
894
908
|
*/
|
|
895
909
|
windowMember(keys: string[]): Promise<string>;
|
|
910
|
+
_origPage(): AllPage;
|
|
896
911
|
}
|
|
897
912
|
interface LsdBrowserContext extends EventEmitter {
|
|
898
913
|
browser(): LsdBrowser;
|
|
@@ -918,7 +933,7 @@ interface LsdBrowserContext extends EventEmitter {
|
|
|
918
933
|
page(pageIdx: number): LsdPage | null;
|
|
919
934
|
pages(): LsdPage[];
|
|
920
935
|
proxy(): ProxyInController | null;
|
|
921
|
-
setStateData(stateData:
|
|
936
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
922
937
|
_origBrowserContext(): AllBrowserContext;
|
|
923
938
|
}
|
|
924
939
|
interface LsdBrowser extends EventEmitter {
|
|
@@ -940,12 +955,15 @@ interface LsdBrowser extends EventEmitter {
|
|
|
940
955
|
* 2. connected: exectuablePath in LsdConnectOptions, default ""(unkown)
|
|
941
956
|
*/
|
|
942
957
|
executablePath(): string;
|
|
958
|
+
/**
|
|
959
|
+
* get a free BrowserContext from current free browserContexts or new browserContext
|
|
960
|
+
*/
|
|
943
961
|
id(): string;
|
|
944
962
|
isConnected(): boolean;
|
|
945
963
|
isHeadless(): boolean;
|
|
946
964
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
947
965
|
version(): Promise<string>;
|
|
948
|
-
|
|
966
|
+
_origBrowser(): AllBrowser;
|
|
949
967
|
}
|
|
950
968
|
interface LsdBrowserController$1 {
|
|
951
969
|
/**
|
|
@@ -1020,7 +1038,7 @@ declare class PlaywrightBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1020
1038
|
isHeadless(): boolean;
|
|
1021
1039
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
1022
1040
|
version(): Promise<string>;
|
|
1023
|
-
|
|
1041
|
+
_origBrowser(): AllBrowser;
|
|
1024
1042
|
}
|
|
1025
1043
|
|
|
1026
1044
|
declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
@@ -1036,7 +1054,7 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
|
|
|
1036
1054
|
page(pageIdx: number): LsdPage | null;
|
|
1037
1055
|
pages(): LsdPage[];
|
|
1038
1056
|
proxy(): ProxyInController | null;
|
|
1039
|
-
setStateData(stateData:
|
|
1057
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
1040
1058
|
_origBrowserContext(): AllBrowserContext;
|
|
1041
1059
|
}
|
|
1042
1060
|
|
|
@@ -1055,6 +1073,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
1055
1073
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
1056
1074
|
cookies(): Promise<CookieItem[]>;
|
|
1057
1075
|
documentHeight(): Promise<number>;
|
|
1076
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
1058
1077
|
findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
|
|
1059
1078
|
findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
|
|
1060
1079
|
free(): Promise<boolean>;
|
|
@@ -1079,10 +1098,10 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
1079
1098
|
setPageInfo(pageInfo: UpdatablePageInfo): boolean;
|
|
1080
1099
|
setRequestInterception(options: RequestInterceptionOption | RequestInterceptionOption[]): Promise<boolean>;
|
|
1081
1100
|
setResponseInterception(options: ResponseInterceptionOption | ResponseInterceptionOption[]): Promise<boolean>;
|
|
1082
|
-
setStateData(stateData:
|
|
1101
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
1083
1102
|
setUserAgent(userAgent: string): Promise<boolean>;
|
|
1084
1103
|
setViewportSize(viewPortSize: ViewportSize): Promise<boolean>;
|
|
1085
|
-
stateData(): Promise<
|
|
1104
|
+
stateData(): Promise<BrowserStateData>;
|
|
1086
1105
|
status(): PageStatus;
|
|
1087
1106
|
title(): Promise<string>;
|
|
1088
1107
|
url(): string;
|
|
@@ -1090,6 +1109,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
1090
1109
|
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
1091
1110
|
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
1092
1111
|
windowMember(keys: string[]): Promise<string>;
|
|
1112
|
+
_origPage(): AllPage;
|
|
1093
1113
|
}
|
|
1094
1114
|
|
|
1095
1115
|
declare class PlaywrightElement implements LsdElement {
|
|
@@ -1129,7 +1149,7 @@ declare class PuppeteerBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1129
1149
|
isHeadless(): boolean;
|
|
1130
1150
|
options(): LsdLaunchOptions | LsdConnectOptions;
|
|
1131
1151
|
version(): Promise<string>;
|
|
1132
|
-
|
|
1152
|
+
_origBrowser(): AllBrowser;
|
|
1133
1153
|
}
|
|
1134
1154
|
|
|
1135
1155
|
declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
@@ -1145,7 +1165,7 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
|
|
|
1145
1165
|
page(pageIdx: number): LsdPage | null;
|
|
1146
1166
|
pages(): LsdPage[];
|
|
1147
1167
|
proxy(): ProxyInController | null;
|
|
1148
|
-
setStateData(stateData:
|
|
1168
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
1149
1169
|
_origBrowserContext(): AllBrowserContext;
|
|
1150
1170
|
}
|
|
1151
1171
|
|
|
@@ -1164,6 +1184,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1164
1184
|
content(iframeOptions?: IframeOption[]): Promise<string>;
|
|
1165
1185
|
cookies(): Promise<CookieItem[]>;
|
|
1166
1186
|
documentHeight(): Promise<number>;
|
|
1187
|
+
evalute(fun: Function, args?: any[]): Promise<any>;
|
|
1167
1188
|
findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
|
|
1168
1189
|
findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
|
|
1169
1190
|
free(): Promise<boolean>;
|
|
@@ -1188,10 +1209,10 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1188
1209
|
setPageInfo(pageInfo: UpdatablePageInfo): boolean;
|
|
1189
1210
|
setRequestInterception(options: RequestInterceptionOption | RequestInterceptionOption[]): Promise<boolean>;
|
|
1190
1211
|
setResponseInterception(options: ResponseInterceptionOption | ResponseInterceptionOption[]): Promise<boolean>;
|
|
1191
|
-
setStateData(stateData:
|
|
1212
|
+
setStateData(stateData: BrowserStateData): Promise<boolean>;
|
|
1192
1213
|
setUserAgent(userAgent: string): Promise<boolean>;
|
|
1193
1214
|
setViewportSize(viewPortSize: ViewportSize): Promise<boolean>;
|
|
1194
|
-
stateData(): Promise<
|
|
1215
|
+
stateData(): Promise<BrowserStateData>;
|
|
1195
1216
|
status(): PageStatus;
|
|
1196
1217
|
title(): Promise<string>;
|
|
1197
1218
|
url(): string;
|
|
@@ -1199,6 +1220,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1199
1220
|
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
1200
1221
|
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
1201
1222
|
windowMember(keys: string[]): Promise<string>;
|
|
1223
|
+
_origPage(): AllPage;
|
|
1202
1224
|
}
|
|
1203
1225
|
|
|
1204
1226
|
declare class PuppeteerElement implements LsdElement {
|
|
@@ -1231,6 +1253,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1231
1253
|
* @param isHtml default true
|
|
1232
1254
|
*/
|
|
1233
1255
|
constructor(html?: string, isHtml?: boolean);
|
|
1256
|
+
_origPage(): AllPage;
|
|
1234
1257
|
apiRequestContext(): APIRequestContext;
|
|
1235
1258
|
bringToFront(): Promise<boolean>;
|
|
1236
1259
|
browserContext(): LsdBrowserContext;
|
|
@@ -1242,6 +1265,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1242
1265
|
close(): Promise<boolean>;
|
|
1243
1266
|
content(): Promise<string>;
|
|
1244
1267
|
cookies(): Promise<CookieItem[]>;
|
|
1268
|
+
evalute(): Promise<any>;
|
|
1245
1269
|
findElement(selectorOrXpath: string | string[]): Promise<LsdElement | null>;
|
|
1246
1270
|
findElements(selectorOrXpath: string | string[]): Promise<LsdElement[]>;
|
|
1247
1271
|
free(): Promise<boolean>;
|
|
@@ -1269,7 +1293,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1269
1293
|
setStateData(): Promise<boolean>;
|
|
1270
1294
|
setUserAgent(): Promise<boolean>;
|
|
1271
1295
|
setViewportSize(): Promise<boolean>;
|
|
1272
|
-
stateData(): Promise<
|
|
1296
|
+
stateData(): Promise<BrowserStateData>;
|
|
1273
1297
|
status(): PageStatus;
|
|
1274
1298
|
title(): Promise<string>;
|
|
1275
1299
|
url(): string;
|
|
@@ -1312,4 +1336,4 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
|
1312
1336
|
}
|
|
1313
1337
|
declare const controller: LsdBrowserController;
|
|
1314
1338
|
|
|
1315
|
-
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
|
|
1339
|
+
export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, type BrowserStateData, 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 UpdatablePageInfo, type ViewportSize, type WaitElementOptions, type WaitElementState, type WaitNavigationOptions, controller };
|
package/dist/index.js
CHANGED
|
@@ -558,7 +558,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
558
558
|
const currentTime = getCurrentUnixTime();
|
|
559
559
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
560
560
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
561
|
-
this.#pageId = `page
|
|
561
|
+
this.#pageId = `page-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
562
562
|
this.#resquestInterceptionOptions = [];
|
|
563
563
|
this.#responseInterceptionOptions = [];
|
|
564
564
|
this.#client = null;
|
|
@@ -667,6 +667,12 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
667
667
|
const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
|
|
668
668
|
return height;
|
|
669
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
|
+
}
|
|
670
676
|
async findElement(selectorOrXpath, iframeOptions = []) {
|
|
671
677
|
if (!this.#page) {
|
|
672
678
|
throw new Error("No valid page");
|
|
@@ -1156,6 +1162,9 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
1156
1162
|
);
|
|
1157
1163
|
return content;
|
|
1158
1164
|
}
|
|
1165
|
+
_origPage() {
|
|
1166
|
+
return this.#page;
|
|
1167
|
+
}
|
|
1159
1168
|
};
|
|
1160
1169
|
|
|
1161
1170
|
// src/playwright/context.ts
|
|
@@ -1225,7 +1234,7 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1225
1234
|
await lsdPage.maximizeViewport();
|
|
1226
1235
|
}
|
|
1227
1236
|
this.#lsdPages.push(lsdPage);
|
|
1228
|
-
loginfo3(`##
|
|
1237
|
+
loginfo3(`##page ${lsdPage.id()} created`);
|
|
1229
1238
|
}
|
|
1230
1239
|
});
|
|
1231
1240
|
browserContext.on("close", (bc) => {
|
|
@@ -1377,12 +1386,16 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1377
1386
|
throw new Error("No valid browserContext");
|
|
1378
1387
|
}
|
|
1379
1388
|
const { cookies, localStorage: localStorageOrigins } = stateData;
|
|
1380
|
-
const page = await this
|
|
1389
|
+
const page = await this.getPage();
|
|
1390
|
+
if (!page) {
|
|
1391
|
+
return false;
|
|
1392
|
+
}
|
|
1393
|
+
const origPage = page._origPage();
|
|
1381
1394
|
if (cookies.length > 0) {
|
|
1382
1395
|
await this.#browserContext.addCookies(cookies);
|
|
1383
1396
|
}
|
|
1384
1397
|
if (localStorageOrigins.length > 0) {
|
|
1385
|
-
await
|
|
1398
|
+
await origPage.route("**/*", async (route) => {
|
|
1386
1399
|
const request = route.request();
|
|
1387
1400
|
await route.fulfill({
|
|
1388
1401
|
status: 200,
|
|
@@ -1392,15 +1405,16 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1392
1405
|
});
|
|
1393
1406
|
for (const localStorageOrigin of localStorageOrigins) {
|
|
1394
1407
|
const { origin, localStorage } = localStorageOrigin;
|
|
1395
|
-
await
|
|
1396
|
-
await
|
|
1408
|
+
await origPage.goto(origin);
|
|
1409
|
+
await origPage.evaluate((localStorageItems) => {
|
|
1397
1410
|
for (const item of localStorageItems) {
|
|
1398
1411
|
window.localStorage.setItem(item.name, item.value);
|
|
1399
1412
|
}
|
|
1400
1413
|
}, localStorage);
|
|
1401
1414
|
}
|
|
1402
1415
|
}
|
|
1403
|
-
await
|
|
1416
|
+
await origPage.unrouteAll();
|
|
1417
|
+
await page.free();
|
|
1404
1418
|
return true;
|
|
1405
1419
|
}
|
|
1406
1420
|
_origBrowserContext() {
|
|
@@ -1455,7 +1469,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1455
1469
|
this.#executablePath = executablePath;
|
|
1456
1470
|
this.#nextBrowserContextIdx = 1;
|
|
1457
1471
|
this.#closeFreePagesIntervalId = null;
|
|
1458
|
-
loginfo4(`##browser
|
|
1472
|
+
loginfo4(`##browser ${this.id()} ${this.#browserCreationMethod}ed by ${this.#browserControllerType}`);
|
|
1459
1473
|
const browserContexts = browser.contexts();
|
|
1460
1474
|
if (browserContexts.length > 0) {
|
|
1461
1475
|
logwarn3(`There are ${browserContexts.length} new browserContexts when playwright launches new browser`);
|
|
@@ -1464,7 +1478,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1464
1478
|
for (const browserContext of browserContexts) {
|
|
1465
1479
|
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, incognito, this.#proxy, this.#browserIdx++, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
1466
1480
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
1467
|
-
loginfo4(`##
|
|
1481
|
+
loginfo4(`##browserContext ${lsdBrowserContext.id()} ${this.#browserCreationMethod}ed`);
|
|
1468
1482
|
}
|
|
1469
1483
|
browser.on("disconnected", () => {
|
|
1470
1484
|
loginfo4(`##browser ${this.id()} disconnected`);
|
|
@@ -1482,7 +1496,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1482
1496
|
logerr3(`Invalid lsdBrowserContext in LsdBrowser.on("browserContextClose)`);
|
|
1483
1497
|
return;
|
|
1484
1498
|
}
|
|
1485
|
-
loginfo4(`##
|
|
1499
|
+
loginfo4(`##browserContext ${lsdBrowserContext.id()} closed
|
|
1486
1500
|
`);
|
|
1487
1501
|
this.#lsdBrowserContexts.splice(idx, 1);
|
|
1488
1502
|
if (this.#lsdBrowserContexts.length === 0) {
|
|
@@ -1553,7 +1567,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1553
1567
|
return this.#executablePath;
|
|
1554
1568
|
}
|
|
1555
1569
|
id() {
|
|
1556
|
-
return `browser-${this.#browserIdx}`;
|
|
1570
|
+
return `browser-${this.#browserType}-${this.#browserIdx}`;
|
|
1557
1571
|
}
|
|
1558
1572
|
isConnected() {
|
|
1559
1573
|
return this.#browser.isConnected();
|
|
@@ -1568,8 +1582,8 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1568
1582
|
const version = await this.#browser.version();
|
|
1569
1583
|
return version;
|
|
1570
1584
|
}
|
|
1571
|
-
|
|
1572
|
-
return this.#browser
|
|
1585
|
+
_origBrowser() {
|
|
1586
|
+
return this.#browser;
|
|
1573
1587
|
}
|
|
1574
1588
|
};
|
|
1575
1589
|
|
|
@@ -2048,7 +2062,7 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2048
2062
|
const currentTime = getCurrentUnixTime3();
|
|
2049
2063
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
2050
2064
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
2051
|
-
this.#pageId = `page
|
|
2065
|
+
this.#pageId = `page-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
2052
2066
|
this.#requestInterceptionNum = 0;
|
|
2053
2067
|
this.#responseInterceptionNum = 0;
|
|
2054
2068
|
this.#client = null;
|
|
@@ -2151,6 +2165,12 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2151
2165
|
const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
|
|
2152
2166
|
return height;
|
|
2153
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
|
+
}
|
|
2154
2174
|
async findElement(selectorOrXpath, iframeOptions = []) {
|
|
2155
2175
|
if (!this.#page) {
|
|
2156
2176
|
throw new Error("No valid page");
|
|
@@ -2631,6 +2651,9 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2631
2651
|
);
|
|
2632
2652
|
return content;
|
|
2633
2653
|
}
|
|
2654
|
+
_origPage() {
|
|
2655
|
+
return this.#page;
|
|
2656
|
+
}
|
|
2634
2657
|
};
|
|
2635
2658
|
|
|
2636
2659
|
// src/puppeteer/context.ts
|
|
@@ -2718,7 +2741,7 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
2718
2741
|
await lsdPage.setUserAgent(this.#userAgent);
|
|
2719
2742
|
}
|
|
2720
2743
|
this.#lsdPages.push(lsdPage);
|
|
2721
|
-
loginfo6(`##
|
|
2744
|
+
loginfo6(`##page ${lsdPage.id()} created`);
|
|
2722
2745
|
}
|
|
2723
2746
|
}
|
|
2724
2747
|
});
|
|
@@ -2870,13 +2893,17 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
2870
2893
|
throw new Error("No valid browserContext");
|
|
2871
2894
|
}
|
|
2872
2895
|
const { cookies, localStorage: localStorageOrigins } = stateData;
|
|
2873
|
-
const page = await this
|
|
2896
|
+
const page = await this.getPage();
|
|
2897
|
+
if (!page) {
|
|
2898
|
+
return false;
|
|
2899
|
+
}
|
|
2900
|
+
const origPage = page._origPage();
|
|
2874
2901
|
if (cookies.length > 0) {
|
|
2875
|
-
await
|
|
2902
|
+
await origPage.setCookie(...cookies);
|
|
2876
2903
|
}
|
|
2877
2904
|
if (localStorageOrigins.length > 0) {
|
|
2878
|
-
await
|
|
2879
|
-
|
|
2905
|
+
await origPage.setRequestInterception(true);
|
|
2906
|
+
origPage.on("request", (request) => {
|
|
2880
2907
|
request.respond({
|
|
2881
2908
|
status: 200,
|
|
2882
2909
|
// contentType: "text/html; charset=utf-8", // "text/plain",
|
|
@@ -2885,15 +2912,16 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
2885
2912
|
});
|
|
2886
2913
|
for (const localStorageOrigin of localStorageOrigins) {
|
|
2887
2914
|
const { origin, localStorage } = localStorageOrigin;
|
|
2888
|
-
await
|
|
2889
|
-
await
|
|
2915
|
+
await origPage.goto(origin);
|
|
2916
|
+
await origPage.evaluate((localStorageItems) => {
|
|
2890
2917
|
for (const item of localStorageItems) {
|
|
2891
2918
|
window.localStorage.setItem(item.name, item.value);
|
|
2892
2919
|
}
|
|
2893
2920
|
}, localStorage);
|
|
2894
2921
|
}
|
|
2895
2922
|
}
|
|
2896
|
-
await
|
|
2923
|
+
await origPage.setRequestInterception(false);
|
|
2924
|
+
await page.free();
|
|
2897
2925
|
return true;
|
|
2898
2926
|
}
|
|
2899
2927
|
_origBrowserContext() {
|
|
@@ -3057,8 +3085,8 @@ var PuppeteerBrowser = class extends EventEmitter6 {
|
|
|
3057
3085
|
const version = await this.#browser.version();
|
|
3058
3086
|
return version;
|
|
3059
3087
|
}
|
|
3060
|
-
|
|
3061
|
-
return this.#browser
|
|
3088
|
+
_origBrowser() {
|
|
3089
|
+
return this.#browser;
|
|
3062
3090
|
}
|
|
3063
3091
|
};
|
|
3064
3092
|
|
|
@@ -17046,6 +17074,9 @@ var CheerioPage = class extends EventEmitter7 {
|
|
|
17046
17074
|
this.#document = load(html3, { xml: true }).root();
|
|
17047
17075
|
}
|
|
17048
17076
|
}
|
|
17077
|
+
_origPage() {
|
|
17078
|
+
throw new Error("Method not implemented.");
|
|
17079
|
+
}
|
|
17049
17080
|
apiRequestContext() {
|
|
17050
17081
|
throw new Error("Not supported in CheerioPage.");
|
|
17051
17082
|
}
|
|
@@ -17079,6 +17110,9 @@ var CheerioPage = class extends EventEmitter7 {
|
|
|
17079
17110
|
async cookies() {
|
|
17080
17111
|
throw new Error("Not supported in CheerioPage.");
|
|
17081
17112
|
}
|
|
17113
|
+
async evalute() {
|
|
17114
|
+
throw new Error("Not supported in CheerioPage.");
|
|
17115
|
+
}
|
|
17082
17116
|
#findNodes(selector) {
|
|
17083
17117
|
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
17084
17118
|
throw new Error("Do not support XPath in cheerio.");
|
package/package.json
CHANGED