@letsscrapedata/controller 0.0.2 → 0.0.3
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 +77 -6
- package/dist/index.d.cts +49 -6
- package/dist/index.d.ts +49 -6
- package/dist/index.js +77 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -667,12 +667,19 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
667
667
|
await this.clearResponseInterceptions();
|
|
668
668
|
return true;
|
|
669
669
|
}
|
|
670
|
+
#getWaitUntil(origWaitUntil) {
|
|
671
|
+
if (origWaitUntil === "networkidle0" || origWaitUntil === "networkidle2") {
|
|
672
|
+
return "networkidle";
|
|
673
|
+
} else {
|
|
674
|
+
return origWaitUntil;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
670
677
|
async goto(url, options) {
|
|
671
678
|
if (!this.#page) {
|
|
672
679
|
throw new Error("No valid page");
|
|
673
680
|
}
|
|
674
681
|
if (options) {
|
|
675
|
-
const { referer, timeout, waitUntil } = options;
|
|
682
|
+
const { referer, timeout, waitUntil = "load" } = options;
|
|
676
683
|
const newOptions = {};
|
|
677
684
|
if (referer) {
|
|
678
685
|
newOptions.referer = referer;
|
|
@@ -680,9 +687,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
680
687
|
if (timeout) {
|
|
681
688
|
newOptions.timeout = timeout;
|
|
682
689
|
}
|
|
683
|
-
|
|
684
|
-
newOptions.waitUntil = waitUntil === "networkidle" ? "networkidle0" : waitUntil;
|
|
685
|
-
}
|
|
690
|
+
newOptions.waitUntil = this.#getWaitUntil(waitUntil);
|
|
686
691
|
await this.#page.goto(url, newOptions);
|
|
687
692
|
} else {
|
|
688
693
|
await this.#page.goto(url);
|
|
@@ -1015,6 +1020,30 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
1015
1020
|
this.#status = "busy";
|
|
1016
1021
|
return true;
|
|
1017
1022
|
}
|
|
1023
|
+
async waitForElement(selector, options = {}) {
|
|
1024
|
+
if (!this.#page) {
|
|
1025
|
+
throw new Error("No valid page");
|
|
1026
|
+
}
|
|
1027
|
+
const locator = this.#page.locator(selector);
|
|
1028
|
+
const { timeout = 3e4, state = "visible" } = options;
|
|
1029
|
+
await locator.waitFor({ state, timeout });
|
|
1030
|
+
return true;
|
|
1031
|
+
}
|
|
1032
|
+
async waitForNavigation(options) {
|
|
1033
|
+
if (!this.#page) {
|
|
1034
|
+
throw new Error("No valid page");
|
|
1035
|
+
}
|
|
1036
|
+
const { url = "", timeout = 3e4, waitUntil = "load" } = options;
|
|
1037
|
+
const newWaitUntil = this.#getWaitUntil(waitUntil);
|
|
1038
|
+
if (url) {
|
|
1039
|
+
await this.#page.waitForURL(url, { timeout, waitUntil: newWaitUntil });
|
|
1040
|
+
} else if (newWaitUntil === "commit") {
|
|
1041
|
+
throw new Error("commit is not supported in PlaywrightPage.waitForNavigation");
|
|
1042
|
+
} else {
|
|
1043
|
+
await this.#page.waitForLoadState(newWaitUntil, { timeout });
|
|
1044
|
+
}
|
|
1045
|
+
return true;
|
|
1046
|
+
}
|
|
1018
1047
|
async windowMember(keys) {
|
|
1019
1048
|
if (!this.#page) {
|
|
1020
1049
|
throw new Error("No valid page");
|
|
@@ -2042,12 +2071,21 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2042
2071
|
await this.clearResponseInterceptions();
|
|
2043
2072
|
return true;
|
|
2044
2073
|
}
|
|
2074
|
+
#getWaitUntil(origWaitUntil) {
|
|
2075
|
+
if (origWaitUntil === "networkidle") {
|
|
2076
|
+
return "networkidle0";
|
|
2077
|
+
} else if (origWaitUntil === "commit") {
|
|
2078
|
+
throw new Error("commit is not supported in PuppeteerPage");
|
|
2079
|
+
} else {
|
|
2080
|
+
return origWaitUntil;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2045
2083
|
async goto(url, options) {
|
|
2046
2084
|
if (!this.#page) {
|
|
2047
2085
|
throw new Error("No valid page");
|
|
2048
2086
|
}
|
|
2049
2087
|
if (options) {
|
|
2050
|
-
const { referer, timeout, waitUntil } = options;
|
|
2088
|
+
const { referer, timeout, waitUntil = "load" } = options;
|
|
2051
2089
|
const newOptions = {};
|
|
2052
2090
|
if (referer) {
|
|
2053
2091
|
newOptions.referer = referer;
|
|
@@ -2056,7 +2094,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2056
2094
|
newOptions.timeout = timeout;
|
|
2057
2095
|
}
|
|
2058
2096
|
if (waitUntil && waitUntil !== "commit") {
|
|
2059
|
-
newOptions.waitUntil = waitUntil
|
|
2097
|
+
newOptions.waitUntil = this.#getWaitUntil(waitUntil);
|
|
2060
2098
|
}
|
|
2061
2099
|
await this.#page.goto(url, newOptions);
|
|
2062
2100
|
} else {
|
|
@@ -2370,6 +2408,33 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2370
2408
|
this.#status = "busy";
|
|
2371
2409
|
return true;
|
|
2372
2410
|
}
|
|
2411
|
+
async waitForElement(selector, options = {}) {
|
|
2412
|
+
if (!this.#page) {
|
|
2413
|
+
throw new Error("No valid page");
|
|
2414
|
+
}
|
|
2415
|
+
const { timeout = 3e4, state = "visible" } = options;
|
|
2416
|
+
if (state === "visible") {
|
|
2417
|
+
await this.#page.waitForSelector(selector, { timeout, visible: true });
|
|
2418
|
+
} else if (state === "hidden") {
|
|
2419
|
+
await this.#page.waitForSelector(selector, { timeout, hidden: true });
|
|
2420
|
+
} else {
|
|
2421
|
+
throw new Error(`${state} is not supported in PuppeteerPage.waitForElement`);
|
|
2422
|
+
}
|
|
2423
|
+
return true;
|
|
2424
|
+
}
|
|
2425
|
+
async waitForNavigation(options) {
|
|
2426
|
+
if (!this.#page) {
|
|
2427
|
+
throw new Error("No valid page");
|
|
2428
|
+
}
|
|
2429
|
+
const { url = "", timeout = 3e4, waitUntil = "load" } = options;
|
|
2430
|
+
const newWaitUntil = this.#getWaitUntil(waitUntil);
|
|
2431
|
+
if (url) {
|
|
2432
|
+
throw new Error("url is not supported in PuppeteerPage.waitForNavigation");
|
|
2433
|
+
} else {
|
|
2434
|
+
await this.#page.waitForNavigation({ timeout, waitUntil: newWaitUntil });
|
|
2435
|
+
}
|
|
2436
|
+
return true;
|
|
2437
|
+
}
|
|
2373
2438
|
async windowMember(keys) {
|
|
2374
2439
|
if (!this.#page) {
|
|
2375
2440
|
throw new Error("No valid page");
|
|
@@ -16946,6 +17011,12 @@ var CheerioPage = class extends import_node_events7.default {
|
|
|
16946
17011
|
use() {
|
|
16947
17012
|
throw new Error("Not supported in CheerioPage.");
|
|
16948
17013
|
}
|
|
17014
|
+
waitForElement() {
|
|
17015
|
+
throw new Error("Not supported in CheerioPage.");
|
|
17016
|
+
}
|
|
17017
|
+
waitForNavigation() {
|
|
17018
|
+
throw new Error("Not supported in CheerioPage.");
|
|
17019
|
+
}
|
|
16949
17020
|
async windowMember() {
|
|
16950
17021
|
throw new Error("Not supported in CheerioPage.");
|
|
16951
17022
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -243,14 +243,15 @@ interface SelectOptions {
|
|
|
243
243
|
*/
|
|
244
244
|
labels?: string[];
|
|
245
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* * playwright: "load" | "domcontentloaded" | "networkidle" | "commit", "networkidle0" | "networkidle2" => "networkidle";
|
|
248
|
+
* * puppeteer: "load" | "domcontentloaded" | "networkidle0" | "networkidle2", "networkidle" => "networkidle0", "commit" ignored;
|
|
249
|
+
*/
|
|
250
|
+
type NavigationWaitUntil = "load" | "domcontentloaded" | "networkidle" | "commit" | "networkidle0" | "networkidle2";
|
|
246
251
|
interface GotoOptions {
|
|
247
252
|
referer?: string;
|
|
248
253
|
timeout?: number;
|
|
249
|
-
|
|
250
|
-
* playwright: "load" | "domcontentloaded" | "networkidle" | "commit", "networkidle0" | "networkidle2" => "networkidle";
|
|
251
|
-
* puppeteer: "load" | "domcontentloaded" | "networkidle0" | "networkidle2", "networkidle" => "networkidle0", "commit" ignored;
|
|
252
|
-
*/
|
|
253
|
-
waitUntil?: "load" | "domcontentloaded" | "networkidle" | "commit" | "networkidle0" | "networkidle2";
|
|
254
|
+
waitUntil?: NavigationWaitUntil;
|
|
254
255
|
}
|
|
255
256
|
/**
|
|
256
257
|
* * src takes precedence over selector, at least one of them must be defined
|
|
@@ -684,6 +685,31 @@ interface ScreenshotOptions {
|
|
|
684
685
|
*/
|
|
685
686
|
type?: 'png' | 'jpeg';
|
|
686
687
|
}
|
|
688
|
+
interface WaitElementOptions {
|
|
689
|
+
/**
|
|
690
|
+
* @default 30_000 ms
|
|
691
|
+
*/
|
|
692
|
+
timeout?: number;
|
|
693
|
+
/**
|
|
694
|
+
* @default "visible"
|
|
695
|
+
*/
|
|
696
|
+
state?: "attached" | "detached" | "hidden" | "visible";
|
|
697
|
+
}
|
|
698
|
+
interface WaitNavigationOptions {
|
|
699
|
+
/**
|
|
700
|
+
* only supported in playwright by now
|
|
701
|
+
* @default ""
|
|
702
|
+
*/
|
|
703
|
+
url?: string | RegExp;
|
|
704
|
+
/**
|
|
705
|
+
* @default 30_000 ms
|
|
706
|
+
*/
|
|
707
|
+
timeout?: number;
|
|
708
|
+
/**
|
|
709
|
+
* @default "visible"
|
|
710
|
+
*/
|
|
711
|
+
waitUntil?: NavigationWaitUntil;
|
|
712
|
+
}
|
|
687
713
|
interface LsdPage extends EventEmitter {
|
|
688
714
|
bringToFront(): Promise<boolean>;
|
|
689
715
|
browserContext(): LsdBrowserContext;
|
|
@@ -778,6 +804,17 @@ interface LsdPage extends EventEmitter {
|
|
|
778
804
|
* 开始使用该page(当前状态必须为free)
|
|
779
805
|
*/
|
|
780
806
|
use(): boolean;
|
|
807
|
+
/**
|
|
808
|
+
*
|
|
809
|
+
* @param selector CSS selector, not XPath
|
|
810
|
+
* @param options
|
|
811
|
+
*/
|
|
812
|
+
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
813
|
+
/**
|
|
814
|
+
*
|
|
815
|
+
* @param options
|
|
816
|
+
*/
|
|
817
|
+
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
781
818
|
/**
|
|
782
819
|
* obj=window?.[key1]...?.[keyn]
|
|
783
820
|
* @return obj ? JSON.stringify(obj) : ""
|
|
@@ -937,6 +974,8 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
937
974
|
title(): Promise<string>;
|
|
938
975
|
url(): string;
|
|
939
976
|
use(): boolean;
|
|
977
|
+
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
978
|
+
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
940
979
|
windowMember(keys: string[]): Promise<string>;
|
|
941
980
|
}
|
|
942
981
|
|
|
@@ -1041,6 +1080,8 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1041
1080
|
title(): Promise<string>;
|
|
1042
1081
|
url(): string;
|
|
1043
1082
|
use(): boolean;
|
|
1083
|
+
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
1084
|
+
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
1044
1085
|
windowMember(keys: string[]): Promise<string>;
|
|
1045
1086
|
}
|
|
1046
1087
|
|
|
@@ -1110,6 +1151,8 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1110
1151
|
title(): Promise<string>;
|
|
1111
1152
|
url(): string;
|
|
1112
1153
|
use(): boolean;
|
|
1154
|
+
waitForElement(): Promise<boolean>;
|
|
1155
|
+
waitForNavigation(): Promise<boolean>;
|
|
1113
1156
|
windowMember(): Promise<string>;
|
|
1114
1157
|
}
|
|
1115
1158
|
|
|
@@ -1135,4 +1178,4 @@ declare class CheerioElement implements LsdElement {
|
|
|
1135
1178
|
scrollIntoView(): Promise<boolean>;
|
|
1136
1179
|
}
|
|
1137
1180
|
|
|
1138
|
-
export { 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, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type PDFMargin, type PDFOptions, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, PlaywrightElement, PlaywrightPage, type Proxy, 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 ScreenshotOptions, type SelectOptions, type StateData, type ViewportSize, defaultProxy };
|
|
1181
|
+
export { 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, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, PlaywrightElement, PlaywrightPage, type Proxy, 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 ScreenshotOptions, type SelectOptions, type StateData, type ViewportSize, type WaitElementOptions, type WaitNavigationOptions, defaultProxy };
|
package/dist/index.d.ts
CHANGED
|
@@ -243,14 +243,15 @@ interface SelectOptions {
|
|
|
243
243
|
*/
|
|
244
244
|
labels?: string[];
|
|
245
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* * playwright: "load" | "domcontentloaded" | "networkidle" | "commit", "networkidle0" | "networkidle2" => "networkidle";
|
|
248
|
+
* * puppeteer: "load" | "domcontentloaded" | "networkidle0" | "networkidle2", "networkidle" => "networkidle0", "commit" ignored;
|
|
249
|
+
*/
|
|
250
|
+
type NavigationWaitUntil = "load" | "domcontentloaded" | "networkidle" | "commit" | "networkidle0" | "networkidle2";
|
|
246
251
|
interface GotoOptions {
|
|
247
252
|
referer?: string;
|
|
248
253
|
timeout?: number;
|
|
249
|
-
|
|
250
|
-
* playwright: "load" | "domcontentloaded" | "networkidle" | "commit", "networkidle0" | "networkidle2" => "networkidle";
|
|
251
|
-
* puppeteer: "load" | "domcontentloaded" | "networkidle0" | "networkidle2", "networkidle" => "networkidle0", "commit" ignored;
|
|
252
|
-
*/
|
|
253
|
-
waitUntil?: "load" | "domcontentloaded" | "networkidle" | "commit" | "networkidle0" | "networkidle2";
|
|
254
|
+
waitUntil?: NavigationWaitUntil;
|
|
254
255
|
}
|
|
255
256
|
/**
|
|
256
257
|
* * src takes precedence over selector, at least one of them must be defined
|
|
@@ -684,6 +685,31 @@ interface ScreenshotOptions {
|
|
|
684
685
|
*/
|
|
685
686
|
type?: 'png' | 'jpeg';
|
|
686
687
|
}
|
|
688
|
+
interface WaitElementOptions {
|
|
689
|
+
/**
|
|
690
|
+
* @default 30_000 ms
|
|
691
|
+
*/
|
|
692
|
+
timeout?: number;
|
|
693
|
+
/**
|
|
694
|
+
* @default "visible"
|
|
695
|
+
*/
|
|
696
|
+
state?: "attached" | "detached" | "hidden" | "visible";
|
|
697
|
+
}
|
|
698
|
+
interface WaitNavigationOptions {
|
|
699
|
+
/**
|
|
700
|
+
* only supported in playwright by now
|
|
701
|
+
* @default ""
|
|
702
|
+
*/
|
|
703
|
+
url?: string | RegExp;
|
|
704
|
+
/**
|
|
705
|
+
* @default 30_000 ms
|
|
706
|
+
*/
|
|
707
|
+
timeout?: number;
|
|
708
|
+
/**
|
|
709
|
+
* @default "visible"
|
|
710
|
+
*/
|
|
711
|
+
waitUntil?: NavigationWaitUntil;
|
|
712
|
+
}
|
|
687
713
|
interface LsdPage extends EventEmitter {
|
|
688
714
|
bringToFront(): Promise<boolean>;
|
|
689
715
|
browserContext(): LsdBrowserContext;
|
|
@@ -778,6 +804,17 @@ interface LsdPage extends EventEmitter {
|
|
|
778
804
|
* 开始使用该page(当前状态必须为free)
|
|
779
805
|
*/
|
|
780
806
|
use(): boolean;
|
|
807
|
+
/**
|
|
808
|
+
*
|
|
809
|
+
* @param selector CSS selector, not XPath
|
|
810
|
+
* @param options
|
|
811
|
+
*/
|
|
812
|
+
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
813
|
+
/**
|
|
814
|
+
*
|
|
815
|
+
* @param options
|
|
816
|
+
*/
|
|
817
|
+
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
781
818
|
/**
|
|
782
819
|
* obj=window?.[key1]...?.[keyn]
|
|
783
820
|
* @return obj ? JSON.stringify(obj) : ""
|
|
@@ -937,6 +974,8 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
937
974
|
title(): Promise<string>;
|
|
938
975
|
url(): string;
|
|
939
976
|
use(): boolean;
|
|
977
|
+
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
978
|
+
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
940
979
|
windowMember(keys: string[]): Promise<string>;
|
|
941
980
|
}
|
|
942
981
|
|
|
@@ -1041,6 +1080,8 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1041
1080
|
title(): Promise<string>;
|
|
1042
1081
|
url(): string;
|
|
1043
1082
|
use(): boolean;
|
|
1083
|
+
waitForElement(selector: string, options?: WaitElementOptions): Promise<boolean>;
|
|
1084
|
+
waitForNavigation(options: WaitNavigationOptions): Promise<boolean>;
|
|
1044
1085
|
windowMember(keys: string[]): Promise<string>;
|
|
1045
1086
|
}
|
|
1046
1087
|
|
|
@@ -1110,6 +1151,8 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1110
1151
|
title(): Promise<string>;
|
|
1111
1152
|
url(): string;
|
|
1112
1153
|
use(): boolean;
|
|
1154
|
+
waitForElement(): Promise<boolean>;
|
|
1155
|
+
waitForNavigation(): Promise<boolean>;
|
|
1113
1156
|
windowMember(): Promise<string>;
|
|
1114
1157
|
}
|
|
1115
1158
|
|
|
@@ -1135,4 +1178,4 @@ declare class CheerioElement implements LsdElement {
|
|
|
1135
1178
|
scrollIntoView(): Promise<boolean>;
|
|
1136
1179
|
}
|
|
1137
1180
|
|
|
1138
|
-
export { 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, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type PDFMargin, type PDFOptions, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, PlaywrightElement, PlaywrightPage, type Proxy, 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 ScreenshotOptions, type SelectOptions, type StateData, type ViewportSize, defaultProxy };
|
|
1181
|
+
export { 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, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, PlaywrightElement, PlaywrightPage, type Proxy, 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 ScreenshotOptions, type SelectOptions, type StateData, type ViewportSize, type WaitElementOptions, type WaitNavigationOptions, defaultProxy };
|
package/dist/index.js
CHANGED
|
@@ -648,12 +648,19 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
648
648
|
await this.clearResponseInterceptions();
|
|
649
649
|
return true;
|
|
650
650
|
}
|
|
651
|
+
#getWaitUntil(origWaitUntil) {
|
|
652
|
+
if (origWaitUntil === "networkidle0" || origWaitUntil === "networkidle2") {
|
|
653
|
+
return "networkidle";
|
|
654
|
+
} else {
|
|
655
|
+
return origWaitUntil;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
651
658
|
async goto(url, options) {
|
|
652
659
|
if (!this.#page) {
|
|
653
660
|
throw new Error("No valid page");
|
|
654
661
|
}
|
|
655
662
|
if (options) {
|
|
656
|
-
const { referer, timeout, waitUntil } = options;
|
|
663
|
+
const { referer, timeout, waitUntil = "load" } = options;
|
|
657
664
|
const newOptions = {};
|
|
658
665
|
if (referer) {
|
|
659
666
|
newOptions.referer = referer;
|
|
@@ -661,9 +668,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
661
668
|
if (timeout) {
|
|
662
669
|
newOptions.timeout = timeout;
|
|
663
670
|
}
|
|
664
|
-
|
|
665
|
-
newOptions.waitUntil = waitUntil === "networkidle" ? "networkidle0" : waitUntil;
|
|
666
|
-
}
|
|
671
|
+
newOptions.waitUntil = this.#getWaitUntil(waitUntil);
|
|
667
672
|
await this.#page.goto(url, newOptions);
|
|
668
673
|
} else {
|
|
669
674
|
await this.#page.goto(url);
|
|
@@ -996,6 +1001,30 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
996
1001
|
this.#status = "busy";
|
|
997
1002
|
return true;
|
|
998
1003
|
}
|
|
1004
|
+
async waitForElement(selector, options = {}) {
|
|
1005
|
+
if (!this.#page) {
|
|
1006
|
+
throw new Error("No valid page");
|
|
1007
|
+
}
|
|
1008
|
+
const locator = this.#page.locator(selector);
|
|
1009
|
+
const { timeout = 3e4, state = "visible" } = options;
|
|
1010
|
+
await locator.waitFor({ state, timeout });
|
|
1011
|
+
return true;
|
|
1012
|
+
}
|
|
1013
|
+
async waitForNavigation(options) {
|
|
1014
|
+
if (!this.#page) {
|
|
1015
|
+
throw new Error("No valid page");
|
|
1016
|
+
}
|
|
1017
|
+
const { url = "", timeout = 3e4, waitUntil = "load" } = options;
|
|
1018
|
+
const newWaitUntil = this.#getWaitUntil(waitUntil);
|
|
1019
|
+
if (url) {
|
|
1020
|
+
await this.#page.waitForURL(url, { timeout, waitUntil: newWaitUntil });
|
|
1021
|
+
} else if (newWaitUntil === "commit") {
|
|
1022
|
+
throw new Error("commit is not supported in PlaywrightPage.waitForNavigation");
|
|
1023
|
+
} else {
|
|
1024
|
+
await this.#page.waitForLoadState(newWaitUntil, { timeout });
|
|
1025
|
+
}
|
|
1026
|
+
return true;
|
|
1027
|
+
}
|
|
999
1028
|
async windowMember(keys) {
|
|
1000
1029
|
if (!this.#page) {
|
|
1001
1030
|
throw new Error("No valid page");
|
|
@@ -2023,12 +2052,21 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2023
2052
|
await this.clearResponseInterceptions();
|
|
2024
2053
|
return true;
|
|
2025
2054
|
}
|
|
2055
|
+
#getWaitUntil(origWaitUntil) {
|
|
2056
|
+
if (origWaitUntil === "networkidle") {
|
|
2057
|
+
return "networkidle0";
|
|
2058
|
+
} else if (origWaitUntil === "commit") {
|
|
2059
|
+
throw new Error("commit is not supported in PuppeteerPage");
|
|
2060
|
+
} else {
|
|
2061
|
+
return origWaitUntil;
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2026
2064
|
async goto(url, options) {
|
|
2027
2065
|
if (!this.#page) {
|
|
2028
2066
|
throw new Error("No valid page");
|
|
2029
2067
|
}
|
|
2030
2068
|
if (options) {
|
|
2031
|
-
const { referer, timeout, waitUntil } = options;
|
|
2069
|
+
const { referer, timeout, waitUntil = "load" } = options;
|
|
2032
2070
|
const newOptions = {};
|
|
2033
2071
|
if (referer) {
|
|
2034
2072
|
newOptions.referer = referer;
|
|
@@ -2037,7 +2075,7 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2037
2075
|
newOptions.timeout = timeout;
|
|
2038
2076
|
}
|
|
2039
2077
|
if (waitUntil && waitUntil !== "commit") {
|
|
2040
|
-
newOptions.waitUntil = waitUntil
|
|
2078
|
+
newOptions.waitUntil = this.#getWaitUntil(waitUntil);
|
|
2041
2079
|
}
|
|
2042
2080
|
await this.#page.goto(url, newOptions);
|
|
2043
2081
|
} else {
|
|
@@ -2351,6 +2389,33 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2351
2389
|
this.#status = "busy";
|
|
2352
2390
|
return true;
|
|
2353
2391
|
}
|
|
2392
|
+
async waitForElement(selector, options = {}) {
|
|
2393
|
+
if (!this.#page) {
|
|
2394
|
+
throw new Error("No valid page");
|
|
2395
|
+
}
|
|
2396
|
+
const { timeout = 3e4, state = "visible" } = options;
|
|
2397
|
+
if (state === "visible") {
|
|
2398
|
+
await this.#page.waitForSelector(selector, { timeout, visible: true });
|
|
2399
|
+
} else if (state === "hidden") {
|
|
2400
|
+
await this.#page.waitForSelector(selector, { timeout, hidden: true });
|
|
2401
|
+
} else {
|
|
2402
|
+
throw new Error(`${state} is not supported in PuppeteerPage.waitForElement`);
|
|
2403
|
+
}
|
|
2404
|
+
return true;
|
|
2405
|
+
}
|
|
2406
|
+
async waitForNavigation(options) {
|
|
2407
|
+
if (!this.#page) {
|
|
2408
|
+
throw new Error("No valid page");
|
|
2409
|
+
}
|
|
2410
|
+
const { url = "", timeout = 3e4, waitUntil = "load" } = options;
|
|
2411
|
+
const newWaitUntil = this.#getWaitUntil(waitUntil);
|
|
2412
|
+
if (url) {
|
|
2413
|
+
throw new Error("url is not supported in PuppeteerPage.waitForNavigation");
|
|
2414
|
+
} else {
|
|
2415
|
+
await this.#page.waitForNavigation({ timeout, waitUntil: newWaitUntil });
|
|
2416
|
+
}
|
|
2417
|
+
return true;
|
|
2418
|
+
}
|
|
2354
2419
|
async windowMember(keys) {
|
|
2355
2420
|
if (!this.#page) {
|
|
2356
2421
|
throw new Error("No valid page");
|
|
@@ -16927,6 +16992,12 @@ var CheerioPage = class extends EventEmitter7 {
|
|
|
16927
16992
|
use() {
|
|
16928
16993
|
throw new Error("Not supported in CheerioPage.");
|
|
16929
16994
|
}
|
|
16995
|
+
waitForElement() {
|
|
16996
|
+
throw new Error("Not supported in CheerioPage.");
|
|
16997
|
+
}
|
|
16998
|
+
waitForNavigation() {
|
|
16999
|
+
throw new Error("Not supported in CheerioPage.");
|
|
17000
|
+
}
|
|
16930
17001
|
async windowMember() {
|
|
16931
17002
|
throw new Error("Not supported in CheerioPage.");
|
|
16932
17003
|
}
|
package/package.json
CHANGED