@letsscrapedata/controller 0.0.50 → 0.0.52

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.d.cts CHANGED
@@ -1,16 +1,20 @@
1
1
  import EventEmitter from 'node:events';
2
- import { Browser as Browser$1, BrowserContext as BrowserContext$1, Frame as Frame$1, Page as Page$1, ElementHandle, HTTPResponse, PuppeteerNode } from 'puppeteer';
3
- import { Browser, BrowserContext, Frame, Page, Locator, Response, APIRequestContext, BrowserType, FrameLocator } from 'playwright';
2
+ import { Browser as Browser$1, BrowserContext as BrowserContext$1, ElementHandle, Frame as Frame$1, Page as Page$1, HTTPResponse, PuppeteerNode } from 'puppeteer';
3
+ import { Browser, BrowserContext, Locator, ElementHandle as ElementHandle$1, Frame, Page, Response, APIRequestContext, BrowserType, FrameLocator } from 'playwright';
4
+ import { Serializable } from 'node:child_process';
5
+ import { LogFunction } from '@letsscrapedata/utils';
6
+ import { Serializable as Serializable$1 } from 'child_process';
4
7
 
8
+ type BrowserControllerType = "puppeteer" | "playwright";
5
9
  type AllBrowser = Browser | Browser$1;
6
10
  type AllBrowserContext = BrowserContext | BrowserContext$1;
11
+ type AllElement = Locator | ElementHandle;
12
+ type AllElementHandle = ElementHandle$1 | ElementHandle;
7
13
  type AllFrame = Frame | Frame$1;
8
14
  type AllPage = Page | Page$1;
9
- type AllElement = Locator | ElementHandle;
10
15
  type AllResponse = Response | HTTPResponse;
11
16
  type AllApiRequestContext = APIRequestContext;
12
17
  type CheerioNode = cheerio.Cheerio;
13
- type BrowserControllerType = "puppeteer" | "playwright";
14
18
  type BrowserCreationMethod = "launch" | "connect";
15
19
  type BrowserContextCreationMethod = "launch" | "new";
16
20
  type BrowserContextStatus = "free" | "busy" | "closed";
