@letsscrapedata/controller 0.0.29 → 0.0.30

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 CHANGED
@@ -545,6 +545,11 @@ var PlaywrightPage = class extends import_node_events.default {
545
545
  this.#responseCb = null;
546
546
  this.#addPageOn();
547
547
  }
548
+ apiRequestContext() {
549
+ const origBrowserContext = this.browserContext()._origBrowserContext();
550
+ const apiRequestContext = origBrowserContext.request;
551
+ return apiRequestContext;
552
+ }
548
553
  async bringToFront() {
549
554
  if (!this.#page) {
550
555
  throw new Error("No valid page");
@@ -2026,6 +2031,9 @@ var PuppeteerPage = class extends import_node_events4.default {
2026
2031
  this.#client = null;
2027
2032
  this.#addPageOn();
2028
2033
  }
2034
+ apiRequestContext() {
2035
+ throw new Error("Not supported in PuppeteerPage.");
2036
+ }
2029
2037
  async bringToFront() {
2030
2038
  if (!this.#page) {
2031
2039
  throw new Error("No valid page");
@@ -17008,6 +17016,9 @@ var CheerioPage = class extends import_node_events7.default {
17008
17016
  this.#document = load(html3, { xml: true }).root();
17009
17017
  }
17010
17018
  }
17019
+ apiRequestContext() {
17020
+ throw new Error("Not supported in CheerioPage.");
17021
+ }
17011
17022
  async bringToFront() {
17012
17023
  throw new Error("Not supported in CheerioPage.");
17013
17024
  }
@@ -17350,6 +17361,9 @@ var LsdBrowserController = class _LsdBrowserController {
17350
17361
  args.push("--start-maximized");
17351
17362
  launchOptions.defaultViewport = null;
17352
17363
  }
17364
+ if (!args.includes("--no-sandbox")) {
17365
+ args.push("--no-sandbox");
17366
+ }
17353
17367
  if (browserType === "chromium") {
17354
17368
  if (incognito) {
17355
17369
  args.push("--incognito");
@@ -17412,6 +17426,10 @@ var LsdBrowserController = class _LsdBrowserController {
17412
17426
  throw new Error(`Invalid browserControllerType: ${browserControllerType} in connect`);
17413
17427
  }
17414
17428
  }
17429
+ async newApiRequestContext(options) {
17430
+ const apiRequestContext = await import_playwright.request.newContext(options);
17431
+ return apiRequestContext;
17432
+ }
17415
17433
  };
17416
17434
  var controller = new LsdBrowserController();
17417
17435
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import EventEmitter from 'node:events';
2
2
  import { Browser as Browser$1, BrowserContext as BrowserContext$1, Frame as Frame$1, Page as Page$1, HTTPResponse, PuppeteerNode, ElementHandle } from 'puppeteer';
3
- import { Browser, BrowserContext, Frame, Page, Response, BrowserType, Locator } from 'playwright';
3
+ import { Browser, BrowserContext, Frame, Page, Response, APIRequestContext, BrowserType, Locator } from 'playwright';
4
4
  import * as cheerio from 'cheerio';
5
5
 
6
6
  /**
@@ -15,6 +15,7 @@ type AllBrowserContext = BrowserContext | BrowserContext$1;
15
15
  type AllFrame = Frame | Frame$1;
16
16
  type AllPage = Page | Page$1;
17
17
  type AllResponse = Response | HTTPResponse;
18
+ type AllApiRequestContext = APIRequestContext;
18
19
  type CheerioNode = cheerio.Cheerio<cheerio.Element>;
19
20
  type Proxy = {
20
21
  server: string;
@@ -772,6 +773,11 @@ interface WaitNavigationOptions {
772
773
  }
773
774
  type PageEvent = "pageClose" | "pagePopup";
774
775
  interface LsdPage extends EventEmitter {
776
+ /**
777
+ * Get the APIRequestContext associated with this page's browser context.
778
+ * * only vaild in playwright
779
+ */
780
+ apiRequestContext(): AllApiRequestContext;
775
781
  bringToFront(): Promise<boolean>;
776
782
  browserContext(): LsdBrowserContext;
777
783
  clearCookies(): Promise<boolean>;
@@ -918,7 +924,7 @@ interface LsdBrowserContext extends EventEmitter {
918
924
  pages(): LsdPage[];
919
925
  proxy(): Proxy | null;
920
926
  setStateData(stateData: StateData): Promise<boolean>;
921
- _origBrowserContext(): AllBrowserContext | null;
927
+ _origBrowserContext(): AllBrowserContext;
922
928
  }
923
929
  interface LsdBrowser extends EventEmitter {
924
930
  newBrowserContext(options?: LsdBrowserContextOptions): Promise<LsdBrowserContext | null>;
@@ -960,6 +966,10 @@ interface LsdBrowserController$1 {
960
966
  * @param puppeteer null means use puppeteer-extra-plugin-stealth based on playwright-extra
961
967
  */
962
968
  setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType | null): boolean;
969
+ /**
970
+ * Create a new APIRequestContext, valid in playwright;
971
+ */
972
+ newApiRequestContext(options?: any): Promise<AllApiRequestContext>;
963
973
  }
964
974
  /**
965
975
  * globObj.cfg.XXX:
@@ -1021,12 +1031,13 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
1021
1031
  pages(): LsdPage[];
1022
1032
  proxy(): Proxy | null;
1023
1033
  setStateData(stateData: StateData): Promise<boolean>;
1024
- _origBrowserContext(): AllBrowserContext | null;
1034
+ _origBrowserContext(): AllBrowserContext;
1025
1035
  }
1026
1036
 
1027
1037
  declare class PlaywrightPage extends EventEmitter implements LsdPage {
1028
1038
  #private;
1029
1039
  constructor(browserContext: LsdBrowserContext, page: Page, pageInfo?: PageInfo);
1040
+ apiRequestContext(): APIRequestContext;
1030
1041
  bringToFront(): Promise<boolean>;
1031
1042
  browserContext(): LsdBrowserContext;
1032
1043
  clearCookies(): Promise<boolean>;
@@ -1129,12 +1140,13 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
1129
1140
  pages(): LsdPage[];
1130
1141
  proxy(): Proxy | null;
1131
1142
  setStateData(stateData: StateData): Promise<boolean>;
1132
- _origBrowserContext(): AllBrowserContext | null;
1143
+ _origBrowserContext(): AllBrowserContext;
1133
1144
  }
1134
1145
 
1135
1146
  declare class PuppeteerPage extends EventEmitter implements LsdPage {
1136
1147
  #private;
1137
1148
  constructor(browserContext: LsdBrowserContext, page: Page$1, pageInfo?: PageInfo);
1149
+ apiRequestContext(): APIRequestContext;
1138
1150
  bringToFront(): Promise<boolean>;
1139
1151
  browserContext(): LsdBrowserContext;
1140
1152
  clearCookies(): Promise<boolean>;
@@ -1213,6 +1225,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1213
1225
  * @param isHtml default true
1214
1226
  */
1215
1227
  constructor(html?: string, isHtml?: boolean);
1228
+ apiRequestContext(): APIRequestContext;
1216
1229
  bringToFront(): Promise<boolean>;
1217
1230
  browserContext(): LsdBrowserContext;
1218
1231
  clearCookies(): Promise<boolean>;
@@ -1289,7 +1302,8 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
1289
1302
  setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType | null): boolean;
1290
1303
  launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdLaunchOptions): Promise<LsdBrowser>;
1291
1304
  connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdConnectOptions): Promise<LsdBrowser>;
