@letsscrapedata/controller 0.0.25 → 0.0.27
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 +24 -11
- package/dist/index.d.cts +12 -5
- package/dist/index.d.ts +12 -5
- package/dist/index.js +24 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1299,6 +1299,7 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1299
1299
|
return null;
|
|
1300
1300
|
}
|
|
1301
1301
|
const page = await this.#browserContext.newPage();
|
|
1302
|
+
await (0, import_utils3.sleep)(2e3);
|
|
1302
1303
|
const pageInfo = page.pageInfo;
|
|
1303
1304
|
if (!pageInfo) {
|
|
1304
1305
|
throw new Error(`Logic error in getPage`);
|
|
@@ -1415,7 +1416,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1415
1416
|
throw new Error(`Invalid playwright browser parameter`);
|
|
1416
1417
|
}
|
|
1417
1418
|
super();
|
|
1418
|
-
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage =
|
|
1419
|
+
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage = true, headless = false, executablePath = "" } = options;
|
|
1419
1420
|
this.#browser = browser;
|
|
1420
1421
|
this.#browserIdx = browserIdx;
|
|
1421
1422
|
this.#lsdBrowserContexts = [];
|
|
@@ -2779,6 +2780,7 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
2779
2780
|
return null;
|
|
2780
2781
|
}
|
|
2781
2782
|
const page = await this.#browserContext.newPage();
|
|
2783
|
+
await (0, import_utils7.sleep)(2e3);
|
|
2782
2784
|
const pageInfo = page.pageInfo;
|
|
2783
2785
|
if (!pageInfo) {
|
|
2784
2786
|
throw new Error(`Logic error in getPage`);
|
|
@@ -2898,7 +2900,7 @@ var PuppeteerBrowser = class extends import_node_events6.default {
|
|
|
2898
2900
|
throw new Error(`Invalid puppeteer browser parameter`);
|
|
2899
2901
|
}
|
|
2900
2902
|
super();
|
|
2901
|
-
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage =
|
|
2903
|
+
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage = true, headless = false, executablePath = "" } = options;
|
|
2902
2904
|
this.#browser = browser;
|
|
2903
2905
|
this.#browserIdx = browserIdx;
|
|
2904
2906
|
this.#lsdBrowserContexts = [];
|
|
@@ -17190,6 +17192,8 @@ var import_playwright = __toESM(require("playwright"), 1);
|
|
|
17190
17192
|
var import_utils15 = require("@letsscrapedata/utils");
|
|
17191
17193
|
var LsdBrowserController = class _LsdBrowserController {
|
|
17192
17194
|
static #forbidConstructor = false;
|
|
17195
|
+
#puppeteer;
|
|
17196
|
+
#playwrightBrowserTypes;
|
|
17193
17197
|
#nextBrowserIdx;
|
|
17194
17198
|
/**
|
|
17195
17199
|
* Possible values are 'aix', 'darwin', 'freebsd','linux', 'openbsd', 'sunos', and 'win32'.
|
|
@@ -17199,19 +17203,22 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17199
17203
|
if (_LsdBrowserController.#forbidConstructor) {
|
|
17200
17204
|
throw new Error("Only one LsdBrowserController instance can be created!");
|
|
17201
17205
|
}
|
|
17206
|
+
this.#puppeteer = import_puppeteer.default;
|
|
17207
|
+
const { chromium, firefox, webkit } = import_playwright.default;
|
|
17208
|
+
this.#playwrightBrowserTypes = { chromium, firefox, webkit };
|
|
17202
17209
|
this.#osPlatform = import_os.default.platform();
|
|
17203
17210
|
this.#nextBrowserIdx = 1;
|
|
17204
17211
|
_LsdBrowserController.#forbidConstructor = true;
|
|
17205
17212
|
}
|
|
17206
17213
|
#playwrightBrowserType(browserType, connectFlag = false) {
|
|
17207
17214
|
if (browserType === "chromium") {
|
|
17208
|
-
return
|
|
17215
|
+
return this.#playwrightBrowserTypes.chromium;
|
|
17209
17216
|
} else if (connectFlag) {
|
|
17210
17217
|
throw new Error(`playwright only can connect to chromium browser, not support ${browserType} browser`);
|
|
17211
17218
|
} else if (browserType === "firefox") {
|
|
17212
|
-
return
|
|
17219
|
+
return this.#playwrightBrowserTypes.firefox;
|
|
17213
17220
|
} else if (browserType === "webkit") {
|
|
17214
|
-
return
|
|
17221
|
+
return this.#playwrightBrowserTypes.webkit;
|
|
17215
17222
|
} else {
|
|
17216
17223
|
throw new Error(`Invalid playwright browserType ${browserType}`);
|
|
17217
17224
|
}
|
|
@@ -17223,18 +17230,24 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17223
17230
|
throw new Error(`Invalid puppeteer product ${browserType}`);
|
|
17224
17231
|
}
|
|
17225
17232
|
}
|
|
17233
|
+
setPuppeteerNode(puppeteer2) {
|
|
17234
|
+
this.#puppeteer = puppeteer2;
|
|
17235
|
+
}
|
|
17236
|
+
setPlaywrightBrowserTypes(playwrightBrowserTypes) {
|
|
17237
|
+
this.#playwrightBrowserTypes = playwrightBrowserTypes;
|
|
17238
|
+
}
|
|
17226
17239
|
async launch(browserControllerType, browserType, options) {
|
|
17227
17240
|
let {
|
|
17228
17241
|
closeFreePagesIntervalSeconds = 300,
|
|
17229
17242
|
maxBrowserContextsPerBrowser = 10,
|
|
17230
17243
|
maxPagesPerBrowserContext = 20,
|
|
17231
17244
|
maxPageFreeSeconds = 900,
|
|
17232
|
-
maxViewportOfNewPage =
|
|
17245
|
+
maxViewportOfNewPage = true,
|
|
17233
17246
|
proxy = null,
|
|
17234
17247
|
timeout = 3e4,
|
|
17235
17248
|
args = [],
|
|
17236
17249
|
executablePath = "",
|
|
17237
|
-
maxWindowSize =
|
|
17250
|
+
maxWindowSize = true,
|
|
17238
17251
|
headless = true,
|
|
17239
17252
|
minBrowserContexts = 1,
|
|
17240
17253
|
// incognito
|
|
@@ -17320,9 +17333,9 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17320
17333
|
launchOptions.args = args;
|
|
17321
17334
|
}
|
|
17322
17335
|
if (!actOptions.executablePath) {
|
|
17323
|
-
actOptions.executablePath =
|
|
17336
|
+
actOptions.executablePath = this.#puppeteer.executablePath();
|
|
17324
17337
|
}
|
|
17325
|
-
const browser = await
|
|
17338
|
+
const browser = await this.#puppeteer.launch(launchOptions);
|
|
17326
17339
|
lsdBrowser = new PuppeteerBrowser(browser, browserType, "launch", actOptions, this.#nextBrowserIdx++);
|
|
17327
17340
|
} else {
|
|
17328
17341
|
throw new Error(`Invalid browserControllerType: ${browserControllerType} in launch`);
|
|
@@ -17338,7 +17351,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17338
17351
|
maxBrowserContextsPerBrowser = 10,
|
|
17339
17352
|
maxPagesPerBrowserContext = 20,
|
|
17340
17353
|
maxPageFreeSeconds = 900,
|
|
17341
|
-
maxViewportOfNewPage =
|
|
17354
|
+
maxViewportOfNewPage = true,
|
|
17342
17355
|
proxy = null,
|
|
17343
17356
|
timeout = 3e4,
|
|
17344
17357
|
browserUrl,
|
|
@@ -17358,7 +17371,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17358
17371
|
return lsdBrowser;
|
|
17359
17372
|
} else if (browserControllerType === "puppeteer") {
|
|
17360
17373
|
this.#puppeteerProduct(browserType);
|
|
17361
|
-
const browser = await
|
|
17374
|
+
const browser = await this.#puppeteer.connect({ browserURL: browserUrl });
|
|
17362
17375
|
const lsdBrowser = new PuppeteerBrowser(browser, browserType, "connect", options, this.#nextBrowserIdx++);
|
|
17363
17376
|
;
|
|
17364
17377
|
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, ElementHandle, PuppeteerNode } 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
|
/**
|
|
@@ -1258,9 +1263,11 @@ declare class CheerioElement implements LsdElement {
|
|
|
1258
1263
|
declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
1259
1264
|
#private;
|
|
1260
1265
|
constructor();
|
|
1266
|
+
setPuppeteerNode(puppeteer: PuppeteerNode): void;
|
|
1267
|
+
setPlaywrightBrowserTypes(playwrightBrowserTypes: PlaywrightBrowserTypes): void;
|
|
1261
1268
|
launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdLaunchOptions): Promise<LsdBrowser>;
|
|
1262
1269
|
connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdConnectOptions): Promise<LsdBrowser>;
|
|
1263
1270
|
}
|
|
1264
1271
|
declare const controller: LsdBrowserController;
|
|
1265
1272
|
|
|
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 };
|
|
1273
|
+
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, ElementHandle, PuppeteerNode } 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
|
/**
|
|
@@ -1258,9 +1263,11 @@ declare class CheerioElement implements LsdElement {
|
|
|
1258
1263
|
declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
1259
1264
|
#private;
|
|
1260
1265
|
constructor();
|
|
1266
|
+
setPuppeteerNode(puppeteer: PuppeteerNode): void;
|
|
1267
|
+
setPlaywrightBrowserTypes(playwrightBrowserTypes: PlaywrightBrowserTypes): void;
|
|
1261
1268
|
launch(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdLaunchOptions): Promise<LsdBrowser>;
|
|
1262
1269
|
connect(browserControllerType: BrowserControllerType, browserType: LsdBrowserType, options: LsdConnectOptions): Promise<LsdBrowser>;
|
|
1263
1270
|
}
|
|
1264
1271
|
declare const controller: LsdBrowserController;
|
|
1265
1272
|
|
|
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 };
|
|
1273
|
+
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
|
@@ -1279,6 +1279,7 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1279
1279
|
return null;
|
|
1280
1280
|
}
|
|
1281
1281
|
const page = await this.#browserContext.newPage();
|
|
1282
|
+
await sleep(2e3);
|
|
1282
1283
|
const pageInfo = page.pageInfo;
|
|
1283
1284
|
if (!pageInfo) {
|
|
1284
1285
|
throw new Error(`Logic error in getPage`);
|
|
@@ -1395,7 +1396,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1395
1396
|
throw new Error(`Invalid playwright browser parameter`);
|
|
1396
1397
|
}
|
|
1397
1398
|
super();
|
|
1398
|
-
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage =
|
|
1399
|
+
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage = true, headless = false, executablePath = "" } = options;
|
|
1399
1400
|
this.#browser = browser;
|
|
1400
1401
|
this.#browserIdx = browserIdx;
|
|
1401
1402
|
this.#lsdBrowserContexts = [];
|
|
@@ -2759,6 +2760,7 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
2759
2760
|
return null;
|
|
2760
2761
|
}
|
|
2761
2762
|
const page = await this.#browserContext.newPage();
|
|
2763
|
+
await sleep2(2e3);
|
|
2762
2764
|
const pageInfo = page.pageInfo;
|
|
2763
2765
|
if (!pageInfo) {
|
|
2764
2766
|
throw new Error(`Logic error in getPage`);
|
|
@@ -2878,7 +2880,7 @@ var PuppeteerBrowser = class extends EventEmitter6 {
|
|
|
2878
2880
|
throw new Error(`Invalid puppeteer browser parameter`);
|
|
2879
2881
|
}
|
|
2880
2882
|
super();
|
|
2881
|
-
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage =
|
|
2883
|
+
const { closeFreePagesIntervalSeconds = 300, maxPageFreeSeconds = 900, maxViewportOfNewPage = true, headless = false, executablePath = "" } = options;
|
|
2882
2884
|
this.#browser = browser;
|
|
2883
2885
|
this.#browserIdx = browserIdx;
|
|
2884
2886
|
this.#lsdBrowserContexts = [];
|
|
@@ -17170,6 +17172,8 @@ import playwright from "playwright";
|
|
|
17170
17172
|
import { logwarn as logwarn6 } from "@letsscrapedata/utils";
|
|
17171
17173
|
var LsdBrowserController = class _LsdBrowserController {
|
|
17172
17174
|
static #forbidConstructor = false;
|
|
17175
|
+
#puppeteer;
|
|
17176
|
+
#playwrightBrowserTypes;
|
|
17173
17177
|
#nextBrowserIdx;
|
|
17174
17178
|
/**
|
|
17175
17179
|
* Possible values are 'aix', 'darwin', 'freebsd','linux', 'openbsd', 'sunos', and 'win32'.
|
|
@@ -17179,19 +17183,22 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17179
17183
|
if (_LsdBrowserController.#forbidConstructor) {
|
|
17180
17184
|
throw new Error("Only one LsdBrowserController instance can be created!");
|
|
17181
17185
|
}
|
|
17186
|
+
this.#puppeteer = puppeteer;
|
|
17187
|
+
const { chromium, firefox, webkit } = playwright;
|
|
17188
|
+
this.#playwrightBrowserTypes = { chromium, firefox, webkit };
|
|
17182
17189
|
this.#osPlatform = os.platform();
|
|
17183
17190
|
this.#nextBrowserIdx = 1;
|
|
17184
17191
|
_LsdBrowserController.#forbidConstructor = true;
|
|
17185
17192
|
}
|
|
17186
17193
|
#playwrightBrowserType(browserType, connectFlag = false) {
|
|
17187
17194
|
if (browserType === "chromium") {
|
|
17188
|
-
return
|
|
17195
|
+
return this.#playwrightBrowserTypes.chromium;
|
|
17189
17196
|
} else if (connectFlag) {
|
|
17190
17197
|
throw new Error(`playwright only can connect to chromium browser, not support ${browserType} browser`);
|
|
17191
17198
|
} else if (browserType === "firefox") {
|
|
17192
|
-
return
|
|
17199
|
+
return this.#playwrightBrowserTypes.firefox;
|
|
17193
17200
|
} else if (browserType === "webkit") {
|
|
17194
|
-
return
|
|
17201
|
+
return this.#playwrightBrowserTypes.webkit;
|
|
17195
17202
|
} else {
|
|
17196
17203
|
throw new Error(`Invalid playwright browserType ${browserType}`);
|
|
17197
17204
|
}
|
|
@@ -17203,18 +17210,24 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17203
17210
|
throw new Error(`Invalid puppeteer product ${browserType}`);
|
|
17204
17211
|
}
|
|
17205
17212
|
}
|
|
17213
|
+
setPuppeteerNode(puppeteer2) {
|
|
17214
|
+
this.#puppeteer = puppeteer2;
|
|
17215
|
+
}
|
|
17216
|
+
setPlaywrightBrowserTypes(playwrightBrowserTypes) {
|
|
17217
|
+
this.#playwrightBrowserTypes = playwrightBrowserTypes;
|
|
17218
|
+
}
|
|
17206
17219
|
async launch(browserControllerType, browserType, options) {
|
|
17207
17220
|
let {
|
|
17208
17221
|
closeFreePagesIntervalSeconds = 300,
|
|
17209
17222
|
maxBrowserContextsPerBrowser = 10,
|
|
17210
17223
|
maxPagesPerBrowserContext = 20,
|
|
17211
17224
|
maxPageFreeSeconds = 900,
|
|
17212
|
-
maxViewportOfNewPage =
|
|
17225
|
+
maxViewportOfNewPage = true,
|
|
17213
17226
|
proxy = null,
|
|
17214
17227
|
timeout = 3e4,
|
|
17215
17228
|
args = [],
|
|
17216
17229
|
executablePath = "",
|
|
17217
|
-
maxWindowSize =
|
|
17230
|
+
maxWindowSize = true,
|
|
17218
17231
|
headless = true,
|
|
17219
17232
|
minBrowserContexts = 1,
|
|
17220
17233
|
// incognito
|
|
@@ -17300,9 +17313,9 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17300
17313
|
launchOptions.args = args;
|
|
17301
17314
|
}
|
|
17302
17315
|
if (!actOptions.executablePath) {
|
|
17303
|
-
actOptions.executablePath = puppeteer.executablePath();
|
|
17316
|
+
actOptions.executablePath = this.#puppeteer.executablePath();
|
|
17304
17317
|
}
|
|
17305
|
-
const browser = await puppeteer.launch(launchOptions);
|
|
17318
|
+
const browser = await this.#puppeteer.launch(launchOptions);
|
|
17306
17319
|
lsdBrowser = new PuppeteerBrowser(browser, browserType, "launch", actOptions, this.#nextBrowserIdx++);
|
|
17307
17320
|
} else {
|
|
17308
17321
|
throw new Error(`Invalid browserControllerType: ${browserControllerType} in launch`);
|
|
@@ -17318,7 +17331,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17318
17331
|
maxBrowserContextsPerBrowser = 10,
|
|
17319
17332
|
maxPagesPerBrowserContext = 20,
|
|
17320
17333
|
maxPageFreeSeconds = 900,
|
|
17321
|
-
maxViewportOfNewPage =
|
|
17334
|
+
maxViewportOfNewPage = true,
|
|
17322
17335
|
proxy = null,
|
|
17323
17336
|
timeout = 3e4,
|
|
17324
17337
|
browserUrl,
|
|
@@ -17338,7 +17351,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17338
17351
|
return lsdBrowser;
|
|
17339
17352
|
} else if (browserControllerType === "puppeteer") {
|
|
17340
17353
|
this.#puppeteerProduct(browserType);
|
|
17341
|
-
const browser = await puppeteer.connect({ browserURL: browserUrl });
|
|
17354
|
+
const browser = await this.#puppeteer.connect({ browserURL: browserUrl });
|
|
17342
17355
|
const lsdBrowser = new PuppeteerBrowser(browser, browserType, "connect", options, this.#nextBrowserIdx++);
|
|
17343
17356
|
;
|
|
17344
17357
|
return lsdBrowser;
|
package/package.json
CHANGED