@@ -296,6 +300,33 @@ interface PageExtInPuppeteer extends Page$1 {
296
300
  interface PageExtInPlaywright extends Page {
297
301
  pageInfo?: PageInfo;
298
302
  }
303
+ interface FrameAddScriptTagOptions {
304
+ /**
305
+ * URL of the script to be added.
306
+ */
307
+ url?: string;
308
+ /**
309
+ * Path to a JavaScript file to be injected into the frame.
310
+ *
311
+ * @remarks
312
+ * If `path` is a relative path, it is resolved relative to the current
313
+ * working directory (`process.cwd()` in Node.js).
314
+ */
315
+ path?: string;
316
+ /**
317
+ * JavaScript to be injected into the frame.
318
+ */
319
+ content?: string;
320
+ /**
321
+ * Sets the `type` of the script. Use `module` in order to load an ES2015 module.
322
+ */
323
+ type?: string;
324
+ /**
325
+ * Sets the `id` of the script.
326
+ * * supported only in puppeteer
327
+ */
328
+ id?: string;
329
+ }
299
330
  type MouseClickType = "click" | "evaluate";
300
331
  interface MouseClickOptions {
301
332
  /**
@@ -370,6 +401,10 @@ interface IframeOption {
370
401
  * * RegExp: iframe.src matches this RegExp
371
402
  */
372
403
  src?: string | RegExp;
404
+ /**
405
+ * id of iframe
406
+ */
407
+ id?: string;
373
408
  /**
374
409
  * CSS selector or XPath
375
410
  */
@@ -411,6 +446,17 @@ interface LsdElement {
411
446
  * @returns the attribute names of the element
412
447
  */
413
448
  attributeNames(): Promise<string[]>;
449
+ dataset(): Promise<Record<string, string>>;
450
+ /**
451
+ * In order to be compatible with various browser controllers, if you need to use this function, please follow the following conventions:
452
+ * * If the element is in an iframe, use the descendant type when locating the iframe, not the child type!
453
+ * * * Reason: args of <page/frame | locator>.evaluate are different in Playwright
454
+ * * When there is only one parameter: element.evaluate(arg=>statements, val)
455
+ * * When there are one or more parameters: element.evaluate(([arg1, arg2]=>statements, [val1, val2])
456
+ * @param func
457
+ * @param args
458
+ */
459
+ evaluate(func: Function, args?: any[]): Promise<Serializable>;
414
460
  /**
415
461
  * @returns the first element matching the given CSS selector or XPath
416
462
  * @param selectorOrXpath CSS selector or XPath; if this parameter is an array, each selectorOrXpath in the array will be tried until elements are selected
@@ -830,6 +876,19 @@ interface WaitNavigationOptions {
830
876
  }
831
877
  type PageEvent = "pageClose" | "pagePopup";
832
878
  interface LsdPage extends EventEmitter {
879
+ /**
880
+ * Adds a script which would be evaluated in one of the following scenarios:
881
+ * * Whenever the page is navigated.
882
+ * * Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly attached frame.
883
+ * @param scriptOrFunc
884
+ * @param arg
885
+ */
886
+ addPreloadScript(scriptOrFunc: string | Function, arg?: Serializable): Promise<boolean>;
887
+ /**
888
+ * Adds a `<script>` tag into the page with the desired URL or content.
889
+ * @param options
890
+ */
891
+ addScriptTag(options: FrameAddScriptTagOptions): Promise<AllElementHandle>;
833
892
  /**
834
893
  * Get the LsdApiContext associated with this page's LsdBrowserContext
835
894
  * * only vaild in playwright
@@ -865,19 +924,38 @@ interface LsdPage extends EventEmitter {
865
924
  * Only free page can be closed!
866
925
  */
867
926
  close(): Promise<boolean>;
927
+ /**
928
+ * Should the page be closed when it is freed?
929
+ * * Sometimes, in order to avoid being used again, you need to close the page.
930
+ * * valid only in browser page
931
+ * @default false, please call setCloseWhenFree to change it
932
+ */
933
+ closeWhenFree(): boolean;
868
934
  /**
869
935
  * Get the full HTML content of the page or decendant frame
870
936
  * @param iframeOptions default [], selectors of decendant frames
871
937
  */
872
938
  content(iframeOptions?: IframeOption[]): Promise<string>;
873
939
  cookies(): Promise<CookieItem[]>;
874
- evalute(fun: Function, args?: any[]): Promise<any>;
940
+ evaluate(func: Function, args?: any[]): Promise<any>;
941
+ /**
942
+ * The method adds a function called `name` on the page's `window` object.
943
+ * When called, the function executes `callbackFunction` in node.js and
944
+ * returns a `Promise` which resolves to the return value of `callbackFunction`.
945
+ * * Reminder: It is not recommended to use this function because it is easy to be detected !!!
946
+ * @param name Name of the function on the window object
947
+ * @param callbackFunction Callback function which will be called in node.js context
948
+ */
949
+ exposeFunction(name: string, callbackFunction: Function): Promise<void>;
875
950
  /**
876
951
  * @returns the first element matching the given CSS selector or XPath
877
952
  * @param selectorOrXpath CSS selector or XPath; if this parameter is an array, each selectorOrXpath in the array will be tried until elements are selected
878
953
  * @param iframeOptions default [], options to select decendant frame
954
+ * @param iframeType default "child", "descendant" is valid only if selectorOrXpath is string , iframeOptions.length is 1 and iframeOptions[0].src is string or RegExp
955
+ * @example
956
+ * * findElement("body", [{src: iframe.src}], "descendant"): to get the body element of a descendant iframe with src
879
957
  */
880
- findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
958
+ findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], iframeType?: "child" | "descendant"): Promise<LsdElement | null>;
881
959
  /**
882
960
  * @returns elements matching the given CSS selector or XPath
883
961
  * @param selectorOrXpath CSS selector or XPath; if this parameter is an array, each selectorOrXpath in the array will be tried until elements are selected
@@ -919,6 +997,12 @@ interface LsdPage extends EventEmitter {
919
997
  * @param detach default true, whether to detach the CDPSession from target
920
998
  */
921
999
  sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<any>;
1000
+ /**
1001
+ * set new value of closeWhenFree, refer to closeWhenFree
1002
+ * * valid only in browser page
1003
+ * @param closeWhenFree
1004
+ */
1005
+ setCloseWhenFree(closeWhenFree: boolean): boolean;
922
1006
  setCookies(cookies: CookieItem[]): Promise<boolean>;
923
1007
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
924
1008
  /**
@@ -1108,6 +1192,8 @@ interface LsdBrowserController$1 {
1108
1192
  newApiContext(options?: LsdApiContextOptions): Promise<LsdApiContext>;
1109
1193
  }
1110
1194
 
1195
+ declare function setControllerLogFun(logFun: LogFunction): boolean;
1196
+
1111
1197
  declare class PlaywrightBrowser extends EventEmitter implements LsdBrowser {
1112
1198
  #private;
1113
1199
  constructor(browser: Browser, browerType: LsdBrowserType, browserCreateMethod: BrowserCreationMethod, options: LsdLaunchOptions | LsdConnectOptions, browserIdx?: number, pid?: number);
@@ -1161,6 +1247,8 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
1161
1247
  declare class PlaywrightPage extends EventEmitter implements LsdPage {
1162
1248
  #private;
1163
1249
  constructor(browserContext: LsdBrowserContext, page: Page, pageInfo?: PageInfo);
1250
+ addPreloadScript(scriptOrFunc: string | Function, arg?: Serializable$1): Promise<boolean>;
1251
+ addScriptTag(options: FrameAddScriptTagOptions): Promise<AllElementHandle>;
1164
1252
  apiContext(): LsdApiContext;
1165
1253
  bringToFront(): Promise<boolean>;
1166
1254
  browserContext(): LsdBrowserContext;
@@ -1170,10 +1258,12 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
1170
1258
  clearResponseInterceptions(): Promise<boolean>;
1171
1259
  clearStateData(): Promise<boolean>;
1172
1260
  close(): Promise<boolean>;
1261
+ closeWhenFree(): boolean;
1173
1262
  content(iframeOptions?: IframeOption[]): Promise<string>;
1174
1263
  cookies(): Promise<CookieItem[]>;
1175
1264
  documentHeight(): Promise<number>;
1176
- evalute(fun: Function, args?: any[]): Promise<any>;
1265
+ evaluate(func: Function, args?: any[]): Promise<any>;
1266
+ exposeFunction(name: string, callbackFunction: Function): Promise<void>;
1177
1267
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
1178
1268
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
1179
1269
  free(): Promise<boolean>;
@@ -1192,6 +1282,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
1192
1282
  scrollBy(x: number, y: number): Promise<boolean>;
1193
1283
  scrollTo(x: number, y: number): Promise<boolean>;
1194
1284
  sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<any>;
1285
+ setCloseWhenFree(closeWhenFree: boolean): boolean;
1195
1286
  setCookies(cookies: CookieItem[]): Promise<boolean>;
1196
1287
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
1197
1288
  setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
@@ -1217,6 +1308,8 @@ declare class PlaywrightElement implements LsdElement {
1217
1308
  constructor(locator: Locator, frame: Frame | FrameLocator);
1218
1309
  attribute(attributeName: string): Promise<string>;
1219
1310
  attributeNames(): Promise<string[]>;
1311
+ dataset(): Promise<Record<string, string>>;
1312
+ evaluate(func: Function, args?: any[]): Promise<any>;
1220
1313
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1221
1314
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1222
1315
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1289,6 +1382,8 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
1289
1382
  declare class PuppeteerPage extends EventEmitter implements LsdPage {
1290
1383
  #private;
1291
1384
  constructor(browserContext: LsdBrowserContext, page: Page$1, pageInfo?: PageInfo);
1385
+ addPreloadScript(scriptOrFunc: string | Function, arg?: Serializable$1): Promise<boolean>;
1386
+ addScriptTag(options: FrameAddScriptTagOptions): Promise<AllElementHandle>;
1292
1387
  apiContext(): LsdApiContext;
1293
1388
  bringToFront(): Promise<boolean>;
1294
1389
  browserContext(): LsdBrowserContext;
@@ -1298,10 +1393,12 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
1298
1393
  clearResponseInterceptions(): Promise<boolean>;
1299
1394
  clearStateData(): Promise<boolean>;
1300
1395
  close(): Promise<boolean>;
1396
+ closeWhenFree(): boolean;
1301
1397
  content(iframeOptions?: IframeOption[]): Promise<string>;
1302
1398
  cookies(): Promise<CookieItem[]>;
1303
1399
  documentHeight(): Promise<number>;
1304
- evalute(fun: Function, args?: any[]): Promise<any>;
1400
+ evaluate(func: Function, args?: any[]): Promise<any>;
1401
+ exposeFunction(name: string, callbackFunction: Function): Promise<void>;
1305
1402
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
1306
1403
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
1307
1404
  free(): Promise<boolean>;
@@ -1320,6 +1417,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
1320
1417
  scrollBy(x: number, y: number): Promise<boolean>;
1321
1418
  scrollTo(x: number, y: number): Promise<boolean>;
1322
1419
  sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<any>;
1420
+ setCloseWhenFree(closeWhenFree: boolean): boolean;
1323
1421
  setCookies(cookies: CookieItem[]): Promise<boolean>;
1324
1422
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
1325
1423
  setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
@@ -1345,6 +1443,8 @@ declare class PuppeteerElement implements LsdElement {
1345
1443
  constructor($ele: ElementHandle, frame: Frame$1);
1346
1444
  attribute(attributeName: string): Promise<string>;
1347
1445
  attributeNames(): Promise<string[]>;
1446
+ dataset(): Promise<Record<string, string>>;
1447
+ evaluate(func: Function, args?: any[]): Promise<any>;
1348
1448
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1349
1449
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1350
1450
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1364,6 +1464,9 @@ declare class PuppeteerElement implements LsdElement {
1364
1464
  _origElement(): AllElement;
1365
1465
  }
1366
1466
 
1467
+ /**
1468
+ * CheerioPage does not support iframe: https://github.com/cheeriojs/cheerio/issues/602
1469
+ */
1367
1470
  declare class CheerioPage extends EventEmitter implements LsdPage {
1368
1471
  #private;
1369
1472
  /**
@@ -1373,6 +1476,8 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1373
1476
  */
1374
1477
  constructor(html?: string, isHtml?: boolean);
1375
1478
  _origPage(): AllPage;
1479
+ addPreloadScript(): Promise<boolean>;
1480
+ addScriptTag(): Promise<AllElementHandle>;
1376
1481
  apiContext(): LsdApiContext;
1377
1482
  bringToFront(): Promise<boolean>;
1378
1483
  browserContext(): LsdBrowserContext;
@@ -1382,9 +1487,11 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1382
1487
  clearResponseInterceptions(): Promise<boolean>;
1383
1488
  clearStateData(): Promise<boolean>;
1384
1489
  close(): Promise<boolean>;
1490
+ closeWhenFree(): boolean;
1385
1491
  content(): Promise<string>;
1386
1492
  cookies(): Promise<CookieItem[]>;
1387
- evalute(): Promise<any>;
1493
+ evaluate(): Promise<any>;
1494
+ exposeFunction(): Promise<void>;
1388
1495
  findElement(selectorOrXpath: string | string[]): Promise<LsdElement | null>;
1389
1496
  findElements(selectorOrXpath: string | string[]): Promise<LsdElement[]>;
1390
1497
  free(): Promise<boolean>;
@@ -1403,6 +1510,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1403
1510
  scrollBy(): Promise<boolean>;
1404
1511
  scrollTo(): Promise<boolean>;
1405
1512
  sendCDPMessage(): Promise<any>;
1513
+ setCloseWhenFree(): boolean;
1406
1514
  setCookies(): Promise<boolean>;
1407
1515
  setExtraHTTPHeaders(): Promise<boolean>;
1408
1516
  setLocalStroage(): Promise<boolean>;
@@ -1427,6 +1535,8 @@ declare class CheerioElement implements LsdElement {
1427
1535
  constructor(node: CheerioNode);
1428
1536
  attribute(attributeName: string): Promise<string>;
1429
1537
  attributeNames(): Promise<string[]>;
1538
+ dataset(): Promise<Record<string, string>>;
1539
+ evaluate(): Promise<any>;
1430
1540
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1431
1541
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1432
1542
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1457,4 +1567,4 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
1457
1567
  }
1458
1568
  declare const controller: LsdBrowserController;
1459
1569
 
1460
- export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllElement, type AllFrame, type AllPage, type AllResponse, type BrowserContextCreationMethod, type BrowserContextRequirements, type BrowserContextStatus, type BrowserControllerType, type BrowserCreationMethod, type BrowserLaunchMethod, type BrowserStateData, CheerioElement, type CheerioNode, CheerioPage, type ClientCertificate, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdApiContext, type LsdApiContextOptions, type LsdApiResponse, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdFetchOptions, 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 };
1570
+ export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllElement, type AllElementHandle, type AllFrame, type AllPage, type AllResponse, type BrowserContextCreationMethod, type BrowserContextRequirements, type BrowserContextStatus, type BrowserControllerType, type BrowserCreationMethod, type BrowserLaunchMethod, type BrowserStateData, CheerioElement, type CheerioNode, CheerioPage, type ClientCertificate, type CookieItem, type FrameAddScriptTagOptions, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdApiContext, type LsdApiContextOptions, type LsdApiResponse, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdFetchOptions, 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, setControllerLogFun };
package/dist/index.d.ts CHANGED
@@ -1,16 +1,20 @@
1
1
  import EventEmitter from 'node:events';