1305
+ newApiRequestContext(options?: any): Promise<AllApiRequestContext>;
1292
1306
  }
1293
1307
  declare const controller: LsdBrowserController;
1294
1308
 
1295
- 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$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type 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, controller, defaultProxy };
1309
+ export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, CheerioElement, type CheerioNode, CheerioPage, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type 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, controller, defaultProxy };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import EventEmitter from 'node:events';
2
2
  import { Browser as Browser$1, BrowserContext as BrowserContext$1, Frame as Frame$1, Page as Page$1, HTTPResponse, PuppeteerNode, ElementHandle } from 'puppeteer';
3
- import { Browser, BrowserContext, Frame, Page, Response, BrowserType, Locator } from 'playwright';
3
+ import { Browser, BrowserContext, Frame, Page, Response, APIRequestContext, BrowserType, Locator } from 'playwright';
4
4
  import * as cheerio from 'cheerio';
5
5
 
6
6
  /**
@@ -15,6 +15,7 @@ type AllBrowserContext = BrowserContext | BrowserContext$1;
15
15
  type AllFrame = Frame | Frame$1;
16
16
  type AllPage = Page | Page$1;
17
17
  type AllResponse = Response | HTTPResponse;
18
+ type AllApiRequestContext = APIRequestContext;
18
19
  type CheerioNode = cheerio.Cheerio<cheerio.Element>;
19
20
  type Proxy = {
20
21
  server: string;
@@ -772,6 +773,11 @@ interface WaitNavigationOptions {
772
773
  }
773
774
  type PageEvent = "pageClose" | "pagePopup";
774
775
  interface LsdPage extends EventEmitter {
776
+ /**
777
+ * Get the APIRequestContext associated with this page's browser context.
778
+ * * only vaild in playwright
779
+ */
780
+ apiRequestContext(): AllApiRequestContext;
775
781
  bringToFront(): Promise<boolean>;
