@letsscrapedata/controller 0.0.26 → 0.0.28
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 +36 -11
- package/dist/index.d.cts +14 -5
- package/dist/index.d.ts +14 -5
- package/dist/index.js +37 -12
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1416,7 +1416,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1416
1416
|
throw new Error(`Invalid playwright browser parameter`);
|
|
1417
1417
|
}
|
|
1418
1418
|
super();
|
|
1419
|
-
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage =
|
|
1419
|
+
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage = true, headless = false, executablePath = "" } = options;
|
|
1420
1420
|
this.#browser = browser;
|
|
1421
1421
|
this.#browserIdx = browserIdx;
|
|
1422
1422
|
this.#lsdBrowserContexts = [];
|
|
@@ -2900,7 +2900,7 @@ var PuppeteerBrowser = class extends import_node_events6.default {
|
|
|
2900
2900
|
throw new Error(`Invalid puppeteer browser parameter`);
|
|
2901
2901
|
}
|
|
2902
2902
|
super();
|
|
2903
|
-
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage =
|
|
2903
|
+
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage = true, headless = false, executablePath = "" } = options;
|
|
2904
2904
|
this.#browser = browser;
|
|
2905
2905
|
this.#browserIdx = browserIdx;
|
|
2906
2906
|
this.#lsdBrowserContexts = [];
|
|
@@ -17192,6 +17192,8 @@ var import_playwright = __toESM(require("playwright"), 1);
|
|
|
17192
17192
|
var import_utils15 = require("@letsscrapedata/utils");
|
|
17193
17193
|
var LsdBrowserController = class _LsdBrowserController {
|
|
17194
17194
|
static #forbidConstructor = false;
|
|
17195
|
+
#puppeteer;
|
|
17196
|
+
#playwrightBrowserTypes;
|
|
17195
17197
|
#nextBrowserIdx;
|
|
17196
17198
|
/**
|
|
17197
17199
|
* Possible values are 'aix', 'darwin', 'freebsd','linux', 'openbsd', 'sunos', and 'win32'.
|
|
@@ -17201,19 +17203,22 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17201
17203
|
if (_LsdBrowserController.#forbidConstructor) {
|
|
17202
17204
|
throw new Error("Only one LsdBrowserController instance can be created!");
|
|
17203
17205
|
}
|
|
17206
|
+
this.#puppeteer = import_puppeteer.default;
|
|
17207
|
+
const { chromium, firefox, webkit } = import_playwright.default;
|
|
17208
|
+
this.#playwrightBrowserTypes = { chromium, firefox, webkit };
|
|
17204
17209
|
this.#osPlatform = import_os.default.platform();
|
|
17205
17210
|
this.#nextBrowserIdx = 1;
|
|
17206
17211
|
_LsdBrowserController.#forbidConstructor = true;
|
|
17207
17212
|
}
|
|
17208
17213
|
#playwrightBrowserType(browserType, connectFlag = false) {
|
|
17209
17214
|
if (browserType === "chromium") {
|
|
17210
|
-
return
|
|
17215
|
+
return this.#playwrightBrowserTypes.chromium;
|
|
17211
17216
|
} else if (connectFlag) {
|
|
17212
17217
|
throw new Error(`playwright only can connect to chromium browser, not support ${browserType} browser`);
|
|
17213
17218
|
} else if (browserType === "firefox") {
|
|
17214
|
-
return
|
|
17219
|
+
return this.#playwrightBrowserTypes.firefox;
|
|
17215
17220
|
} else if (browserType === "webkit") {
|
|
17216
|
-
return
|
|
17221
|
+
return this.#playwrightBrowserTypes.webkit;
|
|
17217
17222
|
} else {
|
|
17218
17223
|
throw new Error(`Invalid playwright browserType ${browserType}`);
|
|
17219
17224
|
}
|
|
@@ -17225,18 +17230,38 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17225
17230
|
throw new Error(`Invalid puppeteer product ${browserType}`);
|
|
17226
17231
|
}
|
|
17227
17232
|
}
|
|
17233
|
+
setPuppeteerNode(puppeteer2) {
|
|
17234
|
+
this.#puppeteer = puppeteer2;
|
|
17235
|
+
return true;
|
|
17236
|
+
}
|
|
17237
|
+
setPlaywrightBrowserType(browserType, playwrightBrowserType) {
|
|
17238
|
+
switch (browserType) {
|
|
17239
|
+
case "chromium":
|
|
17240
|
+
this.#playwrightBrowserTypes.chromium = playwrightBrowserType;
|
|
17241
|
+
break;
|
|
17242
|
+
case "firefox":
|
|
17243
|
+
this.#playwrightBrowserTypes.firefox = playwrightBrowserType;
|
|
17244
|
+
break;
|
|
17245
|
+
case "webkit":
|
|
17246
|
+
this.#playwrightBrowserTypes.webkit = playwrightBrowserType;
|
|
17247
|
+
break;
|
|
17248
|
+
default:
|
|
17249
|
+
(0, import_utils15.unreachable)(browserType);
|
|
17250
|
+
}
|
|
17251
|
+
return true;
|
|
17252
|
+
}
|
|
17228
17253
|
async launch(browserControllerType, browserType, options) {
|
|
17229
17254
|
let {
|
|
17230
17255
|
closeFreePagesIntervalSeconds = 300,
|
|
17231
17256
|
maxBrowserContextsPerBrowser = 10,
|
|
17232
17257
|
maxPagesPerBrowserContext = 20,
|
|
17233
17258
|
maxPageFreeSeconds = 900,
|
|
17234
|
-
maxViewportOfNewPage =
|
|
17259
|
+
maxViewportOfNewPage = true,
|
|
17235
17260
|
proxy = null,
|
|
17236
17261
|
timeout = 3e4,
|
|
17237
17262
|
args = [],
|
|
17238
17263
|
executablePath = "",
|
|
17239
|
-
maxWindowSize =
|
|
17264
|
+
maxWindowSize = true,
|
|
17240
17265
|
headless = true,
|
|
17241
17266
|
minBrowserContexts = 1,
|
|
17242
17267
|
// incognito
|
|
@@ -17322,9 +17347,9 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17322
17347
|
launchOptions.args = args;
|
|
17323
17348
|
}
|
|
17324
17349
|
if (!actOptions.executablePath) {
|
|
17325
|
-
actOptions.executablePath =
|
|
17350
|
+
actOptions.executablePath = this.#puppeteer.executablePath();
|
|
17326
17351
|
}
|
|
17327
|
-
const browser = await
|
|
17352
|
+
const browser = await this.#puppeteer.launch(launchOptions);
|
|
17328
17353
|
lsdBrowser = new PuppeteerBrowser(browser, browserType, "launch", actOptions, this.#nextBrowserIdx++);
|
|
17329
17354
|
} else {
|
|
17330
17355
|
throw new Error(`Invalid browserControllerType: ${browserControllerType} in launch`);
|
|
@@ -17340,7 +17365,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17340
17365
|
maxBrowserContextsPerBrowser = 10,
|
|
17341
17366
|
maxPagesPerBrowserContext = 20,
|
|
17342
17367
|
maxPageFreeSeconds = 900,
|
|
17343
|
-
maxViewportOfNewPage =
|
|
17368
|
+
maxViewportOfNewPage = true,
|
|
17344
17369
|
proxy = null,
|
|
17345
17370
|
timeout = 3e4,
|
|
17346
17371
|
browserUrl,
|
|
@@ -17360,7 +17385,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17360
17385
|
return lsdBrowser;
|
|
17361
17386
|
} else if (browserControllerType === "puppeteer") {
|
|
17362
17387
|
this.#puppeteerProduct(browserType);
|
|
17363
|
-
const browser = await
|
|
17388
|
+
const browser = await this.#puppeteer.connect({ browserURL: browserUrl });
|
|
17364
17389
|
const lsdBrowser = new PuppeteerBrowser(browser, browserType, "connect", options, this.#nextBrowserIdx++);
|
|
17365
17390
|
;
|
|
17366
17391
|
return lsdBrowser;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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, HTTPResponse, ElementHandle } from 'puppeteer';
|
|
3
|
-
import { Browser, BrowserContext, Frame, Page, Response, Locator } from 'playwright';
|
|
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';
|
|
4
4
|
import * as cheerio from 'cheerio';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -36,6 +36,11 @@ type Proxy = {
|
|
|
36
36
|
type BrowserControllerType = "puppeteer" | "playwright";
|
|
37
37
|
type BrowserCreationMethod = "launch" | "connect";
|
|
38
38
|
type LsdBrowserType = "chromium" | "firefox" | "webkit";
|
|
39
|
+
interface PlaywrightBrowserTypes {
|
|
40
|
+
chromium: BrowserType;
|
|
41
|
+
firefox: BrowserType;
|
|
42
|
+
webkit: BrowserType;
|
|
43
|
+
}
|
|
39
44
|
type BrowserControllerOptions = {
|
|
40
45
|
browserControllerType: BrowserControllerType;
|
|
41
46
|
};
|
|
@@ -62,7 +67,7 @@ interface BrowserOptions {
|
|
|
62
67
|
*/
|
|
63
68
|
maxPageFreeSeconds?: number;
|
|
64
69
|
/**
|
|
65
|
-
* @default
|
|
70
|
+
* @default true
|
|
66
71
|
*/
|
|
67
72
|
maxViewportOfNewPage?: boolean;
|
|
68
73
|
/**
|
|
@@ -81,7 +86,7 @@ interface LsdLaunchOptions extends BrowserOptions {
|
|
|
81
86
|
args?: string[];
|
|
82
87
|
executablePath?: string;
|
|
83
88
|
/**
|
|
84
|
-
* @default
|
|
89
|
+
* @default true
|
|
85
90
|
*/
|
|
86
91
|
maxWindowSize?: boolean;
|
|
87
92
|
/**
|
|
@@ -933,6 +938,8 @@ interface LsdBrowser extends EventEmitter {
|
|
|
933
938
|
interface LsdBrowserController$1 {
|
|
934
939
|
launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options?: LsdLaunchOptions): Promise<LsdBrowser>;
|
|
935
940
|
connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options?: LsdConnectOptions): Promise<LsdBrowser>;
|
|
941
|
+
setPuppeteerNode(puppeteer: PuppeteerNode): boolean;
|
|
942
|
+
setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType): boolean;
|
|
936
943
|
}
|
|
937
944
|
/**
|
|
938
945
|
* globObj.cfg.XXX:
|
|
@@ -1258,9 +1265,11 @@ declare class CheerioElement implements LsdElement {
|
|
|
1258
1265
|
declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
1259
1266
|
#private;
|
|
1260
1267
|
constructor();
|
|
1268
|
+
setPuppeteerNode(puppeteer: PuppeteerNode): boolean;
|
|
1269
|
+
setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType): boolean;
|
|
1261
1270
|
launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdLaunchOptions): Promise<LsdBrowser>;
|
|
1262
1271
|
connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdConnectOptions): Promise<LsdBrowser>;
|
|
1263
1272
|
}
|
|
1264
1273
|
declare const controller: LsdBrowserController;
|
|
1265
1274
|
|
|
1266
|
-
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, 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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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, HTTPResponse, ElementHandle } from 'puppeteer';
|
|
3
|
-
import { Browser, BrowserContext, Frame, Page, Response, Locator } from 'playwright';
|
|
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';
|
|
4
4
|
import * as cheerio from 'cheerio';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -36,6 +36,11 @@ type Proxy = {
|
|
|
36
36
|
type BrowserControllerType = "puppeteer" | "playwright";
|
|
37
37
|
type BrowserCreationMethod = "launch" | "connect";
|
|
38
38
|
type LsdBrowserType = "chromium" | "firefox" | "webkit";
|
|
39
|
+
interface PlaywrightBrowserTypes {
|
|
40
|
+
chromium: BrowserType;
|
|
41
|
+
firefox: BrowserType;
|
|
42
|
+
webkit: BrowserType;
|
|
43
|
+
}
|
|
39
44
|
type BrowserControllerOptions = {
|
|
40
45
|
browserControllerType: BrowserControllerType;
|
|
41
46
|
};
|
|
@@ -62,7 +67,7 @@ interface BrowserOptions {
|
|
|
62
67
|
*/
|
|
63
68
|
maxPageFreeSeconds?: number;
|
|
64
69
|
/**
|
|
65
|
-
* @default
|
|
70
|
+
* @default true
|
|
66
71
|
*/
|
|
67
72
|
maxViewportOfNewPage?: boolean;
|
|
68
73
|
/**
|
|
@@ -81,7 +86,7 @@ interface LsdLaunchOptions extends BrowserOptions {
|
|
|
81
86
|
args?: string[];
|
|
82
87
|
executablePath?: string;
|
|
83
88
|
/**
|
|
84
|
-
* @default
|
|
89
|
+
* @default true
|
|
85
90
|
*/
|
|
86
91
|
maxWindowSize?: boolean;
|
|
87
92
|
/**
|
|
@@ -933,6 +938,8 @@ interface LsdBrowser extends EventEmitter {
|
|
|
933
938
|
interface LsdBrowserController$1 {
|
|
934
939
|
launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options?: LsdLaunchOptions): Promise<LsdBrowser>;
|
|
935
940
|
connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options?: LsdConnectOptions): Promise<LsdBrowser>;
|
|
941
|
+
setPuppeteerNode(puppeteer: PuppeteerNode): boolean;
|
|
942
|
+
setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType): boolean;
|
|
936
943
|
}
|
|
937
944
|
/**
|
|
938
945
|
* globObj.cfg.XXX:
|
|
@@ -1258,9 +1265,11 @@ declare class CheerioElement implements LsdElement {
|
|
|
1258
1265
|
declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
1259
1266
|
#private;
|
|
1260
1267
|
constructor();
|
|
1268
|
+
setPuppeteerNode(puppeteer: PuppeteerNode): boolean;
|
|
1269
|
+
setPlaywrightBrowserType(browserType: LsdBrowserType, playwrightBrowserType: BrowserType): boolean;
|
|
1261
1270
|
launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdLaunchOptions): Promise<LsdBrowser>;
|
|
1262
1271
|
connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdConnectOptions): Promise<LsdBrowser>;
|
|
1263
1272
|
}
|
|
1264
1273
|
declare const controller: LsdBrowserController;
|
|
1265
1274
|
|
|
1266
|
-
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, 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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1396,7 +1396,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1396
1396
|
throw new Error(`Invalid playwright browser parameter`);
|
|
1397
1397
|
}
|
|
1398
1398
|
super();
|
|
1399
|
-
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage =
|
|
1399
|
+
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage = true, headless = false, executablePath = "" } = options;
|
|
1400
1400
|
this.#browser = browser;
|
|
1401
1401
|
this.#browserIdx = browserIdx;
|
|
1402
1402
|
this.#lsdBrowserContexts = [];
|
|
@@ -2880,7 +2880,7 @@ var PuppeteerBrowser = class extends EventEmitter6 {
|
|
|
2880
2880
|
throw new Error(`Invalid puppeteer browser parameter`);
|
|
2881
2881
|
}
|
|
2882
2882
|
super();
|
|
2883
|
-
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage =
|
|
2883
|
+
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage = true, headless = false, executablePath = "" } = options;
|
|
2884
2884
|
this.#browser = browser;
|
|
2885
2885
|
this.#browserIdx = browserIdx;
|
|
2886
2886
|
this.#lsdBrowserContexts = [];
|
|
@@ -17169,9 +17169,11 @@ var CheerioPage = class extends EventEmitter7 {
|
|
|
17169
17169
|
import os from "os";
|
|
17170
17170
|
import puppeteer from "puppeteer";
|
|
17171
17171
|
import playwright from "playwright";
|
|
17172
|
-
import { logwarn as logwarn6 } from "@letsscrapedata/utils";
|
|
17172
|
+
import { logwarn as logwarn6, unreachable as unreachable5 } from "@letsscrapedata/utils";
|
|
17173
17173
|
var LsdBrowserController = class _LsdBrowserController {
|
|
17174
17174
|
static #forbidConstructor = false;
|
|
17175
|
+
#puppeteer;
|
|
17176
|
+
#playwrightBrowserTypes;
|
|
17175
17177
|
#nextBrowserIdx;
|
|
17176
17178
|
/**
|
|
17177
17179
|
* Possible values are 'aix', 'darwin', 'freebsd','linux', 'openbsd', 'sunos', and 'win32'.
|
|
@@ -17181,19 +17183,22 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17181
17183
|
if (_LsdBrowserController.#forbidConstructor) {
|
|
17182
17184
|
throw new Error("Only one LsdBrowserController instance can be created!");
|
|
17183
17185
|
}
|
|
17186
|
+
this.#puppeteer = puppeteer;
|
|
17187
|
+
const { chromium, firefox, webkit } = playwright;
|
|
17188
|
+
this.#playwrightBrowserTypes = { chromium, firefox, webkit };
|
|
17184
17189
|
this.#osPlatform = os.platform();
|
|
17185
17190
|
this.#nextBrowserIdx = 1;
|
|
17186
17191
|
_LsdBrowserController.#forbidConstructor = true;
|
|
17187
17192
|
}
|
|
17188
17193
|
#playwrightBrowserType(browserType, connectFlag = false) {
|
|
17189
17194
|
if (browserType === "chromium") {
|
|
17190
|
-
return
|
|
17195
|
+
return this.#playwrightBrowserTypes.chromium;
|
|
17191
17196
|
} else if (connectFlag) {
|
|
17192
17197
|
throw new Error(`playwright only can connect to chromium browser, not support ${browserType} browser`);
|
|
17193
17198
|
} else if (browserType === "firefox") {
|
|
17194
|
-
return
|
|
17199
|
+
return this.#playwrightBrowserTypes.firefox;
|
|
17195
17200
|
} else if (browserType === "webkit") {
|
|
17196
|
-
return
|
|
17201
|
+
return this.#playwrightBrowserTypes.webkit;
|
|
17197
17202
|
} else {
|
|
17198
17203
|
throw new Error(`Invalid playwright browserType ${browserType}`);
|
|
17199
17204
|
}
|
|
@@ -17205,18 +17210,38 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17205
17210
|
throw new Error(`Invalid puppeteer product ${browserType}`);
|
|
17206
17211
|
}
|
|
17207
17212
|
}
|
|
17213
|
+
setPuppeteerNode(puppeteer2) {
|
|
17214
|
+
this.#puppeteer = puppeteer2;
|
|
17215
|
+
return true;
|
|
17216
|
+
}
|
|
17217
|
+
setPlaywrightBrowserType(browserType, playwrightBrowserType) {
|
|
17218
|
+
switch (browserType) {
|
|
17219
|
+
case "chromium":
|
|
17220
|
+
this.#playwrightBrowserTypes.chromium = playwrightBrowserType;
|
|
17221
|
+
break;
|
|
17222
|
+
case "firefox":
|
|
17223
|
+
this.#playwrightBrowserTypes.firefox = playwrightBrowserType;
|
|
17224
|
+
break;
|
|
17225
|
+
case "webkit":
|
|
17226
|
+
this.#playwrightBrowserTypes.webkit = playwrightBrowserType;
|
|
17227
|
+
break;
|
|
17228
|
+
default:
|
|
17229
|
+
unreachable5(browserType);
|
|
17230
|
+
}
|
|
17231
|
+
return true;
|
|
17232
|
+
}
|
|
17208
17233
|
async launch(browserControllerType, browserType, options) {
|
|
17209
17234
|
let {
|
|
17210
17235
|
closeFreePagesIntervalSeconds = 300,
|
|
17211
17236
|
maxBrowserContextsPerBrowser = 10,
|
|
17212
17237
|
maxPagesPerBrowserContext = 20,
|
|
17213
17238
|
maxPageFreeSeconds = 900,
|
|
17214
|
-
maxViewportOfNewPage =
|
|
17239
|
+
maxViewportOfNewPage = true,
|
|
17215
17240
|
proxy = null,
|
|
17216
17241
|
timeout = 3e4,
|
|
17217
17242
|
args = [],
|
|
17218
17243
|
executablePath = "",
|
|
17219
|
-
maxWindowSize =
|
|
17244
|
+
maxWindowSize = true,
|
|
17220
17245
|
headless = true,
|
|
17221
17246
|
minBrowserContexts = 1,
|
|
17222
17247
|
// incognito
|
|
@@ -17302,9 +17327,9 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17302
17327
|
launchOptions.args = args;
|
|
17303
17328
|
}
|
|
17304
17329
|
if (!actOptions.executablePath) {
|
|
17305
|
-
actOptions.executablePath = puppeteer.executablePath();
|
|
17330
|
+
actOptions.executablePath = this.#puppeteer.executablePath();
|
|
17306
17331
|
}
|
|
17307
|
-
const browser = await puppeteer.launch(launchOptions);
|
|
17332
|
+
const browser = await this.#puppeteer.launch(launchOptions);
|
|
17308
17333
|
lsdBrowser = new PuppeteerBrowser(browser, browserType, "launch", actOptions, this.#nextBrowserIdx++);
|
|
17309
17334
|
} else {
|
|
17310
17335
|
throw new Error(`Invalid browserControllerType: ${browserControllerType} in launch`);
|
|
@@ -17320,7 +17345,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17320
17345
|
maxBrowserContextsPerBrowser = 10,
|
|
17321
17346
|
maxPagesPerBrowserContext = 20,
|
|
17322
17347
|
maxPageFreeSeconds = 900,
|
|
17323
|
-
maxViewportOfNewPage =
|
|
17348
|
+
maxViewportOfNewPage = true,
|
|
17324
17349
|
proxy = null,
|
|
17325
17350
|
timeout = 3e4,
|
|
17326
17351
|
browserUrl,
|
|
@@ -17340,7 +17365,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17340
17365
|
return lsdBrowser;
|
|
17341
17366
|
} else if (browserControllerType === "puppeteer") {
|
|
17342
17367
|
this.#puppeteerProduct(browserType);
|
|
17343
|
-
const browser = await puppeteer.connect({ browserURL: browserUrl });
|
|
17368
|
+
const browser = await this.#puppeteer.connect({ browserURL: browserUrl });
|
|
17344
17369
|
const lsdBrowser = new PuppeteerBrowser(browser, browserType, "connect", options, this.#nextBrowserIdx++);
|
|
17345
17370
|
;
|
|
17346
17371
|
return lsdBrowser;
|
package/package.json
CHANGED