2
- import { Browser as Browser$1, BrowserContext as BrowserContext$1, Frame as Frame$1, Page as Page$1, ElementHandle, HTTPResponse, PuppeteerNode } from 'puppeteer';
3
- import { Browser, BrowserContext, Frame, Page, Locator, Response, APIRequestContext, BrowserType, FrameLocator } from 'playwright';
2
+ import { Browser as Browser$1, BrowserContext as BrowserContext$1, ElementHandle, Frame as Frame$1, Page as Page$1, HTTPResponse, PuppeteerNode } from 'puppeteer';
3
+ import { Browser, BrowserContext, Locator, ElementHandle as ElementHandle$1, Frame, Page, Response, APIRequestContext, BrowserType, FrameLocator } from 'playwright';
4
+ import { Serializable } from 'node:child_process';
5
+ import { LogFunction } from '@letsscrapedata/utils';
6
+ import { Serializable as Serializable$1 } from 'child_process';
4
7
 
8
+ type BrowserControllerType = "puppeteer" | "playwright";
5
9
  type AllBrowser = Browser | Browser$1;
6
10
  type AllBrowserContext = BrowserContext | BrowserContext$1;
11
+ type AllElement = Locator | ElementHandle;
12
+ type AllElementHandle = ElementHandle$1 | ElementHandle;
7
13
  type AllFrame = Frame | Frame$1;
