@letsscrapedata/controller 0.0.6 → 0.0.8
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 +59 -4
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +59 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -233,9 +233,15 @@ var PlaywrightElement = class _PlaywrightElement {
|
|
|
233
233
|
return text3 ? text3 : "";
|
|
234
234
|
}
|
|
235
235
|
async click(options = {}) {
|
|
236
|
-
const { button, clickCount: count, delay, position: offset } = options;
|
|
236
|
+
const { button, clickCount: count, delay, position: offset, clickType = "click" } = options;
|
|
237
237
|
const actOptions = { button, count, delay, offset };
|
|
238
|
-
|
|
238
|
+
if (clickType === "click") {
|
|
239
|
+
await this.#locator.click(actOptions);
|
|
240
|
+
} else if (clickType === "evaluate") {
|
|
241
|
+
await this.#locator.evaluate(async (ev) => await ev.click());
|
|
242
|
+
} else {
|
|
243
|
+
(0, import_utils.unreachable)(clickType);
|
|
244
|
+
}
|
|
239
245
|
return true;
|
|
240
246
|
}
|
|
241
247
|
async focus() {
|
|
@@ -321,6 +327,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
321
327
|
#pageId;
|
|
322
328
|
#resquestInterceptionOptions;
|
|
323
329
|
#responseInterceptionOptions;
|
|
330
|
+
#client;
|
|
324
331
|
#hasValidUrl(page) {
|
|
325
332
|
const url = page.url();
|
|
326
333
|
return url.toLowerCase().startsWith("http");
|
|
@@ -532,6 +539,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
532
539
|
this.#pageId = `page${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
533
540
|
this.#resquestInterceptionOptions = [];
|
|
534
541
|
this.#responseInterceptionOptions = [];
|
|
542
|
+
this.#client = null;
|
|
535
543
|
this.#addPageOn();
|
|
536
544
|
}
|
|
537
545
|
async bringToFront() {
|
|
@@ -787,6 +795,24 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
787
795
|
);
|
|
788
796
|
return true;
|
|
789
797
|
}
|
|
798
|
+
async sendCDPMessage(method, params = null, detach = true) {
|
|
799
|
+
if (!this.#client) {
|
|
800
|
+
const origContext = this.browserContext()._origBrowserContext();
|
|
801
|
+
if (!origContext) {
|
|
802
|
+
throw new Error(`Invalid playwright browserContext`);
|
|
803
|
+
}
|
|
804
|
+
this.#client = origContext.newCDPSession(this.#page);
|
|
805
|
+
}
|
|
806
|
+
if (!this.#client) {
|
|
807
|
+
throw new Error("No valid CDP session to send message");
|
|
808
|
+
}
|
|
809
|
+
const response = params ? await this.#client.send(method, params) : await this.#client.send(method);
|
|
810
|
+
if (detach) {
|
|
811
|
+
await this.#client.detach();
|
|
812
|
+
this.#client = null;
|
|
813
|
+
}
|
|
814
|
+
return response;
|
|
815
|
+
}
|
|
790
816
|
async setCookies(cookies) {
|
|
791
817
|
if (!this.#page) {
|
|
792
818
|
throw new Error("No valid page");
|
|
@@ -1650,9 +1676,16 @@ var PuppeteerElement = class _PuppeteerElement {
|
|
|
1650
1676
|
return text3 ? text3 : "";
|
|
1651
1677
|
}
|
|
1652
1678
|
async click(options = {}) {
|
|
1653
|
-
const { button, clickCount: count, delay, position: offset } = options;
|
|
1679
|
+
const { button, clickCount: count, delay, position: offset, clickType = "click" } = options;
|
|
1654
1680
|
const actOptions = { button, count, delay, offset };
|
|
1655
|
-
|
|
1681
|
+
if (clickType === "click") {
|
|
1682
|
+
await this.#$ele.click(actOptions);
|
|
1683
|
+
} else if (clickType === "evaluate") {
|
|
1684
|
+
await this.#frame.evaluate(async (ev) => await ev.click(), this.#$ele);
|
|
1685
|
+
await this.#$ele.click(actOptions);
|
|
1686
|
+
} else {
|
|
1687
|
+
(0, import_utils5.unreachable)(clickType);
|
|
1688
|
+
}
|
|
1656
1689
|
return true;
|
|
1657
1690
|
}
|
|
1658
1691
|
async focus() {
|
|
@@ -1756,6 +1789,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
1756
1789
|
#pageId;
|
|
1757
1790
|
#requestInterceptionNum;
|
|
1758
1791
|
#responseInterceptionNum;
|
|
1792
|
+
#client;
|
|
1759
1793
|
#hasValidUrl(page) {
|
|
1760
1794
|
const url = page.url();
|
|
1761
1795
|
return url.toLowerCase().startsWith("http");
|
|
@@ -1952,6 +1986,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
1952
1986
|
this.#pageId = `page${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
1953
1987
|
this.#requestInterceptionNum = 0;
|
|
1954
1988
|
this.#responseInterceptionNum = 0;
|
|
1989
|
+
this.#client = null;
|
|
1955
1990
|
this.#addPageOn();
|
|
1956
1991
|
}
|
|
1957
1992
|
async bringToFront() {
|
|
@@ -2210,6 +2245,23 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2210
2245
|
);
|
|
2211
2246
|
return true;
|
|
2212
2247
|
}
|
|
2248
|
+
async sendCDPMessage(method, params = null, detach = true) {
|
|
2249
|
+
if (!this.#page) {
|
|
2250
|
+
throw new Error("No valid page");
|
|
2251
|
+
}
|
|
2252
|
+
if (!this.#client) {
|
|
2253
|
+
this.#client = await this.#page.createCDPSession();
|
|
2254
|
+
}
|
|
2255
|
+
if (!this.#client) {
|
|
2256
|
+
throw new Error("No valid CDP session to send message");
|
|
2257
|
+
}
|
|
2258
|
+
const response = params ? await this.#client.send(method, params) : await this.#client.send(method);
|
|
2259
|
+
if (detach) {
|
|
2260
|
+
await this.#client.detach();
|
|
2261
|
+
this.#client = null;
|
|
2262
|
+
}
|
|
2263
|
+
return response;
|
|
2264
|
+
}
|
|
2213
2265
|
async setCookies(cookies) {
|
|
2214
2266
|
if (!this.#page) {
|
|
2215
2267
|
throw new Error("No valid page");
|
|
@@ -16999,6 +17051,9 @@ var CheerioPage = class extends import_node_events7.default {
|
|
|
16999
17051
|
async scrollTo() {
|
|
17000
17052
|
throw new Error("Not supported in CheerioElement.");
|
|
17001
17053
|
}
|
|
17054
|
+
async sendCDPMessage() {
|
|
17055
|
+
throw new Error("Method not implemented.");
|
|
17056
|
+
}
|
|
17002
17057
|
async setCookies() {
|
|
17003
17058
|
throw new Error("Not supported in CheerioPage.");
|
|
17004
17059
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -222,6 +222,7 @@ interface PageExtInPuppeteer extends Page$1 {
|
|
|
222
222
|
interface PageExtInPlaywright extends Page {
|
|
223
223
|
pageInfo?: PageInfo;
|
|
224
224
|
}
|
|
225
|
+
type MouseClickType = "click" | "evaluate";
|
|
225
226
|
interface MouseClickOptions {
|
|
226
227
|
/**
|
|
227
228
|
* Which button will be pressed.
|
|
@@ -252,6 +253,10 @@ interface MouseClickOptions {
|
|
|
252
253
|
* * puppeteer: not supported, ignored
|
|
253
254
|
*/
|
|
254
255
|
modifiers?: Array<"Alt" | "Control" | "Meta" | "Shift">;
|
|
256
|
+
/**
|
|
257
|
+
* @default click
|
|
258
|
+
*/
|
|
259
|
+
clickType?: MouseClickType;
|
|
255
260
|
}
|
|
256
261
|
interface SelectOptions {
|
|
257
262
|
/**
|
|
@@ -801,6 +806,14 @@ interface LsdPage extends EventEmitter {
|
|
|
801
806
|
screenshot(options?: ScreenshotOptions): Promise<Buffer>;
|
|
802
807
|
scrollBy(x: number, y: number): Promise<boolean>;
|
|
803
808
|
scrollTo(x: number, y: number): Promise<boolean>;
|
|
809
|
+
/**
|
|
810
|
+
*
|
|
811
|
+
* Send a CDP message over the current(not detached) or new CDP session
|
|
812
|
+
* @param method protocol method name
|
|
813
|
+
* @param params default null(ignored), method parameters
|
|
814
|
+
* @param detach default true, whether to detach the CDPSession from target
|
|
815
|
+
*/
|
|
816
|
+
sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<object>;
|
|
804
817
|
setCookies(cookies: CookieItem[]): Promise<boolean>;
|
|
805
818
|
setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
|
|
806
819
|
/**
|
|
@@ -992,6 +1005,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
992
1005
|
screenshot(options?: ScreenshotOptions): Promise<Buffer>;
|
|
993
1006
|
scrollBy(x: number, y: number): Promise<boolean>;
|
|
994
1007
|
scrollTo(x: number, y: number): Promise<boolean>;
|
|
1008
|
+
sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<object>;
|
|
995
1009
|
setCookies(cookies: CookieItem[]): Promise<boolean>;
|
|
996
1010
|
setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
|
|
997
1011
|
setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
|
|
@@ -1099,6 +1113,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1099
1113
|
screenshot(options?: ScreenshotOptions): Promise<Buffer>;
|
|
1100
1114
|
scrollBy(x: number, y: number): Promise<boolean>;
|
|
1101
1115
|
scrollTo(x: number, y: number): Promise<boolean>;
|
|
1116
|
+
sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<object>;
|
|
1102
1117
|
setCookies(cookies: CookieItem[]): Promise<boolean>;
|
|
1103
1118
|
setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
|
|
1104
1119
|
setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
|
|
@@ -1170,6 +1185,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1170
1185
|
screenshot(): Promise<Buffer>;
|
|
1171
1186
|
scrollBy(): Promise<boolean>;
|
|
1172
1187
|
scrollTo(): Promise<boolean>;
|
|
1188
|
+
sendCDPMessage(): Promise<object>;
|
|
1173
1189
|
setCookies(): Promise<boolean>;
|
|
1174
1190
|
setExtraHTTPHeaders(): Promise<boolean>;
|
|
1175
1191
|
setLocalStroage(): Promise<boolean>;
|
|
@@ -1211,4 +1227,4 @@ declare class CheerioElement implements LsdElement {
|
|
|
1211
1227
|
scrollIntoView(): Promise<boolean>;
|
|
1212
1228
|
}
|
|
1213
1229
|
|
|
1214
|
-
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 PageEvent, 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 UpdatablePageInfo, type ViewportSize, type WaitElementOptions, type WaitElementState, type WaitNavigationOptions, defaultProxy };
|
|
1230
|
+
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 MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, 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 UpdatablePageInfo, type ViewportSize, type WaitElementOptions, type WaitElementState, type WaitNavigationOptions, defaultProxy };
|
package/dist/index.d.ts
CHANGED
|
@@ -222,6 +222,7 @@ interface PageExtInPuppeteer extends Page$1 {
|
|
|
222
222
|
interface PageExtInPlaywright extends Page {
|
|
223
223
|
pageInfo?: PageInfo;
|
|
224
224
|
}
|
|
225
|
+
type MouseClickType = "click" | "evaluate";
|
|
225
226
|
interface MouseClickOptions {
|
|
226
227
|
/**
|
|
227
228
|
* Which button will be pressed.
|
|
@@ -252,6 +253,10 @@ interface MouseClickOptions {
|
|
|
252
253
|
* * puppeteer: not supported, ignored
|
|
253
254
|
*/
|
|
254
255
|
modifiers?: Array<"Alt" | "Control" | "Meta" | "Shift">;
|
|
256
|
+
/**
|
|
257
|
+
* @default click
|
|
258
|
+
*/
|
|
259
|
+
clickType?: MouseClickType;
|
|
255
260
|
}
|
|
256
261
|
interface SelectOptions {
|
|
257
262
|
/**
|
|
@@ -801,6 +806,14 @@ interface LsdPage extends EventEmitter {
|
|
|
801
806
|
screenshot(options?: ScreenshotOptions): Promise<Buffer>;
|
|
802
807
|
scrollBy(x: number, y: number): Promise<boolean>;
|
|
803
808
|
scrollTo(x: number, y: number): Promise<boolean>;
|
|
809
|
+
/**
|
|
810
|
+
*
|
|
811
|
+
* Send a CDP message over the current(not detached) or new CDP session
|
|
812
|
+
* @param method protocol method name
|
|
813
|
+
* @param params default null(ignored), method parameters
|
|
814
|
+
* @param detach default true, whether to detach the CDPSession from target
|
|
815
|
+
*/
|
|
816
|
+
sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<object>;
|
|
804
817
|
setCookies(cookies: CookieItem[]): Promise<boolean>;
|
|
805
818
|
setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
|
|
806
819
|
/**
|
|
@@ -992,6 +1005,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
|
992
1005
|
screenshot(options?: ScreenshotOptions): Promise<Buffer>;
|
|
993
1006
|
scrollBy(x: number, y: number): Promise<boolean>;
|
|
994
1007
|
scrollTo(x: number, y: number): Promise<boolean>;
|
|
1008
|
+
sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<object>;
|
|
995
1009
|
setCookies(cookies: CookieItem[]): Promise<boolean>;
|
|
996
1010
|
setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
|
|
997
1011
|
setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
|
|
@@ -1099,6 +1113,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
|
1099
1113
|
screenshot(options?: ScreenshotOptions): Promise<Buffer>;
|
|
1100
1114
|
scrollBy(x: number, y: number): Promise<boolean>;
|
|
1101
1115
|
scrollTo(x: number, y: number): Promise<boolean>;
|
|
1116
|
+
sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<object>;
|
|
1102
1117
|
setCookies(cookies: CookieItem[]): Promise<boolean>;
|
|
1103
1118
|
setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
|
|
1104
1119
|
setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
|
|
@@ -1170,6 +1185,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1170
1185
|
screenshot(): Promise<Buffer>;
|
|
1171
1186
|
scrollBy(): Promise<boolean>;
|
|
1172
1187
|
scrollTo(): Promise<boolean>;
|
|
1188
|
+
sendCDPMessage(): Promise<object>;
|
|
1173
1189
|
setCookies(): Promise<boolean>;
|
|
1174
1190
|
setExtraHTTPHeaders(): Promise<boolean>;
|
|
1175
1191
|
setLocalStroage(): Promise<boolean>;
|
|
@@ -1211,4 +1227,4 @@ declare class CheerioElement implements LsdElement {
|
|
|
1211
1227
|
scrollIntoView(): Promise<boolean>;
|
|
1212
1228
|
}
|
|
1213
1229
|
|
|
1214
|
-
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 PageEvent, 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 UpdatablePageInfo, type ViewportSize, type WaitElementOptions, type WaitElementState, type WaitNavigationOptions, defaultProxy };
|
|
1230
|
+
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 MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, 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 UpdatablePageInfo, type ViewportSize, type WaitElementOptions, type WaitElementState, type WaitNavigationOptions, defaultProxy };
|
package/dist/index.js
CHANGED
|
@@ -214,9 +214,15 @@ var PlaywrightElement = class _PlaywrightElement {
|
|
|
214
214
|
return text3 ? text3 : "";
|
|
215
215
|
}
|
|
216
216
|
async click(options = {}) {
|
|
217
|
-
const { button, clickCount: count, delay, position: offset } = options;
|
|
217
|
+
const { button, clickCount: count, delay, position: offset, clickType = "click" } = options;
|
|
218
218
|
const actOptions = { button, count, delay, offset };
|
|
219
|
-
|
|
219
|
+
if (clickType === "click") {
|
|
220
|
+
await this.#locator.click(actOptions);
|
|
221
|
+
} else if (clickType === "evaluate") {
|
|
222
|
+
await this.#locator.evaluate(async (ev) => await ev.click());
|
|
223
|
+
} else {
|
|
224
|
+
unreachable(clickType);
|
|
225
|
+
}
|
|
220
226
|
return true;
|
|
221
227
|
}
|
|
222
228
|
async focus() {
|
|
@@ -302,6 +308,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
302
308
|
#pageId;
|
|
303
309
|
#resquestInterceptionOptions;
|
|
304
310
|
#responseInterceptionOptions;
|
|
311
|
+
#client;
|
|
305
312
|
#hasValidUrl(page) {
|
|
306
313
|
const url = page.url();
|
|
307
314
|
return url.toLowerCase().startsWith("http");
|
|
@@ -513,6 +520,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
513
520
|
this.#pageId = `page${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
514
521
|
this.#resquestInterceptionOptions = [];
|
|
515
522
|
this.#responseInterceptionOptions = [];
|
|
523
|
+
this.#client = null;
|
|
516
524
|
this.#addPageOn();
|
|
517
525
|
}
|
|
518
526
|
async bringToFront() {
|
|
@@ -768,6 +776,24 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
768
776
|
);
|
|
769
777
|
return true;
|
|
770
778
|
}
|
|
779
|
+
async sendCDPMessage(method, params = null, detach = true) {
|
|
780
|
+
if (!this.#client) {
|
|
781
|
+
const origContext = this.browserContext()._origBrowserContext();
|
|
782
|
+
if (!origContext) {
|
|
783
|
+
throw new Error(`Invalid playwright browserContext`);
|
|
784
|
+
}
|
|
785
|
+
this.#client = origContext.newCDPSession(this.#page);
|
|
786
|
+
}
|
|
787
|
+
if (!this.#client) {
|
|
788
|
+
throw new Error("No valid CDP session to send message");
|
|
789
|
+
}
|
|
790
|
+
const response = params ? await this.#client.send(method, params) : await this.#client.send(method);
|
|
791
|
+
if (detach) {
|
|
792
|
+
await this.#client.detach();
|
|
793
|
+
this.#client = null;
|
|
794
|
+
}
|
|
795
|
+
return response;
|
|
796
|
+
}
|
|
771
797
|
async setCookies(cookies) {
|
|
772
798
|
if (!this.#page) {
|
|
773
799
|
throw new Error("No valid page");
|
|
@@ -1631,9 +1657,16 @@ var PuppeteerElement = class _PuppeteerElement {
|
|
|
1631
1657
|
return text3 ? text3 : "";
|
|
1632
1658
|
}
|
|
1633
1659
|
async click(options = {}) {
|
|
1634
|
-
const { button, clickCount: count, delay, position: offset } = options;
|
|
1660
|
+
const { button, clickCount: count, delay, position: offset, clickType = "click" } = options;
|
|
1635
1661
|
const actOptions = { button, count, delay, offset };
|
|
1636
|
-
|
|
1662
|
+
if (clickType === "click") {
|
|
1663
|
+
await this.#$ele.click(actOptions);
|
|
1664
|
+
} else if (clickType === "evaluate") {
|
|
1665
|
+
await this.#frame.evaluate(async (ev) => await ev.click(), this.#$ele);
|
|
1666
|
+
await this.#$ele.click(actOptions);
|
|
1667
|
+
} else {
|
|
1668
|
+
unreachable3(clickType);
|
|
1669
|
+
}
|
|
1637
1670
|
return true;
|
|
1638
1671
|
}
|
|
1639
1672
|
async focus() {
|
|
@@ -1737,6 +1770,7 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
1737
1770
|
#pageId;
|
|
1738
1771
|
#requestInterceptionNum;
|
|
1739
1772
|
#responseInterceptionNum;
|
|
1773
|
+
#client;
|
|
1740
1774
|
#hasValidUrl(page) {
|
|
1741
1775
|
const url = page.url();
|
|
1742
1776
|
return url.toLowerCase().startsWith("http");
|
|
@@ -1933,6 +1967,7 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
1933
1967
|
this.#pageId = `page${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
1934
1968
|
this.#requestInterceptionNum = 0;
|
|
1935
1969
|
this.#responseInterceptionNum = 0;
|
|
1970
|
+
this.#client = null;
|
|
1936
1971
|
this.#addPageOn();
|
|
1937
1972
|
}
|
|
1938
1973
|
async bringToFront() {
|
|
@@ -2191,6 +2226,23 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2191
2226
|
);
|
|
2192
2227
|
return true;
|
|
2193
2228
|
}
|
|
2229
|
+
async sendCDPMessage(method, params = null, detach = true) {
|
|
2230
|
+
if (!this.#page) {
|
|
2231
|
+
throw new Error("No valid page");
|
|
2232
|
+
}
|
|
2233
|
+
if (!this.#client) {
|
|
2234
|
+
this.#client = await this.#page.createCDPSession();
|
|
2235
|
+
}
|
|
2236
|
+
if (!this.#client) {
|
|
2237
|
+
throw new Error("No valid CDP session to send message");
|
|
2238
|
+
}
|
|
2239
|
+
const response = params ? await this.#client.send(method, params) : await this.#client.send(method);
|
|
2240
|
+
if (detach) {
|
|
2241
|
+
await this.#client.detach();
|
|
2242
|
+
this.#client = null;
|
|
2243
|
+
}
|
|
2244
|
+
return response;
|
|
2245
|
+
}
|
|
2194
2246
|
async setCookies(cookies) {
|
|
2195
2247
|
if (!this.#page) {
|
|
2196
2248
|
throw new Error("No valid page");
|
|
@@ -16980,6 +17032,9 @@ var CheerioPage = class extends EventEmitter7 {
|
|
|
16980
17032
|
async scrollTo() {
|
|
16981
17033
|
throw new Error("Not supported in CheerioElement.");
|
|
16982
17034
|
}
|
|
17035
|
+
async sendCDPMessage() {
|
|
17036
|
+
throw new Error("Method not implemented.");
|
|
17037
|
+
}
|
|
16983
17038
|
async setCookies() {
|
|
16984
17039
|
throw new Error("Not supported in CheerioPage.");
|
|
16985
17040
|
}
|
package/package.json
CHANGED