@letsscrapedata/controller 0.0.51 → 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,17 +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';
4
5
  import { LogFunction } from '@letsscrapedata/utils';
6
+ import { Serializable as Serializable$1 } from 'child_process';
5
7
 
8
+ type BrowserControllerType = "puppeteer" | "playwright";
6
9
  type AllBrowser = Browser | Browser$1;
7
10
  type AllBrowserContext = BrowserContext | BrowserContext$1;
11
+ type AllElement = Locator | ElementHandle;
12
+ type AllElementHandle = ElementHandle$1 | ElementHandle;
8
13
  type AllFrame = Frame | Frame$1;
9
14
  type AllPage = Page | Page$1;
10
- type AllElement = Locator | ElementHandle;
11
15
  type AllResponse = Response | HTTPResponse;
12
16
  type AllApiRequestContext = APIRequestContext;
13
17
  type CheerioNode = cheerio.Cheerio;
14
- type BrowserControllerType = "puppeteer" | "playwright";
15
18
  type BrowserCreationMethod = "launch" | "connect";
16
19
  type BrowserContextCreationMethod = "launch" | "new";
17
20
  type BrowserContextStatus = "free" | "busy" | "closed";
@@ -297,6 +300,33 @@ interface PageExtInPuppeteer extends Page$1 {
297
300
  interface PageExtInPlaywright extends Page {
298
301
  pageInfo?: PageInfo;
299
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
+ }
300
330
  type MouseClickType = "click" | "evaluate";
301
331
  interface MouseClickOptions {
302
332
  /**
@@ -371,6 +401,10 @@ interface IframeOption {
371
401
  * * RegExp: iframe.src matches this RegExp
372
402
  */
373
403
  src?: string | RegExp;
404
+ /**
405
+ * id of iframe
406
+ */
407
+ id?: string;
374
408
  /**
375
409
  * CSS selector or XPath
376
410
  */
@@ -412,6 +446,17 @@ interface LsdElement {
412
446
  * @returns the attribute names of the element
413
447
  */
414
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>;
415
460
  /**
416
461
  * @returns the first element matching the given CSS selector or XPath
417
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
@@ -831,6 +876,19 @@ interface WaitNavigationOptions {
831
876
  }
832
877
  type PageEvent = "pageClose" | "pagePopup";
833
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>;
834
892
  /**
835
893
  * Get the LsdApiContext associated with this page's LsdBrowserContext
836
894
  * * only vaild in playwright
@@ -866,19 +924,38 @@ interface LsdPage extends EventEmitter {
866
924
  * Only free page can be closed!
867
925
  */
868
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;
869
934
  /**
870
935
  * Get the full HTML content of the page or decendant frame
871
936
  * @param iframeOptions default [], selectors of decendant frames
872
937
  */
873
938
  content(iframeOptions?: IframeOption[]): Promise<string>;
874
939
  cookies(): Promise<CookieItem[]>;
875
- 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>;
876
950
  /**
877
951
  * @returns the first element matching the given CSS selector or XPath
878
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
879
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
880
957
  */
881
- findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
958
+ findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], iframeType?: "child" | "descendant"): Promise<LsdElement | null>;
882
959
  /**
883
960
  * @returns elements matching the given CSS selector or XPath
884
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
@@ -920,6 +997,12 @@ interface LsdPage extends EventEmitter {
920
997
  * @param detach default true, whether to detach the CDPSession from target
921
998
  */
922
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;
923
1006
  setCookies(cookies: CookieItem[]): Promise<boolean>;
924
1007
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
925
1008
  /**
@@ -1164,6 +1247,8 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
1164
1247
  declare class PlaywrightPage extends EventEmitter implements LsdPage {
1165
1248
  #private;
1166
1249
  constructor(browserContext: LsdBrowserContext, page: Page, pageInfo?: PageInfo);
1250
+ addPreloadScript(scriptOrFunc: string | Function, arg?: Serializable$1): Promise<boolean>;
1251
+ addScriptTag(options: FrameAddScriptTagOptions): Promise<AllElementHandle>;
1167
1252
  apiContext(): LsdApiContext;
1168
1253
  bringToFront(): Promise<boolean>;
1169
1254
  browserContext(): LsdBrowserContext;
@@ -1173,10 +1258,12 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
1173
1258
  clearResponseInterceptions(): Promise<boolean>;
1174
1259
  clearStateData(): Promise<boolean>;
1175
1260
  close(): Promise<boolean>;
1261
+ closeWhenFree(): boolean;
1176
1262
  content(iframeOptions?: IframeOption[]): Promise<string>;
1177
1263
  cookies(): Promise<CookieItem[]>;
1178
1264
  documentHeight(): Promise<number>;
1179
- evalute(fun: Function, args?: any[]): Promise<any>;
1265
+ evaluate(func: Function, args?: any[]): Promise<any>;
1266
+ exposeFunction(name: string, callbackFunction: Function): Promise<void>;
1180
1267
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
1181
1268
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
1182
1269
  free(): Promise<boolean>;
@@ -1195,6 +1282,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
1195
1282
  scrollBy(x: number, y: number): Promise<boolean>;
1196
1283
  scrollTo(x: number, y: number): Promise<boolean>;
1197
1284
  sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<any>;
1285
+ setCloseWhenFree(closeWhenFree: boolean): boolean;
1198
1286
  setCookies(cookies: CookieItem[]): Promise<boolean>;
1199
1287
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
1200
1288
  setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
@@ -1220,6 +1308,8 @@ declare class PlaywrightElement implements LsdElement {
1220
1308
  constructor(locator: Locator, frame: Frame | FrameLocator);
1221
1309
  attribute(attributeName: string): Promise<string>;
1222
1310
  attributeNames(): Promise<string[]>;
1311
+ dataset(): Promise<Record<string, string>>;
1312
+ evaluate(func: Function, args?: any[]): Promise<any>;
1223
1313
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1224
1314
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1225
1315
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1292,6 +1382,8 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
1292
1382
  declare class PuppeteerPage extends EventEmitter implements LsdPage {
1293
1383
  #private;
1294
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>;
1295
1387
  apiContext(): LsdApiContext;
1296
1388
  bringToFront(): Promise<boolean>;
1297
1389
  browserContext(): LsdBrowserContext;
@@ -1301,10 +1393,12 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
1301
1393
  clearResponseInterceptions(): Promise<boolean>;
1302
1394
  clearStateData(): Promise<boolean>;
1303
1395
  close(): Promise<boolean>;
1396
+ closeWhenFree(): boolean;
1304
1397
  content(iframeOptions?: IframeOption[]): Promise<string>;
1305
1398
  cookies(): Promise<CookieItem[]>;
1306
1399
  documentHeight(): Promise<number>;
1307
- evalute(fun: Function, args?: any[]): Promise<any>;
1400
+ evaluate(func: Function, args?: any[]): Promise<any>;
1401
+ exposeFunction(name: string, callbackFunction: Function): Promise<void>;
1308
1402
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
1309
1403
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
1310
1404
  free(): Promise<boolean>;
@@ -1323,6 +1417,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
1323
1417
  scrollBy(x: number, y: number): Promise<boolean>;
1324
1418
  scrollTo(x: number, y: number): Promise<boolean>;
1325
1419
  sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<any>;
1420
+ setCloseWhenFree(closeWhenFree: boolean): boolean;
1326
1421
  setCookies(cookies: CookieItem[]): Promise<boolean>;
1327
1422
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
1328
1423
  setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
@@ -1348,6 +1443,8 @@ declare class PuppeteerElement implements LsdElement {
1348
1443
  constructor($ele: ElementHandle, frame: Frame$1);
1349
1444
  attribute(attributeName: string): Promise<string>;
1350
1445
  attributeNames(): Promise<string[]>;
1446
+ dataset(): Promise<Record<string, string>>;
1447
+ evaluate(func: Function, args?: any[]): Promise<any>;
1351
1448
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1352
1449
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1353
1450
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1367,6 +1464,9 @@ declare class PuppeteerElement implements LsdElement {
1367
1464
  _origElement(): AllElement;
1368
1465
  }
1369
1466
 
1467
+ /**
1468
+ * CheerioPage does not support iframe: https://github.com/cheeriojs/cheerio/issues/602
1469
+ */
1370
1470
  declare class CheerioPage extends EventEmitter implements LsdPage {
1371
1471
  #private;
1372
1472
  /**
@@ -1376,6 +1476,8 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1376
1476
  */
1377
1477
  constructor(html?: string, isHtml?: boolean);
1378
1478
  _origPage(): AllPage;
1479
+ addPreloadScript(): Promise<boolean>;
1480
+ addScriptTag(): Promise<AllElementHandle>;
1379
1481
  apiContext(): LsdApiContext;
1380
1482
  bringToFront(): Promise<boolean>;
1381
1483
  browserContext(): LsdBrowserContext;
@@ -1385,9 +1487,11 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1385
1487
  clearResponseInterceptions(): Promise<boolean>;
1386
1488
  clearStateData(): Promise<boolean>;
1387
1489
  close(): Promise<boolean>;
1490
+ closeWhenFree(): boolean;
1388
1491
  content(): Promise<string>;
1389
1492
  cookies(): Promise<CookieItem[]>;
1390
- evalute(): Promise<any>;
1493
+ evaluate(): Promise<any>;
1494
+ exposeFunction(): Promise<void>;
1391
1495
  findElement(selectorOrXpath: string | string[]): Promise<LsdElement | null>;
1392
1496
  findElements(selectorOrXpath: string | string[]): Promise<LsdElement[]>;
1393
1497
  free(): Promise<boolean>;
@@ -1406,6 +1510,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1406
1510
  scrollBy(): Promise<boolean>;
1407
1511
  scrollTo(): Promise<boolean>;
1408
1512
  sendCDPMessage(): Promise<any>;
1513
+ setCloseWhenFree(): boolean;
1409
1514
  setCookies(): Promise<boolean>;
1410
1515
  setExtraHTTPHeaders(): Promise<boolean>;
1411
1516
  setLocalStroage(): Promise<boolean>;
@@ -1430,6 +1535,8 @@ declare class CheerioElement implements LsdElement {
1430
1535
  constructor(node: CheerioNode);
1431
1536
  attribute(attributeName: string): Promise<string>;
1432
1537
  attributeNames(): Promise<string[]>;
1538
+ dataset(): Promise<Record<string, string>>;
1539
+ evaluate(): Promise<any>;
1433
1540
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1434
1541
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1435
1542
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1460,4 +1567,4 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
1460
1567
  }
1461
1568
  declare const controller: LsdBrowserController;
1462
1569
 
1463
- 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, setControllerLogFun };
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,17 +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';
4
5
  import { LogFunction } from '@letsscrapedata/utils';
6
+ import { Serializable as Serializable$1 } from 'child_process';
5
7
 
8
+ type BrowserControllerType = "puppeteer" | "playwright";
6
9
  type AllBrowser = Browser | Browser$1;
7
10
  type AllBrowserContext = BrowserContext | BrowserContext$1;
11
+ type AllElement = Locator | ElementHandle;
12
+ type AllElementHandle = ElementHandle$1 | ElementHandle;
8
13
  type AllFrame = Frame | Frame$1;
9
14
  type AllPage = Page | Page$1;
10
- type AllElement = Locator | ElementHandle;
11
15
  type AllResponse = Response | HTTPResponse;
12
16
  type AllApiRequestContext = APIRequestContext;
13
17
  type CheerioNode = cheerio.Cheerio;
14
- type BrowserControllerType = "puppeteer" | "playwright";
15
18
  type BrowserCreationMethod = "launch" | "connect";
16
19
  type BrowserContextCreationMethod = "launch" | "new";
17
20
  type BrowserContextStatus = "free" | "busy" | "closed";
@@ -297,6 +300,33 @@ interface PageExtInPuppeteer extends Page$1 {
297
300
  interface PageExtInPlaywright extends Page {
298
301
  pageInfo?: PageInfo;
299
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
+ }
300
330
  type MouseClickType = "click" | "evaluate";
301
331
  interface MouseClickOptions {
302
332
  /**
@@ -371,6 +401,10 @@ interface IframeOption {
371
401
  * * RegExp: iframe.src matches this RegExp
372
402
  */
373
403
  src?: string | RegExp;
404
+ /**
405
+ * id of iframe
406
+ */
407
+ id?: string;
374
408
  /**
375
409
  * CSS selector or XPath
376
410
  */
@@ -412,6 +446,17 @@ interface LsdElement {
412
446
  * @returns the attribute names of the element
413
447
  */
414
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>;
415
460
  /**
416
461
  * @returns the first element matching the given CSS selector or XPath
417
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
@@ -831,6 +876,19 @@ interface WaitNavigationOptions {
831
876
  }
832
877
  type PageEvent = "pageClose" | "pagePopup";
833
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>;
834
892
  /**
835
893
  * Get the LsdApiContext associated with this page's LsdBrowserContext
836
894
  * * only vaild in playwright
@@ -866,19 +924,38 @@ interface LsdPage extends EventEmitter {
866
924
  * Only free page can be closed!
867
925
  */
868
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;
869
934
  /**
870
935
  * Get the full HTML content of the page or decendant frame
871
936
  * @param iframeOptions default [], selectors of decendant frames
872
937
  */
873
938
  content(iframeOptions?: IframeOption[]): Promise<string>;
874
939
  cookies(): Promise<CookieItem[]>;
875
- 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>;
876
950
  /**
877
951
  * @returns the first element matching the given CSS selector or XPath
878
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
879
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
880
957
  */
881
- findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
958
+ findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], iframeType?: "child" | "descendant"): Promise<LsdElement | null>;
882
959
  /**
883
960
  * @returns elements matching the given CSS selector or XPath
884
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
@@ -920,6 +997,12 @@ interface LsdPage extends EventEmitter {
920
997
  * @param detach default true, whether to detach the CDPSession from target
921
998
  */
922
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;
923
1006
  setCookies(cookies: CookieItem[]): Promise<boolean>;
924
1007
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
925
1008
  /**
@@ -1164,6 +1247,8 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
1164
1247
  declare class PlaywrightPage extends EventEmitter implements LsdPage {
1165
1248
  #private;
1166
1249
  constructor(browserContext: LsdBrowserContext, page: Page, pageInfo?: PageInfo);
1250
+ addPreloadScript(scriptOrFunc: string | Function, arg?: Serializable$1): Promise<boolean>;
1251
+ addScriptTag(options: FrameAddScriptTagOptions): Promise<AllElementHandle>;
1167
1252
  apiContext(): LsdApiContext;
1168
1253
  bringToFront(): Promise<boolean>;
1169
1254
  browserContext(): LsdBrowserContext;
@@ -1173,10 +1258,12 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
1173
1258
  clearResponseInterceptions(): Promise<boolean>;
1174
1259
  clearStateData(): Promise<boolean>;
1175
1260
  close(): Promise<boolean>;
1261
+ closeWhenFree(): boolean;
1176
1262
  content(iframeOptions?: IframeOption[]): Promise<string>;
1177
1263
  cookies(): Promise<CookieItem[]>;
1178
1264
  documentHeight(): Promise<number>;
1179
- evalute(fun: Function, args?: any[]): Promise<any>;
1265
+ evaluate(func: Function, args?: any[]): Promise<any>;
1266
+ exposeFunction(name: string, callbackFunction: Function): Promise<void>;
1180
1267
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
1181
1268
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
1182
1269
  free(): Promise<boolean>;
@@ -1195,6 +1282,7 @@ declare class PlaywrightPage extends EventEmitter implements LsdPage {
1195
1282
  scrollBy(x: number, y: number): Promise<boolean>;
1196
1283
  scrollTo(x: number, y: number): Promise<boolean>;
1197
1284
  sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<any>;
1285
+ setCloseWhenFree(closeWhenFree: boolean): boolean;
1198
1286
  setCookies(cookies: CookieItem[]): Promise<boolean>;
1199
1287
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
1200
1288
  setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
@@ -1220,6 +1308,8 @@ declare class PlaywrightElement implements LsdElement {
1220
1308
  constructor(locator: Locator, frame: Frame | FrameLocator);
1221
1309
  attribute(attributeName: string): Promise<string>;
1222
1310
  attributeNames(): Promise<string[]>;
1311
+ dataset(): Promise<Record<string, string>>;
1312
+ evaluate(func: Function, args?: any[]): Promise<any>;
1223
1313
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1224
1314
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1225
1315
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1292,6 +1382,8 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
1292
1382
  declare class PuppeteerPage extends EventEmitter implements LsdPage {
1293
1383
  #private;
1294
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>;
1295
1387
  apiContext(): LsdApiContext;
1296
1388
  bringToFront(): Promise<boolean>;
1297
1389
  browserContext(): LsdBrowserContext;
@@ -1301,10 +1393,12 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
1301
1393
  clearResponseInterceptions(): Promise<boolean>;
1302
1394
  clearStateData(): Promise<boolean>;
1303
1395
  close(): Promise<boolean>;
1396
+ closeWhenFree(): boolean;
1304
1397
  content(iframeOptions?: IframeOption[]): Promise<string>;
1305
1398
  cookies(): Promise<CookieItem[]>;
1306
1399
  documentHeight(): Promise<number>;
1307
- evalute(fun: Function, args?: any[]): Promise<any>;
1400
+ evaluate(func: Function, args?: any[]): Promise<any>;
1401
+ exposeFunction(name: string, callbackFunction: Function): Promise<void>;
1308
1402
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement | null>;
1309
1403
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[]): Promise<LsdElement[]>;
1310
1404
  free(): Promise<boolean>;
@@ -1323,6 +1417,7 @@ declare class PuppeteerPage extends EventEmitter implements LsdPage {
1323
1417
  scrollBy(x: number, y: number): Promise<boolean>;
1324
1418
  scrollTo(x: number, y: number): Promise<boolean>;
1325
1419
  sendCDPMessage(method: string, params?: object | null, detach?: boolean): Promise<any>;
1420
+ setCloseWhenFree(closeWhenFree: boolean): boolean;
1326
1421
  setCookies(cookies: CookieItem[]): Promise<boolean>;
1327
1422
  setExtraHTTPHeaders(headers: Record<string, string>): Promise<boolean>;
1328
1423
  setLocalStroage(localStorageItems: LocalStorageItem[]): Promise<boolean>;
@@ -1348,6 +1443,8 @@ declare class PuppeteerElement implements LsdElement {
1348
1443
  constructor($ele: ElementHandle, frame: Frame$1);
1349
1444
  attribute(attributeName: string): Promise<string>;
1350
1445
  attributeNames(): Promise<string[]>;
1446
+ dataset(): Promise<Record<string, string>>;
1447
+ evaluate(func: Function, args?: any[]): Promise<any>;
1351
1448
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1352
1449
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1353
1450
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1367,6 +1464,9 @@ declare class PuppeteerElement implements LsdElement {
1367
1464
  _origElement(): AllElement;
1368
1465
  }
1369
1466
 
1467
+ /**
1468
+ * CheerioPage does not support iframe: https://github.com/cheeriojs/cheerio/issues/602
1469
+ */
1370
1470
  declare class CheerioPage extends EventEmitter implements LsdPage {
1371
1471
  #private;
1372
1472
  /**
@@ -1376,6 +1476,8 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1376
1476
  */
1377
1477
  constructor(html?: string, isHtml?: boolean);
1378
1478
  _origPage(): AllPage;
1479
+ addPreloadScript(): Promise<boolean>;
1480
+ addScriptTag(): Promise<AllElementHandle>;
1379
1481
  apiContext(): LsdApiContext;
1380
1482
  bringToFront(): Promise<boolean>;
1381
1483
  browserContext(): LsdBrowserContext;
@@ -1385,9 +1487,11 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1385
1487
  clearResponseInterceptions(): Promise<boolean>;
1386
1488
  clearStateData(): Promise<boolean>;
1387
1489
  close(): Promise<boolean>;
1490
+ closeWhenFree(): boolean;
1388
1491
  content(): Promise<string>;
1389
1492
  cookies(): Promise<CookieItem[]>;
1390
- evalute(): Promise<any>;
1493
+ evaluate(): Promise<any>;
1494
+ exposeFunction(): Promise<void>;
1391
1495
  findElement(selectorOrXpath: string | string[]): Promise<LsdElement | null>;
1392
1496
  findElements(selectorOrXpath: string | string[]): Promise<LsdElement[]>;
1393
1497
  free(): Promise<boolean>;
@@ -1406,6 +1510,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1406
1510
  scrollBy(): Promise<boolean>;
1407
1511
  scrollTo(): Promise<boolean>;
1408
1512
  sendCDPMessage(): Promise<any>;
1513
+ setCloseWhenFree(): boolean;
1409
1514
  setCookies(): Promise<boolean>;
1410
1515
  setExtraHTTPHeaders(): Promise<boolean>;
1411
1516
  setLocalStroage(): Promise<boolean>;
@@ -1430,6 +1535,8 @@ declare class CheerioElement implements LsdElement {
1430
1535
  constructor(node: CheerioNode);
1431
1536
  attribute(attributeName: string): Promise<string>;
1432
1537
  attributeNames(): Promise<string[]>;
1538
+ dataset(): Promise<Record<string, string>>;
1539
+ evaluate(): Promise<any>;
1433
1540
  findElement(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement | null>;
1434
1541
  findElements(selectorOrXpath: string | string[], iframeOptions?: IframeOption[], absolute?: boolean): Promise<LsdElement[]>;
1435
1542
  hasAttribute(attributeName: string): Promise<boolean>;
@@ -1460,4 +1567,4 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
1460
1567
  }
1461
1568
  declare const controller: LsdBrowserController;
1462
1569
 
1463
- 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, setControllerLogFun };
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 };