@letsscrapedata/controller 0.0.13 → 0.0.15
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 +14 -10
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +14 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -952,7 +952,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
952
952
|
return;
|
|
953
953
|
}
|
|
954
954
|
for (const option of this.#responseInterceptionOptions) {
|
|
955
|
-
const { requestMatch, responseMatch, responseItems, handler, handlerOptions } = option;
|
|
955
|
+
const { requestMatch, responseMatch, responseItems, handler, handlerOptions = {} } = option;
|
|
956
956
|
let matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
957
957
|
if (matchedFlag && responseMatch) {
|
|
958
958
|
const { minLength, maxLength } = responseMatch;
|
|
@@ -981,7 +981,7 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
981
981
|
(0, import_utils2.loginfo)(`##browser cache matched response: ${requestUrl}`);
|
|
982
982
|
}
|
|
983
983
|
if (typeof handler === "function") {
|
|
984
|
-
await handler(response, handlerOptions);
|
|
984
|
+
await handler(response, handlerOptions, pageUrl);
|
|
985
985
|
}
|
|
986
986
|
}
|
|
987
987
|
return;
|
|
@@ -2408,18 +2408,18 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2408
2408
|
return false;
|
|
2409
2409
|
}
|
|
2410
2410
|
this.#responseInterceptionNum++;
|
|
2411
|
-
const pageUrl = this.#page.url();
|
|
2412
2411
|
this.#page.on("response", async (response) => {
|
|
2413
2412
|
try {
|
|
2414
|
-
if (!response.ok()) {
|
|
2413
|
+
if (!response.ok() || !this.#page) {
|
|
2415
2414
|
return false;
|
|
2416
2415
|
}
|
|
2416
|
+
const pageUrl = this.#page.url();
|
|
2417
2417
|
const request = response.request();
|
|
2418
2418
|
if (!request) {
|
|
2419
2419
|
return false;
|
|
2420
2420
|
}
|
|
2421
2421
|
for (const option of actOptions) {
|
|
2422
|
-
const { requestMatch, responseMatch, responseItems, handler, handlerOptions } = option;
|
|
2422
|
+
const { requestMatch, responseMatch, responseItems, handler, handlerOptions = {} } = option;
|
|
2423
2423
|
let matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
2424
2424
|
if (matchedFlag && responseMatch) {
|
|
2425
2425
|
const { minLength, maxLength } = responseMatch;
|
|
@@ -2447,7 +2447,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2447
2447
|
});
|
|
2448
2448
|
}
|
|
2449
2449
|
if (typeof handler === "function") {
|
|
2450
|
-
await handler(response, handlerOptions);
|
|
2450
|
+
await handler(response, handlerOptions, pageUrl);
|
|
2451
2451
|
}
|
|
2452
2452
|
}
|
|
2453
2453
|
return true;
|
|
@@ -17194,6 +17194,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17194
17194
|
args = [],
|
|
17195
17195
|
executablePath = "",
|
|
17196
17196
|
headless = false,
|
|
17197
|
+
minBrowserContexts = 1,
|
|
17197
17198
|
// incognito
|
|
17198
17199
|
proxy = null,
|
|
17199
17200
|
proxyPerBrowserContext = false,
|
|
@@ -17217,6 +17218,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17217
17218
|
(0, import_utils15.logwarn)(`Please use options.userDataDir instead when launching new browser.`);
|
|
17218
17219
|
args.splice(idx, 1);
|
|
17219
17220
|
}
|
|
17221
|
+
let lsdBrowser;
|
|
17220
17222
|
if (browserControllerType === "playwright") {
|
|
17221
17223
|
const launchOptions = { headless, timeout };
|
|
17222
17224
|
if (executablePath) {
|
|
@@ -17242,8 +17244,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17242
17244
|
actOptions.executablePath = playwrightBrowserType.executablePath();
|
|
17243
17245
|
}
|
|
17244
17246
|
const browser = await playwrightBrowserType.launch(launchOptions);
|
|
17245
|
-
|
|
17246
|
-
return lsdBrowser;
|
|
17247
|
+
lsdBrowser = new PlaywrightBrowser(browser, browserType, "launch", actOptions, this.#nextBrowserIdx++);
|
|
17247
17248
|
} else if (browserControllerType === "puppeteer") {
|
|
17248
17249
|
const product = this.#puppeteerProduct(browserType);
|
|
17249
17250
|
const launchOptions = { headless, timeout, product };
|
|
@@ -17269,11 +17270,14 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17269
17270
|
actOptions.executablePath = import_puppeteer.default.executablePath();
|
|
17270
17271
|
}
|
|
17271
17272
|
const browser = await import_puppeteer.default.launch(launchOptions);
|
|
17272
|
-
|
|
17273
|
-
return lsdBrowser;
|
|
17273
|
+
lsdBrowser = new PuppeteerBrowser(browser, browserType, "launch", actOptions, this.#nextBrowserIdx++);
|
|
17274
17274
|
} else {
|
|
17275
17275
|
throw new Error(`Invalid browserControllerType: ${browserControllerType} in launch`);
|
|
17276
17276
|
}
|
|
17277
|
+
for (let i = lsdBrowser.browserContexts().length; i < minBrowserContexts; i++) {
|
|
17278
|
+
lsdBrowser.newBrowserContext();
|
|
17279
|
+
}
|
|
17280
|
+
return lsdBrowser;
|
|
17277
17281
|
}
|
|
17278
17282
|
async connect(browserControllerType, browserType, options) {
|
|
17279
17283
|
const { browserUrl } = options;
|
package/dist/index.d.cts
CHANGED
|
@@ -80,6 +80,11 @@ interface LsdLaunchOptions extends BrowserOptions {
|
|
|
80
80
|
* @default true
|
|
81
81
|
*/
|
|
82
82
|
headless?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* min number of browserContexts
|
|
85
|
+
* @default 1
|
|
86
|
+
*/
|
|
87
|
+
minBrowserContexts?: number;
|
|
83
88
|
/** * @default false for puppeteer, true for playwright
|
|
84
89
|
*/
|
|
85
90
|
incognito?: boolean;
|
|
@@ -456,7 +461,7 @@ interface ResponseMatch {
|
|
|
456
461
|
maxLength?: number;
|
|
457
462
|
}
|
|
458
463
|
type ResponseHandlerOptions = Record<string, any>;
|
|
459
|
-
type ResponseHandler = (response: AllResponse, options
|
|
464
|
+
type ResponseHandler = (response: AllResponse, options: ResponseHandlerOptions, pageUrl: string) => Promise<void> | void;
|
|
460
465
|
interface ResponseInterceptionItem {
|
|
461
466
|
/**
|
|
462
467
|
* page.url()
|
|
@@ -490,6 +495,10 @@ interface ResponseInterceptionOption {
|
|
|
490
495
|
* handler will be called if handler is a function
|
|
491
496
|
*/
|
|
492
497
|
handler?: ResponseHandler;
|
|
498
|
+
/**
|
|
499
|
+
* valid only if handler is a function
|
|
500
|
+
* @default {}
|
|
501
|
+
*/
|
|
493
502
|
handlerOptions?: ResponseHandlerOptions;
|
|
494
503
|
}
|
|
495
504
|
interface PDFMargin {
|
package/dist/index.d.ts
CHANGED
|
@@ -80,6 +80,11 @@ interface LsdLaunchOptions extends BrowserOptions {
|
|
|
80
80
|
* @default true
|
|
81
81
|
*/
|
|
82
82
|
headless?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* min number of browserContexts
|
|
85
|
+
* @default 1
|
|
86
|
+
*/
|
|
87
|
+
minBrowserContexts?: number;
|
|
83
88
|
/** * @default false for puppeteer, true for playwright
|
|
84
89
|
*/
|
|
85
90
|
incognito?: boolean;
|
|
@@ -456,7 +461,7 @@ interface ResponseMatch {
|
|
|
456
461
|
maxLength?: number;
|
|
457
462
|
}
|
|
458
463
|
type ResponseHandlerOptions = Record<string, any>;
|
|
459
|
-
type ResponseHandler = (response: AllResponse, options
|
|
464
|
+
type ResponseHandler = (response: AllResponse, options: ResponseHandlerOptions, pageUrl: string) => Promise<void> | void;
|
|
460
465
|
interface ResponseInterceptionItem {
|
|
461
466
|
/**
|
|
462
467
|
* page.url()
|
|
@@ -490,6 +495,10 @@ interface ResponseInterceptionOption {
|
|
|
490
495
|
* handler will be called if handler is a function
|
|
491
496
|
*/
|
|
492
497
|
handler?: ResponseHandler;
|
|
498
|
+
/**
|
|
499
|
+
* valid only if handler is a function
|
|
500
|
+
* @default {}
|
|
501
|
+
*/
|
|
493
502
|
handlerOptions?: ResponseHandlerOptions;
|
|
494
503
|
}
|
|
495
504
|
interface PDFMargin {
|
package/dist/index.js
CHANGED
|
@@ -932,7 +932,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
932
932
|
return;
|
|
933
933
|
}
|
|
934
934
|
for (const option of this.#responseInterceptionOptions) {
|
|
935
|
-
const { requestMatch, responseMatch, responseItems, handler, handlerOptions } = option;
|
|
935
|
+
const { requestMatch, responseMatch, responseItems, handler, handlerOptions = {} } = option;
|
|
936
936
|
let matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
937
937
|
if (matchedFlag && responseMatch) {
|
|
938
938
|
const { minLength, maxLength } = responseMatch;
|
|
@@ -961,7 +961,7 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
961
961
|
loginfo(`##browser cache matched response: ${requestUrl}`);
|
|
962
962
|
}
|
|
963
963
|
if (typeof handler === "function") {
|
|
964
|
-
await handler(response, handlerOptions);
|
|
964
|
+
await handler(response, handlerOptions, pageUrl);
|
|
965
965
|
}
|
|
966
966
|
}
|
|
967
967
|
return;
|
|
@@ -2388,18 +2388,18 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2388
2388
|
return false;
|
|
2389
2389
|
}
|
|
2390
2390
|
this.#responseInterceptionNum++;
|
|
2391
|
-
const pageUrl = this.#page.url();
|
|
2392
2391
|
this.#page.on("response", async (response) => {
|
|
2393
2392
|
try {
|
|
2394
|
-
if (!response.ok()) {
|
|
2393
|
+
if (!response.ok() || !this.#page) {
|
|
2395
2394
|
return false;
|
|
2396
2395
|
}
|
|
2396
|
+
const pageUrl = this.#page.url();
|
|
2397
2397
|
const request = response.request();
|
|
2398
2398
|
if (!request) {
|
|
2399
2399
|
return false;
|
|
2400
2400
|
}
|
|
2401
2401
|
for (const option of actOptions) {
|
|
2402
|
-
const { requestMatch, responseMatch, responseItems, handler, handlerOptions } = option;
|
|
2402
|
+
const { requestMatch, responseMatch, responseItems, handler, handlerOptions = {} } = option;
|
|
2403
2403
|
let matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
|
|
2404
2404
|
if (matchedFlag && responseMatch) {
|
|
2405
2405
|
const { minLength, maxLength } = responseMatch;
|
|
@@ -2427,7 +2427,7 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
2427
2427
|
});
|
|
2428
2428
|
}
|
|
2429
2429
|
if (typeof handler === "function") {
|
|
2430
|
-
await handler(response, handlerOptions);
|
|
2430
|
+
await handler(response, handlerOptions, pageUrl);
|
|
2431
2431
|
}
|
|
2432
2432
|
}
|
|
2433
2433
|
return true;
|
|
@@ -17174,6 +17174,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17174
17174
|
args = [],
|
|
17175
17175
|
executablePath = "",
|
|
17176
17176
|
headless = false,
|
|
17177
|
+
minBrowserContexts = 1,
|
|
17177
17178
|
// incognito
|
|
17178
17179
|
proxy = null,
|
|
17179
17180
|
proxyPerBrowserContext = false,
|
|
@@ -17197,6 +17198,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17197
17198
|
logwarn6(`Please use options.userDataDir instead when launching new browser.`);
|
|
17198
17199
|
args.splice(idx, 1);
|
|
17199
17200
|
}
|
|
17201
|
+
let lsdBrowser;
|
|
17200
17202
|
if (browserControllerType === "playwright") {
|
|
17201
17203
|
const launchOptions = { headless, timeout };
|
|
17202
17204
|
if (executablePath) {
|
|
@@ -17222,8 +17224,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17222
17224
|
actOptions.executablePath = playwrightBrowserType.executablePath();
|
|
17223
17225
|
}
|
|
17224
17226
|
const browser = await playwrightBrowserType.launch(launchOptions);
|
|
17225
|
-
|
|
17226
|
-
return lsdBrowser;
|
|
17227
|
+
lsdBrowser = new PlaywrightBrowser(browser, browserType, "launch", actOptions, this.#nextBrowserIdx++);
|
|
17227
17228
|
} else if (browserControllerType === "puppeteer") {
|
|
17228
17229
|
const product = this.#puppeteerProduct(browserType);
|
|
17229
17230
|
const launchOptions = { headless, timeout, product };
|
|
@@ -17249,11 +17250,14 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17249
17250
|
actOptions.executablePath = puppeteer.executablePath();
|
|
17250
17251
|
}
|
|
17251
17252
|
const browser = await puppeteer.launch(launchOptions);
|
|
17252
|
-
|
|
17253
|
-
return lsdBrowser;
|
|
17253
|
+
lsdBrowser = new PuppeteerBrowser(browser, browserType, "launch", actOptions, this.#nextBrowserIdx++);
|
|
17254
17254
|
} else {
|
|
17255
17255
|
throw new Error(`Invalid browserControllerType: ${browserControllerType} in launch`);
|
|
17256
17256
|
}
|
|
17257
|
+
for (let i = lsdBrowser.browserContexts().length; i < minBrowserContexts; i++) {
|
|
17258
|
+
lsdBrowser.newBrowserContext();
|
|
17259
|
+
}
|
|
17260
|
+
return lsdBrowser;
|
|
17257
17261
|
}
|
|
17258
17262
|
async connect(browserControllerType, browserType, options) {
|
|
17259
17263
|
const { browserUrl } = options;
|
package/package.json
CHANGED