776
782
  browserContext(): LsdBrowserContext;
777
783
  clearCookies(): Promise<boolean>;
@@ -918,7 +924,7 @@ interface LsdBrowserContext extends EventEmitter {
918
924
  pages(): LsdPage[];
919
925
  proxy(): Proxy | null;
920
926
  setStateData(stateData: StateData): Promise<boolean>;
921
- _origBrowserContext(): AllBrowserContext | null;
927
+ _origBrowserContext(): AllBrowserContext;
922
928
  }
923
929
  interface LsdBrowser extends EventEmitter {
924
930
  newBrowserContext(options?: LsdBrowserContextOptions): Promise<LsdBrowserContext | null>;
@@ -960,6 +966,10 @@ interface LsdBrowserController$1 {
960
966
  * @param puppeteer null means use puppeteer-extra-plugin-stealth based on playwright-extra
961
967
  */
962
968
  setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType | null): boolean;
969
+ /**
970
+ * Create a new APIRequestContext, valid in playwright;
971
+ */
972
+ newApiRequestContext(options?: any): Promise<AllApiRequestContext>;
963
973
  }
964
974
  /**
965
975
  * globObj.cfg.XXX:
@@ -1021,12 +1031,13 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
1021
1031
  pages(): LsdPage[];
1022
1032
  proxy(): Proxy | null;
1023
1033
  setStateData(stateData: StateData): Promise<boolean>;
1024
- _origBrowserContext(): AllBrowserContext | null;
1034
+ _origBrowserContext(): AllBrowserContext;
1025
1035
  }
1026
1036
 
1027
1037
  declare class PlaywrightPage extends EventEmitter implements LsdPage {
1028
1038
  #private;
1029
1039
  constructor(browserContext: LsdBrowserContext, page: Page, pageInfo?: PageInfo);
1040
+ apiRequestContext(): APIRequestContext;
1030
1041
  bringToFront(): Promise<boolean>;
1031
1042
  browserContext(): LsdBrowserContext;
1032
1043
  clearCookies(): Promise<boolean>;
@@ -1129,12 +1140,13 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
1129
1140
  pages(): LsdPage[];
1130
1141
  proxy(): Proxy | null;
1131
1142
  setStateData(stateData: StateData): Promise<boolean>;
1132
- _origBrowserContext(): AllBrowserContext | null;
1143
+ _origBrowserContext(): AllBrowserContext;
1133
1144
  }
1134
1145
 
1135
1146
  declare class PuppeteerPage extends EventEmitter implements LsdPage {
1136
1147
  #private;
1137
1148
  constructor(browserContext: LsdBrowserContext, page: Page$1, pageInfo?: PageInfo);
1149
+ apiRequestContext(): APIRequestContext;
1138
1150
  bringToFront(): Promise<boolean>;
1139
1151
  browserContext(): LsdBrowserContext;
1140
1152
  clearCookies(): Promise<boolean>;
@@ -1213,6 +1225,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
1213
1225
  * @param isHtml default true
1214
1226
  */