8
14
  type AllPage = Page | Page$1;
9
- type AllElement = Locator | ElementHandle;
10
15
  type AllResponse = Response | HTTPResponse;
11
16
  type AllApiRequestContext = APIRequestContext;
12
17
  type CheerioNode = cheerio.Cheerio;
13
- type BrowserControllerType = "puppeteer" | "playwright";
14
18
  type BrowserCreationMethod = "launch" | "connect";
15
19
  type BrowserContextCreationMethod = "launch" | "new";
16
20
  type BrowserContextStatus = "free" | "busy" | "closed";
@@ -296,6 +300,33 @@ interface PageExtInPuppeteer extends Page$1 {
296
300
  interface PageExtInPlaywright extends Page {
297
301
  pageInfo?: PageInfo;
298
302
  }
303
+ interface FrameAddScriptTagOptions {
304
+ /**
305
+ * URL of the script to be added.
306
+ */
307
+ url?: string;
308
+ /**
309
+ * Path to a JavaScript file to be injected into the frame.
310
+ *
311
+ * @remarks
312
+ * If `path` is a relative path, it is resolved relative to the current
313
+ * working directory (`process.cwd()` in Node.js).
314
+ */
315
+ path?: string;
316
+ /**
317
+ * JavaScript to be injected into the frame.
318
+ */
319
+ content?: string;
320
+ /**
321
+ * Sets the `type` of the script. Use `module` in order to load an ES2015 module.
322
+ */
323
+ type?: string;
324
+ /**
325
+ * Sets the `id` of the script.
326
+ * * supported only in puppeteer
327
+ */
328
+ id?: string;
329
+ }
299
330
  type MouseClickType = "click" | "evaluate";
300
331
  interface MouseClickOptions {
301
332
  /**
@@ -370,6 +401,10 @@ interface IframeOption {
370
401
  * * RegExp: iframe.src matches this RegExp
371
402
  */
372
403
  src?: string | RegExp;
404
+ /**
405
+ * id of iframe
406
+ */
407
+ id?: string;
373
408
  /**
374
409
  * CSS selector or XPath
375
410
  */
@@ -411,6 +446,17 @@ interface LsdElement {
411
446
  * @returns the attribute names of the element
412
447
  */
413
448
  attributeNames(): Promise<string[]>;
449
+ dataset(): Promise<Record<string, string>>;
450
+ /**
451
+ * In order to be compatible with various browser controllers, if you need to use this function, please follow the following conventions:
452
+ * * If the element is in an iframe, use the descendant type when locating the iframe, not the child type!
453
+ * * * Reason: args of <page/frame | locator>.evaluate are different in Playwright
454
+ * * When there is only one parameter: element.evaluate(arg=>statements, val)
455
+ * * When there are one or more parameters: element.evaluate(([arg1, arg2]=>statements, [val1, val2])
456
+ * @param func
457
+ * @param args
458
+ */
459
+ evaluate(func: Function, args?: any[]): Promise<Serializable>;
414
460
  /**
415
461
  * @returns the first element matching the given CSS selector or XPath
416
462
  * @param selectorOrXpath CSS selector or XPath; if this parameter is an array, each selectorOrXpath in the array will be tried until elements are selected
@@ -830,6 +876,19 @@ interface WaitNavigationOptions {
830
876
  }
831
877
  type PageEvent = "pageClose" | "pagePopup";
832
878
  interface LsdPage extends EventEmitter {
879
+ /**
880
+ * Adds a script which would be evaluated in one of the following scenarios:
881
+ * * Whenever the page is navigated.
882
+ * * Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly attached frame.
883
+ * @param scriptOrFunc
884
+ * @param arg
885
+ */
886
+ addPreloadScript(scriptOrFunc: string | Function, arg?: Serializable): Promise<boolean>;
887
+ /**
888
+ * Adds a `<script>` tag into the page with the desired URL or content.
889
+ * @param options
890
+ */
891
+ addScriptTag(options: FrameAddScriptTagOptions): Promise<AllElementHandle>;
833
892
  /**
834
893
  * Get the LsdApiContext associated with this page's LsdBrowserContext
835
894
  * * only vaild in playwright
@@ -865,19 +924,38 @@ interface LsdPage extends EventEmitter {
865
924
  * Only free page can be closed!
866
925
  */
867
926
  close(): Promise<boolean>;
927
+ /**
928
+ * Should the page be closed when it is freed?
929
+ * * Sometimes, in order to avoid being used again, you need to close the page.
930
+ * * valid only in browser page
931
+ * @default false, please call setCloseWhenFree to change it
932
+ */
933
+ closeWhenFree(): boolean;
868
934
  /**
869
935
  * Get the full HTML content of the page or decendant frame
870
936
  * @param iframeOptions default [], selectors of decendant frames
871
937
  */
872
938
  content(iframeOptions?: IframeOption[]): Promise<string>;
873
939
  cookies(): Promise<CookieItem[]>;
874
- evalute(fun: Function, args?: any[]): Promise<any>;
940
+ evaluate(func: Function, args?: any[]): Promise<any>;
941
+ /**
942
+ * The method adds a function called `name` on the page's `window` object.
943
+ * When called, the function executes `callbackFunction` in node.js and
944
+ * returns a `Promise` which resolves to the return value of `callbackFunction`.
945
+ * * Reminder: It is not recommended to use this function because it is easy to be detected !!!
946
+ * @param name Name of the function on the window object
947
+ * @param callbackFunction Callback function which will be called in node.js context
948
+ */
949
+ exposeFunction(name: string, callbackFunction: Function): Promise<void>;
875
950
  /**
876
951
  * @returns the first element matching the given CSS selector or XPath
877
952
  * @param selectorOrXpath CSS selector or XPath; if this parameter is an array, each selectorOrXpath in the array will be tried until elements are selected
878
953
  * @param iframeOptions default [], options to select decendant frame
954
+ * @param iframeType default "child", "descendant" is valid only if selectorOrXpath is string , iframeOptions.length is 1 and iframeOptions[0].src is string or RegExp
955
+ * @example
956
+ * * findElement("body", [{src: iframe.src}], "descendant"): to get the body element of a descendant iframe with src
879
957
  */
880
- findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
958
+ findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], iframeType?: "child" | "descendant"): Promise<LsdElement | null>;
881
959
  /**
882
960
  * @returns elements matching the given CSS selector or XPath
883
961
  * @param selectorOrXpath CSS selector or XPath; if this parameter is an array, each selectorOrXpath in the array will be tried until elements are selected
@@ -919,6 +997,12 @@ interface LsdPage extends EventEmitter {
919
997
  * @param detach default true, whether to detach the CDPSession from target
920
998
  */
921
999
  sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<any>;
1000
+ /**
1001
+ * set new value of closeWhenFree, refer to closeWhenFree
1002
+ * * valid only in browser page
1003
+ * @param closeWhenFree
1004
+ */
1005
+ setCloseWhenFree(closeWhenFree: boolean): boolean;
922
1006
  setCookies(cookies: CookieItem[]): Promise<boolean>;
923
1007
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
924
1008
  /**
@@ -1108,6 +1192,8 @@ interface LsdBrowserController$1 {
1108
1192
  newApiContext(options?: LsdApiContextOptions): Promise<LsdApiContext>;
1109
1193
  }
1110
1194
 
1195
+ declare function setControllerLogFun(logFun: LogFunction): boolean;
1196
+
1111
1197
  declare class PlaywrightBrowser extends EventEmitter implements LsdBrowser {
1112
1198
  #private;
1113
1199
  constructor(browser: Browser, browerType: LsdBrowserType, browserCreateMethod: BrowserCreationMethod, options: LsdLaunchOptions | LsdConnectOptions, browserIdx?: number, pid?: number);
@@ -1161,6 +1247,8 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
1161
1247
  declare class PlaywrightPage extends EventEmitter implements LsdPage {
1162
1248
  #private;
1163
1249
  constructor(browserContext: LsdBrowserContext, page: Page, pageInfo?: PageInfo);
1250
+ addPreloadScript(scriptOrFunc: string | Function, arg?: Serializable$1): Promise<boolean>;
1251
+ addScriptTag(options: FrameAddScriptTagOptions): Promise<AllElementHandle>;
1164
1252
  apiContext(): LsdApiContext;
1165
1253
  bringToFront(): Promise<boolean>;
1166
1254
  browserContext(): LsdBrowserContext;
@@ -1170,10 +1258,12 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
1170
1258
  clearResponseInterceptions(): Promise<boolean>;
1171
1259
  clearStateData(): Promise<boolean>;
1172
1260
  close(): Promise<boolean>;
1261
+ closeWhenFree(): boolean;
1173
1262
  content(iframeOptions?: IframeOption[]): Promise<string>;
1174
1263
  cookies(): Promise<CookieItem[]>;
1175
1264
  documentHeight(): Promise<number>;
1176
- evalute(fun: Function, args?: any[]): Promise<any>;
1265
+ evaluate(func: Function, args?: any[]): Promise<any>;
1266
+ exposeFunction(name: string, callbackFunction: Function): Promise<void>;
1177
1267
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
1178
1268
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
1179
1269
  free(): Promise<boolean>;
@@ -1192,6 +1282,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
1192
1282
  scrollBy(x: number, y: number): Promise<boolean>;
1193
1283
  scrollTo(x: number, y: number): Promise<boolean>;
1194
1284
  sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<any>;
1285
+ setCloseWhenFree(closeWhenFree: boolean): boolean;
1195
1286
  setCookies(cookies: CookieItem[]): Promise<boolean>;
1196
1287
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
1197
1288
  setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
@@ -1217,6 +1308,8 @@ declare class PlaywrightElement implements LsdElement {
1217
1308
  constructor(locator: Locator, frame: Frame | FrameLocator);
1218
1309
  attribute(attributeName: string): Promise<string>;
1219
1310
  attributeNames(): Promise<string[]>;
1311
+ dataset(): Promise<Record<string, string>>;
1312
+ evaluate(func: Function, args?: any[]): Promise<any>;
1220
1313
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1221
1314
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1222
1315
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1289,6 +1382,8 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
1289
1382
  declare class PuppeteerPage extends EventEmitter implements LsdPage {
1290
1383
  #private;
1291
1384
  constructor(browserContext: LsdBrowserContext, page: Page$1, pageInfo?: PageInfo);
1385
+ addPreloadScript(scriptOrFunc: string | Function, arg?: Serializable$1): Promise<boolean>;
1386
+ addScriptTag(options: FrameAddScriptTagOptions): Promise<AllElementHandle>;
1292
1387
  apiContext(): LsdApiContext;
1293
1388
  bringToFront(): Promise<boolean>;
1294
1389
  browserContext(): LsdBrowserContext;
@@ -1298,10 +1393,12 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
1298
1393
  clearResponseInterceptions(): Promise<boolean>;
1299
1394
  clearStateData(): Promise<boolean>;
1300
1395
  close(): Promise<boolean>;
1396
+ closeWhenFree(): boolean;
1301
1397
  content(iframeOptions?: IframeOption[]): Promise<string>;
1302
1398
  cookies(): Promise<CookieItem[]>;
1303
1399
  documentHeight(): Promise<number>;
1304
- evalute(fun: Function, args?: any[]): Promise<any>;
1400
+ evaluate(func: Function, args?: any[]): Promise<any>;
1401
+ exposeFunction(name: string, callbackFunction: Function): Promise<void>;
1305
1402
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
1306
1403
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
1307
1404
  free(): Promise<boolean>;
@@ -1320,6 +1417,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
1320
1417
  scrollBy(x: number, y: number): Promise<boolean>;
1321
1418
  scrollTo(x: number, y: number): Promise<boolean>;
1322
1419
  sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<any>;
1420
+ setCloseWhenFree(closeWhenFree: boolean): boolean;
1323
1421
  setCookies(cookies: CookieItem[]): Promise<boolean>;
1324
1422
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
1325
1423
  setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
@@ -1345,6 +1443,8 @@ declare class PuppeteerElement implements LsdElement {
1345
1443
  constructor($ele: ElementHandle, frame: Frame$1);
1346
1444
  attribute(attributeName: string): Promise<string>;
1347
1445
  attributeNames(): Promise<string[]>;
1446
+ dataset(): Promise<Record<string, string>>;
1447
+ evaluate(func: Function, args?: any[]): Promise<any>;
1348
1448
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1349
1449
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1350
1450
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1364,6 +1464,9 @@ declare class PuppeteerElement implements LsdElement {
1364
1464
  _origElement(): AllElement;
1365
1465
  }
1366
1466
 
1467
+ /**
1468
+ * CheerioPage does not support iframe: https://github.com/cheeriojs/cheerio/issues/602
1469
+ */
1367
1470
  declare class CheerioPage extends EventEmitter implements LsdPage {
1368
1471
  #private;
1369
1472
  /**
@@ -1373,6 +1476,8 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1373
1476
  */
1374
1477
  constructor(html?: string, isHtml?: boolean);
1375
1478
  _origPage(): AllPage;
1479
+ addPreloadScript(): Promise<boolean>;
1480
+ addScriptTag(): Promise<AllElementHandle>;
1376
1481
  apiContext(): LsdApiContext;
1377
1482
  bringToFront(): Promise<boolean>;
1378
1483
  browserContext(): LsdBrowserContext;
@@ -1382,9 +1487,11 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1382
1487
  clearResponseInterceptions(): Promise<boolean>;
1383
1488
  clearStateData(): Promise<boolean>;
1384
1489
  close(): Promise<boolean>;
1490
+ closeWhenFree(): boolean;
1385
1491
  content(): Promise<string>;
1386
1492
  cookies(): Promise<CookieItem[]>;
1387
- evalute(): Promise<any>;
1493
+ evaluate(): Promise<any>;
1494
+ exposeFunction(): Promise<void>;
1388
1495
  findElement(selectorOrXpath: string | string[]): Promise<LsdElement | null>;
1389
1496
  findElements(selectorOrXpath: string | string[]): Promise<LsdElement[]>;
1390
1497
  free(): Promise<boolean>;
@@ -1403,6 +1510,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1403
1510
  scrollBy(): Promise<boolean>;
1404
1511
  scrollTo(): Promise<boolean>;
1405
1512
  sendCDPMessage(): Promise<any>;
1513
+ setCloseWhenFree(): boolean;
1406
1514
  setCookies(): Promise<boolean>;
1407
1515
  setExtraHTTPHeaders(): Promise<boolean>;
1408
1516
  setLocalStroage(): Promise<boolean>;
@@ -1427,6 +1535,8 @@ declare class CheerioElement implements LsdElement {
1427
1535
  constructor(node: CheerioNode);
1428
1536
  attribute(attributeName: string): Promise<string>;
1429
1537
  attributeNames(): Promise<string[]>;
1538
+ dataset(): Promise<Record<string, string>>;
1539
+ evaluate(): Promise<any>;
1430
1540
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1431
1541
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1432
1542
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1457,4 +1567,4 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
1457
1567
  }
1458
1568
  declare const controller: LsdBrowserController;
1459
1569
 
1460
- export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllElement, type AllFrame, type AllPage, type AllResponse, type BrowserContextCreationMethod, type BrowserContextRequirements, type BrowserContextStatus, type BrowserControllerType, type BrowserCreationMethod, type BrowserLaunchMethod, type BrowserStateData, CheerioElement, type CheerioNode, CheerioPage, type ClientCertificate, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdApiContext, type LsdApiContextOptions, type LsdApiResponse, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdFetchOptions, 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 };
1570
+ export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllElement, type AllElementHandle, type AllFrame, type AllPage, type AllResponse, type BrowserContextCreationMethod, type BrowserContextRequirements, type BrowserContextStatus, type BrowserControllerType, type BrowserCreationMethod, type BrowserLaunchMethod, type BrowserStateData, CheerioElement, type CheerioNode, CheerioPage, type ClientCertificate, type CookieItem, type FrameAddScriptTagOptions, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdApiContext, type LsdApiContextOptions, type LsdApiResponse, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdFetchOptions, 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, setControllerLogFun };