@letsscrapedata/controller 0.0.28 → 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 +43 -6
- package/dist/index.d.cts +43 -9
- package/dist/index.d.ts +43 -9
- package/dist/index.js +44 -7
- package/package.json +5 -2
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
|
}
|
|
@@ -17190,6 +17201,9 @@ var import_os = __toESM(require("os"), 1);
|
|
|
17190
17201
|
var import_puppeteer = __toESM(require("puppeteer"), 1);
|
|
17191
17202
|
var import_playwright = __toESM(require("playwright"), 1);
|
|
17192
17203
|
var import_utils15 = require("@letsscrapedata/utils");
|
|
17204
|
+
var import_puppeteer_extra = __toESM(require("puppeteer-extra"), 1);
|
|
17205
|
+
var playwrightExtra = __toESM(require("playwright-extra"), 1);
|
|
17206
|
+
var import_puppeteer_extra_plugin_stealth = __toESM(require("puppeteer-extra-plugin-stealth"), 1);
|
|
17193
17207
|
var LsdBrowserController = class _LsdBrowserController {
|
|
17194
17208
|
static #forbidConstructor = false;
|
|
17195
17209
|
#puppeteer;
|
|
@@ -17204,8 +17218,8 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17204
17218
|
throw new Error("Only one LsdBrowserController instance can be created!");
|
|
17205
17219
|
}
|
|
17206
17220
|
this.#puppeteer = import_puppeteer.default;
|
|
17207
|
-
const { chromium, firefox, webkit } = import_playwright.default;
|
|
17208
|
-
this.#playwrightBrowserTypes = { chromium, firefox, webkit };
|
|
17221
|
+
const { chromium: chromium2, firefox: firefox2, webkit: webkit2 } = import_playwright.default;
|
|
17222
|
+
this.#playwrightBrowserTypes = { chromium: chromium2, firefox: firefox2, webkit: webkit2 };
|
|
17209
17223
|
this.#osPlatform = import_os.default.platform();
|
|
17210
17224
|
this.#nextBrowserIdx = 1;
|
|
17211
17225
|
_LsdBrowserController.#forbidConstructor = true;
|
|
@@ -17231,19 +17245,35 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17231
17245
|
}
|
|
17232
17246
|
}
|
|
17233
17247
|
setPuppeteerNode(puppeteer2) {
|
|
17234
|
-
|
|
17248
|
+
if (puppeteer2) {
|
|
17249
|
+
this.#puppeteer = puppeteer2;
|
|
17250
|
+
} else {
|
|
17251
|
+
this.#puppeteer = import_puppeteer_extra.default.use((0, import_puppeteer_extra_plugin_stealth.default)());
|
|
17252
|
+
}
|
|
17235
17253
|
return true;
|
|
17236
17254
|
}
|
|
17237
17255
|
setPlaywrightBrowserType(browserType, playwrightBrowserType) {
|
|
17238
17256
|
switch (browserType) {
|
|
17239
17257
|
case "chromium":
|
|
17240
|
-
|
|
17258
|
+
if (playwrightBrowserType) {
|
|
17259
|
+
this.#playwrightBrowserTypes.chromium = playwrightBrowserType;
|
|
17260
|
+
} else {
|
|
17261
|
+
this.#playwrightBrowserTypes.chromium = playwrightExtra.chromium.use((0, import_puppeteer_extra_plugin_stealth.default)());
|
|
17262
|
+
}
|
|
17241
17263
|
break;
|
|
17242
17264
|
case "firefox":
|
|
17243
|
-
|
|
17265
|
+
if (playwrightBrowserType) {
|
|
17266
|
+
this.#playwrightBrowserTypes.firefox = playwrightBrowserType;
|
|
17267
|
+
} else {
|
|
17268
|
+
this.#playwrightBrowserTypes.firefox = playwrightExtra.firefox.use((0, import_puppeteer_extra_plugin_stealth.default)());
|
|
17269
|
+
}
|
|
17244
17270
|
break;
|
|
17245
17271
|
case "webkit":
|
|
17246
|
-
|
|
17272
|
+
if (playwrightBrowserType) {
|
|
17273
|
+
this.#playwrightBrowserTypes.webkit = playwrightBrowserType;
|
|
17274
|
+
} else {
|
|
17275
|
+
this.#playwrightBrowserTypes.webkit = playwrightExtra.webkit.use((0, import_puppeteer_extra_plugin_stealth.default)());
|
|
17276
|
+
}
|
|
17247
17277
|
break;
|
|
17248
17278
|
default:
|
|
17249
17279
|
(0, import_utils15.unreachable)(browserType);
|
|
@@ -17331,6 +17361,9 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17331
17361
|
args.push("--start-maximized");
|
|
17332
17362
|
launchOptions.defaultViewport = null;
|
|
17333
17363
|
}
|
|
17364
|
+
if (!args.includes("--no-sandbox")) {
|
|
17365
|
+
args.push("--no-sandbox");
|
|
17366
|
+
}
|
|
17334
17367
|
if (browserType === "chromium") {
|
|
17335
17368
|
if (incognito) {
|
|
17336
17369
|
args.push("--incognito");
|
|
@@ -17393,6 +17426,10 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17393
17426
|
throw new Error(`Invalid browserControllerType: ${browserControllerType} in connect`);
|
|
17394
17427
|
}
|
|
17395
17428
|
}
|
|
17429
|
+
async newApiRequestContext(options) {
|
|
17430
|
+
const apiRequestContext = await import_playwright.request.newContext(options);
|
|
17431
|
+
return apiRequestContext;
|
|
17432
|
+
}
|
|
17396
17433
|
};
|
|
17397
17434
|
var controller = new LsdBrowserController();
|
|
17398
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
|
|
927
|
+
_origBrowserContext(): AllBrowserContext;
|
|
922
928
|
}
|
|
923
929
|
interface LsdBrowser extends EventEmitter {
|
|
924
930
|
newBrowserContext(options?: LsdBrowserContextOptions): Promise<LsdBrowserContext | null>;
|
|
@@ -936,10 +942,34 @@ interface LsdBrowser extends EventEmitter {
|
|
|
936
942
|
_origBrowserContexts(): AllBrowserContext[];
|
|
937
943
|
}
|
|
938
944
|
interface LsdBrowserController$1 {
|
|
945
|
+
/**
|
|
946
|
+
* launch a new browser using related browser controller
|
|
947
|
+
* @param browserControllerType
|
|
948
|
+
* @param browserType
|
|
949
|
+
* @param options
|
|
950
|
+
*/
|
|
939
951
|
launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options?: LsdLaunchOptions): Promise<LsdBrowser>;
|
|
952
|
+
/**
|
|
953
|
+
* connect to the current browser using related browser controller
|
|
954
|
+
* @param browserControllerType
|
|
955
|
+
* @param browserType
|
|
956
|
+
* @param options
|
|
957
|
+
*/
|
|
940
958
|
connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options?: LsdConnectOptions): Promise<LsdBrowser>;
|
|
941
|
-
|
|
942
|
-
|
|
959
|
+
/**
|
|
960
|
+
*
|
|
961
|
+
* @param puppeteer null means use puppeteer-extra-plugin-stealth based on puppeteer-extra
|
|
962
|
+
*/
|
|
963
|
+
setPuppeteerNode(puppeteer: PuppeteerNode | null): boolean;
|
|
964
|
+
/**
|
|
965
|
+
*
|
|
966
|
+
* @param puppeteer null means use puppeteer-extra-plugin-stealth based on playwright-extra
|
|
967
|
+
*/
|
|
968
|
+
setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType | null): boolean;
|
|
969
|
+
/**
|
|
970
|
+
* Create a new APIRequestContext, valid in playwright;
|
|
971
|
+
*/
|
|
972
|
+
newApiRequestContext(options?: any): Promise<AllApiRequestContext>;
|
|
943
973
|
}
|
|
944
974
|
/**
|
|
945
975
|
* globObj.cfg.XXX:
|
|
@@ -1001,12 +1031,13 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
|
|
|
1001
1031
|
pages(): LsdPage[];
|
|
1002
1032
|
proxy(): Proxy | null;
|
|
1003
1033
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1004
|
-
_origBrowserContext(): AllBrowserContext
|
|
1034
|
+
_origBrowserContext(): AllBrowserContext;
|
|
1005
1035
|
}
|
|
1006
1036
|
|
|
1007
1037
|
declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
1008
1038
|
#private;
|
|
1009
1039
|
constructor(browserContext: LsdBrowserContext, page: Page, pageInfo?: PageInfo);
|
|
1040
|
+
apiRequestContext(): APIRequestContext;
|
|
1010
1041
|
bringToFront(): Promise<boolean>;
|
|
1011
1042
|
browserContext(): LsdBrowserContext;
|
|
1012
1043
|
clearCookies(): Promise<boolean>;
|
|
@@ -1109,12 +1140,13 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
|
|
|
1109
1140
|
pages(): LsdPage[];
|
|
1110
1141
|
proxy(): Proxy | null;
|
|
1111
1142
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1112
|
-
_origBrowserContext(): AllBrowserContext
|
|
1143
|
+
_origBrowserContext(): AllBrowserContext;
|
|
1113
1144
|
}
|
|
1114
1145
|
|
|
1115
1146
|
declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
1116
1147
|
#private;
|
|
1117
1148
|
constructor(browserContext: LsdBrowserContext, page: Page$1, pageInfo?: PageInfo);
|
|
1149
|
+
apiRequestContext(): APIRequestContext;
|
|
1118
1150
|
bringToFront(): Promise<boolean>;
|
|
1119
1151
|
browserContext(): LsdBrowserContext;
|
|
1120
1152
|
clearCookies(): Promise<boolean>;
|
|
@@ -1193,6 +1225,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1193
1225
|
* @param isHtml default true
|
|
1194
1226
|
*/
|
|
1195
1227
|
constructor(html?: string, isHtml?: boolean);
|
|
1228
|
+
apiRequestContext(): APIRequestContext;
|
|
1196
1229
|
bringToFront(): Promise<boolean>;
|
|
1197
1230
|
browserContext(): LsdBrowserContext;
|
|
1198
1231
|
clearCookies(): Promise<boolean>;
|
|
@@ -1265,11 +1298,12 @@ declare class CheerioElement implements LsdElement {
|
|
|
1265
1298
|
declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
1266
1299
|
#private;
|
|
1267
1300
|
constructor();
|
|
1268
|
-
setPuppeteerNode(puppeteer: PuppeteerNode): boolean;
|
|
1269
|
-
setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType): boolean;
|
|
1301
|
+
setPuppeteerNode(puppeteer: PuppeteerNode | null): boolean;
|
|
1302
|
+
setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType | null): boolean;
|
|
1270
1303
|
launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdLaunchOptions): Promise<LsdBrowser>;
|
|
1271
1304
|
connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdConnectOptions): Promise<LsdBrowser>;
|
|
1305
|
+
newApiRequestContext(options?: any): Promise<AllApiRequestContext>;
|
|
1272
1306
|
}
|
|
1273
1307
|
declare const controller: LsdBrowserController;
|
|
1274
1308
|
|
|
1275
|
-
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
|
|
927
|
+
_origBrowserContext(): AllBrowserContext;
|
|
922
928
|
}
|
|
923
929
|
interface LsdBrowser extends EventEmitter {
|
|
924
930
|
newBrowserContext(options?: LsdBrowserContextOptions): Promise<LsdBrowserContext | null>;
|
|
@@ -936,10 +942,34 @@ interface LsdBrowser extends EventEmitter {
|
|
|
936
942
|
_origBrowserContexts(): AllBrowserContext[];
|
|
937
943
|
}
|
|
938
944
|
interface LsdBrowserController$1 {
|
|
945
|
+
/**
|
|
946
|
+
* launch a new browser using related browser controller
|
|
947
|
+
* @param browserControllerType
|
|
948
|
+
* @param browserType
|
|
949
|
+
* @param options
|
|
950
|
+
*/
|
|
939
951
|
launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options?: LsdLaunchOptions): Promise<LsdBrowser>;
|
|
952
|
+
/**
|
|
953
|
+
* connect to the current browser using related browser controller
|
|
954
|
+
* @param browserControllerType
|
|
955
|
+
* @param browserType
|
|
956
|
+
* @param options
|
|
957
|
+
*/
|
|
940
958
|
connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options?: LsdConnectOptions): Promise<LsdBrowser>;
|
|
941
|
-
|
|
942
|
-
|
|
959
|
+
/**
|
|
960
|
+
*
|
|
961
|
+
* @param puppeteer null means use puppeteer-extra-plugin-stealth based on puppeteer-extra
|
|
962
|
+
*/
|
|
963
|
+
setPuppeteerNode(puppeteer: PuppeteerNode | null): boolean;
|
|
964
|
+
/**
|
|
965
|
+
*
|
|
966
|
+
* @param puppeteer null means use puppeteer-extra-plugin-stealth based on playwright-extra
|
|
967
|
+
*/
|
|
968
|
+
setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType | null): boolean;
|
|
969
|
+
/**
|
|
970
|
+
* Create a new APIRequestContext, valid in playwright;
|
|
971
|
+
*/
|
|
972
|
+
newApiRequestContext(options?: any): Promise<AllApiRequestContext>;
|
|
943
973
|
}
|
|
944
974
|
/**
|
|
945
975
|
* globObj.cfg.XXX:
|
|
@@ -1001,12 +1031,13 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
|
|
|
1001
1031
|
pages(): LsdPage[];
|
|
1002
1032
|
proxy(): Proxy | null;
|
|
1003
1033
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1004
|
-
_origBrowserContext(): AllBrowserContext
|
|
1034
|
+
_origBrowserContext(): AllBrowserContext;
|
|
1005
1035
|
}
|
|
1006
1036
|
|
|
1007
1037
|
declare class PlaywrightPage extends EventEmitter implements LsdPage {
|
|
1008
1038
|
#private;
|
|
1009
1039
|
constructor(browserContext: LsdBrowserContext, page: Page, pageInfo?: PageInfo);
|
|
1040
|
+
apiRequestContext(): APIRequestContext;
|
|
1010
1041
|
bringToFront(): Promise<boolean>;
|
|
1011
1042
|
browserContext(): LsdBrowserContext;
|
|
1012
1043
|
clearCookies(): Promise<boolean>;
|
|
@@ -1109,12 +1140,13 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
|
|
|
1109
1140
|
pages(): LsdPage[];
|
|
1110
1141
|
proxy(): Proxy | null;
|
|
1111
1142
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1112
|
-
_origBrowserContext(): AllBrowserContext
|
|
1143
|
+
_origBrowserContext(): AllBrowserContext;
|
|
1113
1144
|
}
|
|
1114
1145
|
|
|
1115
1146
|
declare class PuppeteerPage extends EventEmitter implements LsdPage {
|
|
1116
1147
|
#private;
|
|
1117
1148
|
constructor(browserContext: LsdBrowserContext, page: Page$1, pageInfo?: PageInfo);
|
|
1149
|
+
apiRequestContext(): APIRequestContext;
|
|
1118
1150
|
bringToFront(): Promise<boolean>;
|
|
1119
1151
|
browserContext(): LsdBrowserContext;
|
|
1120
1152
|
clearCookies(): Promise<boolean>;
|
|
@@ -1193,6 +1225,7 @@ declare class CheerioPage extends EventEmitter implements LsdPage {
|
|
|
1193
1225
|
* @param isHtml default true
|
|
1194
1226
|
*/
|
|
1195
1227
|
constructor(html?: string, isHtml?: boolean);
|
|
1228
|
+
apiRequestContext(): APIRequestContext;
|
|
1196
1229
|
bringToFront(): Promise<boolean>;
|
|
1197
1230
|
browserContext(): LsdBrowserContext;
|
|
1198
1231
|
clearCookies(): Promise<boolean>;
|
|
@@ -1265,11 +1298,12 @@ declare class CheerioElement implements LsdElement {
|
|
|
1265
1298
|
declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
1266
1299
|
#private;
|
|
1267
1300
|
constructor();
|
|
1268
|
-
setPuppeteerNode(puppeteer: PuppeteerNode): boolean;
|
|
1269
|
-
setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType): boolean;
|
|
1301
|
+
setPuppeteerNode(puppeteer: PuppeteerNode | null): boolean;
|
|
1302
|
+
setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType | null): boolean;
|
|
1270
1303
|
launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdLaunchOptions): Promise<LsdBrowser>;
|
|
1271
1304
|
connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdConnectOptions): Promise<LsdBrowser>;
|
|
1305
|
+
newApiRequestContext(options?: any): Promise<AllApiRequestContext>;
|
|
1272
1306
|
}
|
|
1273
1307
|
declare const controller: LsdBrowserController;
|
|
1274
1308
|
|
|
1275
|
-
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,8 +17179,11 @@ 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";
|
|
17184
|
+
import puppeteerExtra from "puppeteer-extra";
|
|
17185
|
+
import * as playwrightExtra from "playwright-extra";
|
|
17186
|
+
import StealthPlugin from "puppeteer-extra-plugin-stealth";
|
|
17173
17187
|
var LsdBrowserController = class _LsdBrowserController {
|
|
17174
17188
|
static #forbidConstructor = false;
|
|
17175
17189
|
#puppeteer;
|
|
@@ -17184,8 +17198,8 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17184
17198
|
throw new Error("Only one LsdBrowserController instance can be created!");
|
|
17185
17199
|
}
|
|
17186
17200
|
this.#puppeteer = puppeteer;
|
|
17187
|
-
const { chromium, firefox, webkit } = playwright;
|
|
17188
|
-
this.#playwrightBrowserTypes = { chromium, firefox, webkit };
|
|
17201
|
+
const { chromium: chromium2, firefox: firefox2, webkit: webkit2 } = playwright;
|
|
17202
|
+
this.#playwrightBrowserTypes = { chromium: chromium2, firefox: firefox2, webkit: webkit2 };
|
|
17189
17203
|
this.#osPlatform = os.platform();
|
|
17190
17204
|
this.#nextBrowserIdx = 1;
|
|
17191
17205
|
_LsdBrowserController.#forbidConstructor = true;
|
|
@@ -17211,19 +17225,35 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17211
17225
|
}
|
|
17212
17226
|
}
|
|
17213
17227
|
setPuppeteerNode(puppeteer2) {
|
|
17214
|
-
|
|
17228
|
+
if (puppeteer2) {
|
|
17229
|
+
this.#puppeteer = puppeteer2;
|
|
17230
|
+
} else {
|
|
17231
|
+
this.#puppeteer = puppeteerExtra.use(StealthPlugin());
|
|
17232
|
+
}
|
|
17215
17233
|
return true;
|
|
17216
17234
|
}
|
|
17217
17235
|
setPlaywrightBrowserType(browserType, playwrightBrowserType) {
|
|
17218
17236
|
switch (browserType) {
|
|
17219
17237
|
case "chromium":
|
|
17220
|
-
|
|
17238
|
+
if (playwrightBrowserType) {
|
|
17239
|
+
this.#playwrightBrowserTypes.chromium = playwrightBrowserType;
|
|
17240
|
+
} else {
|
|
17241
|
+
this.#playwrightBrowserTypes.chromium = playwrightExtra.chromium.use(StealthPlugin());
|
|
17242
|
+
}
|
|
17221
17243
|
break;
|
|
17222
17244
|
case "firefox":
|
|
17223
|
-
|
|
17245
|
+
if (playwrightBrowserType) {
|
|
17246
|
+
this.#playwrightBrowserTypes.firefox = playwrightBrowserType;
|
|
17247
|
+
} else {
|
|
17248
|
+
this.#playwrightBrowserTypes.firefox = playwrightExtra.firefox.use(StealthPlugin());
|
|
17249
|
+
}
|
|
17224
17250
|
break;
|
|
17225
17251
|
case "webkit":
|
|
17226
|
-
|
|
17252
|
+
if (playwrightBrowserType) {
|
|
17253
|
+
this.#playwrightBrowserTypes.webkit = playwrightBrowserType;
|
|
17254
|
+
} else {
|
|
17255
|
+
this.#playwrightBrowserTypes.webkit = playwrightExtra.webkit.use(StealthPlugin());
|
|
17256
|
+
}
|
|
17227
17257
|
break;
|
|
17228
17258
|
default:
|
|
17229
17259
|
unreachable5(browserType);
|
|
@@ -17311,6 +17341,9 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17311
17341
|
args.push("--start-maximized");
|
|
17312
17342
|
launchOptions.defaultViewport = null;
|
|
17313
17343
|
}
|
|
17344
|
+
if (!args.includes("--no-sandbox")) {
|
|
17345
|
+
args.push("--no-sandbox");
|
|
17346
|
+
}
|
|
17314
17347
|
if (browserType === "chromium") {
|
|
17315
17348
|
if (incognito) {
|
|
17316
17349
|
args.push("--incognito");
|
|
@@ -17373,6 +17406,10 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17373
17406
|
throw new Error(`Invalid browserControllerType: ${browserControllerType} in connect`);
|
|
17374
17407
|
}
|
|
17375
17408
|
}
|
|
17409
|
+
async newApiRequestContext(options) {
|
|
17410
|
+
const apiRequestContext = await apiRequest.newContext(options);
|
|
17411
|
+
return apiRequestContext;
|
|
17412
|
+
}
|
|
17376
17413
|
};
|
|
17377
17414
|
var controller = new LsdBrowserController();
|
|
17378
17415
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@letsscrapedata/controller",
|
|
3
|
-
"version": "0.0.
|
|
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",
|
|
@@ -36,7 +36,10 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@letsscrapedata/utils": "^0.0.7",
|
|
38
38
|
"playwright": "^1.43.0",
|
|
39
|
-
"
|
|
39
|
+
"playwright-extra": "^4.3.6",
|
|
40
|
+
"puppeteer": "^22.6.3",
|
|
41
|
+
"puppeteer-extra": "^3.3.6",
|
|
42
|
+
"puppeteer-extra-plugin-stealth": "^2.11.2"
|
|
40
43
|
},
|
|
41
44
|
"devDependencies": {
|
|
42
45
|
"tsup": "^8.0.2"
|