1215
1227
  constructor(html?: string, isHtml?: boolean);
1228
+ apiRequestContext(): APIRequestContext;
1216
1229
  bringToFront(): Promise<boolean>;
1217
1230
  browserContext(): LsdBrowserContext;
1218
1231
  clearCookies(): Promise<boolean>;
@@ -1289,7 +1302,8 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
1289
1302
  setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType | null): boolean;
1290
1303
  launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdLaunchOptions): Promise<LsdBrowser>;
1291
1304
  connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdConnectOptions): Promise<LsdBrowser>;
1305
+ newApiRequestContext(options?: any): Promise<AllApiRequestContext>;
1292
1306
  }
1293
1307
  declare const controller: LsdBrowserController;
1294
1308
 
1295
- 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$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type 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, controller, defaultProxy };
1309
+ export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, CheerioElement, type CheerioNode, CheerioPage, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type 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, controller, defaultProxy };
package/dist/index.js CHANGED
@@ -525,6 +525,11 @@ var PlaywrightPage = class extends EventEmitter {
525
525
  this.#responseCb = null;
526
526
  this.#addPageOn();
527
527
  }
528
+ apiRequestContext() {
529
+ const origBrowserContext = this.browserContext()._origBrowserContext();
530
+ const apiRequestContext = origBrowserContext.request;
531
+ return apiRequestContext;
532
+ }
528
533
  async bringToFront() {
529
534
  if (!this.#page) {
530
535
  throw new Error("No valid page");
@@ -2006,6 +2011,9 @@ var PuppeteerPage = class extends EventEmitter4 {
2006
2011
  this.#client = null;
2007
2012
  this.#addPageOn();
2008
2013
  }
2014
+ apiRequestContext() {
2015
+ throw new Error("Not supported in PuppeteerPage.");
2016
+ }
2009
2017
  async bringToFront() {
2010
2018
  if (!this.#page) {
2011
2019
  throw new Error("No valid page");
@@ -16988,6 +16996,9 @@ var CheerioPage = class extends EventEmitter7 {
16988
16996
  this.#document = load(html3, { xml: true }).root();
16989
16997
  }
16990
16998
  }
16999
+ apiRequestContext() {
17000
+ throw new Error("Not supported in CheerioPage.");
17001
+ }
16991
17002
  async bringToFront() {
16992
17003
  throw new Error("Not supported in CheerioPage.");
16993
17004
  }
@@ -17168,7 +17179,7 @@ var CheerioPage = class extends EventEmitter7 {
17168
17179
  // src/controller/controller.ts
17169
17180
  import os from "os";
17170
17181
  import puppeteer from "puppeteer";
17171
- import playwright from "playwright";
17182
+ import playwright, { request as apiRequest } from "playwright";
17172
17183
  import { logwarn as logwarn6, unreachable as unreachable5 } from "@letsscrapedata/utils";
17173
17184
  import puppeteerExtra from "puppeteer-extra";
17174
17185
  import * as playwrightExtra from "playwright-extra";
@@ -17330,6 +17341,9 @@ var LsdBrowserController = class _LsdBrowserController {
17330
17341
  args.push("--start-maximized");
17331
17342
  launchOptions.defaultViewport = null;
17332
17343
  }
17344
+ if (!args.includes("--no-sandbox")) {
17345
+ args.push("--no-sandbox");
17346
+ }
17333
17347
  if (browserType === "chromium") {
17334
17348
  if (incognito) {
17335
17349
  args.push("--incognito");
@@ -17392,6 +17406,10 @@ var LsdBrowserController = class _LsdBrowserController {
17392
17406
  throw new Error(`Invalid browserControllerType: ${browserControllerType} in connect`);
17393
17407
  }
17394
17408
  }
17409
+ async newApiRequestContext(options) {
17410
+ const apiRequestContext = await apiRequest.newContext(options);
17411
+ return apiRequestContext;
17412
+ }
17395
17413
  };
17396
17414
  var controller = new LsdBrowserController();
17397
17415
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letsscrapedata/controller",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "description": "Unified browser / HTML controller interfaces that support playwright, puppeteer and cheerio",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",