@letsscrapedata/controller 0.0.69 → 0.0.71
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 +165 -42
- package/dist/index.d.cts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +163 -40
- package/package.json +7 -12
package/dist/index.cjs
CHANGED
|
@@ -470,8 +470,8 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
470
470
|
const url = page.url();
|
|
471
471
|
const origCookies = await browserContext.cookies(url);
|
|
472
472
|
const cookies = origCookies.map((origCookie) => {
|
|
473
|
-
const { name, value, domain, path, expires, httpOnly, secure, sameSite = "Lax" } = origCookie;
|
|
474
|
-
return { name, value, domain, path, expires, httpOnly, secure, sameSite };
|
|
473
|
+
const { name, value, domain, path: path2, expires, httpOnly, secure, sameSite = "Lax" } = origCookie;
|
|
474
|
+
return { name, value, domain, path: path2, expires, httpOnly, secure, sameSite };
|
|
475
475
|
});
|
|
476
476
|
return cookies;
|
|
477
477
|
}
|
|
@@ -1355,6 +1355,9 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
1355
1355
|
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
1356
1356
|
return true;
|
|
1357
1357
|
}
|
|
1358
|
+
userAgent() {
|
|
1359
|
+
return this.#lsdBrowserContext.userAgent();
|
|
1360
|
+
}
|
|
1358
1361
|
async waitForElement(selector, options = {}) {
|
|
1359
1362
|
if (!this.#page) {
|
|
1360
1363
|
throw new Error("No valid page");
|
|
@@ -1469,6 +1472,7 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1469
1472
|
#browserContextIdx;
|
|
1470
1473
|
#browserContext;
|
|
1471
1474
|
#browserContextCreationMethod;
|
|
1475
|
+
#userAgent;
|
|
1472
1476
|
#apiContext;
|
|
1473
1477
|
#createTime;
|
|
1474
1478
|
#lastStatusUpdateTime;
|
|
@@ -1496,8 +1500,15 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1496
1500
|
await lsdPage.maximizeViewport();
|
|
1497
1501
|
}
|
|
1498
1502
|
}
|
|
1503
|
+
if (!this.#userAgent && this.#lsdPages.length > 0) {
|
|
1504
|
+
const lsdPage = this.#lsdPages[0];
|
|
1505
|
+
const userAgent = await lsdPage.evaluate(() => navigator.userAgent);
|
|
1506
|
+
if (typeof userAgent === "string" && userAgent) {
|
|
1507
|
+
this.#userAgent = userAgent;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1499
1510
|
}
|
|
1500
|
-
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, maxViewportOfNewPage = true) {
|
|
1511
|
+
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, userAgent = "", maxViewportOfNewPage = true) {
|
|
1501
1512
|
if (!lsdBrowser || typeof lsdBrowser.browserContexts !== "function") {
|
|
1502
1513
|
throw new Error(`Invalid lsdBrowser parameter`);
|
|
1503
1514
|
}
|
|
@@ -1510,6 +1521,7 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1510
1521
|
this.#browserContextIdx = browserContextIdx;
|
|
1511
1522
|
this.#browserContext = browserContext;
|
|
1512
1523
|
this.#browserContextCreationMethod = browserContextCreationMethod;
|
|
1524
|
+
this.#userAgent = userAgent;
|
|
1513
1525
|
const apiRequestContext = browserContext.request;
|
|
1514
1526
|
this.#apiContext = new PlaywrightApiContext(apiRequestContext);
|
|
1515
1527
|
const currentTime = (0, import_utils4.getCurrentUnixTime)();
|
|
@@ -1663,6 +1675,12 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1663
1675
|
}
|
|
1664
1676
|
lsdPage = this.#lsdPages.find((p) => p.isFree());
|
|
1665
1677
|
if (lsdPage) {
|
|
1678
|
+
if (!this.#userAgent) {
|
|
1679
|
+
const userAgent = await lsdPage.evaluate(() => navigator.userAgent);
|
|
1680
|
+
if (typeof userAgent === "string" && userAgent) {
|
|
1681
|
+
this.#userAgent = userAgent;
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1666
1684
|
lsdPage.use();
|
|
1667
1685
|
this.#freeGettingLock();
|
|
1668
1686
|
return lsdPage;
|
|
@@ -1769,6 +1787,9 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1769
1787
|
return false;
|
|
1770
1788
|
}
|
|
1771
1789
|
}
|
|
1790
|
+
userAgent() {
|
|
1791
|
+
return this.#userAgent;
|
|
1792
|
+
}
|
|
1772
1793
|
_origBrowserContext() {
|
|
1773
1794
|
return this.#browserContext;
|
|
1774
1795
|
}
|
|
@@ -1838,7 +1859,7 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends import_node_events3.def
|
|
|
1838
1859
|
}
|
|
1839
1860
|
const incognito = typeof options?.incognito === "boolean" ? options.incognito : true;
|
|
1840
1861
|
for (const browserContext of browserContexts) {
|
|
1841
|
-
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
1862
|
+
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), "", maxViewportOfNewPage);
|
|
1842
1863
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
1843
1864
|
}
|
|
1844
1865
|
browser.on("disconnected" /* BROWSER_DISCONNECTED */, () => {
|
|
@@ -1890,12 +1911,13 @@ var PlaywrightBrowser = class _PlaywrightBrowser extends import_node_events3.def
|
|
|
1890
1911
|
const { proxyUrl: server, username, password } = proxy;
|
|
1891
1912
|
browserContextOptions.proxy = { server, username, password };
|
|
1892
1913
|
}
|
|
1893
|
-
|
|
1894
|
-
|
|
1914
|
+
let userAgent = options?.userAgent ? options.userAgent : this.#options.userAgent;
|
|
1915
|
+
if (userAgent) {
|
|
1916
|
+
browserContextOptions.userAgent = userAgent;
|
|
1895
1917
|
}
|
|
1896
1918
|
const browserContext = await this.#browser.newContext(browserContextOptions);
|
|
1897
1919
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
1898
|
-
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
1920
|
+
const lsdBrowserContext = new PlaywrightBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), userAgent, maxViewportOfNewPage);
|
|
1899
1921
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
1900
1922
|
return lsdBrowserContext;
|
|
1901
1923
|
}
|
|
@@ -2278,6 +2300,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2278
2300
|
#page;
|
|
2279
2301
|
#status;
|
|
2280
2302
|
#pageId;
|
|
2303
|
+
#userAgent;
|
|
2281
2304
|
#closeWhenFree;
|
|
2282
2305
|
#requestInterceptionNum;
|
|
2283
2306
|
#responseInterceptionNum;
|
|
@@ -2301,8 +2324,8 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2301
2324
|
}
|
|
2302
2325
|
const origCookies = await page.cookies();
|
|
2303
2326
|
const cookies = origCookies.map((origCookie) => {
|
|
2304
|
-
const { name, value, domain, path, expires, httpOnly, secure, sameSite = "Lax" } = origCookie;
|
|
2305
|
-
return { name, value, domain, path, expires, httpOnly, secure, sameSite };
|
|
2327
|
+
const { name, value, domain, path: path2, expires, httpOnly = false, secure, sameSite = "Lax" } = origCookie;
|
|
2328
|
+
return { name, value, domain, path: path2, expires, httpOnly, secure, sameSite };
|
|
2306
2329
|
});
|
|
2307
2330
|
return cookies;
|
|
2308
2331
|
}
|
|
@@ -2511,6 +2534,7 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2511
2534
|
const { browserIdx = 0, browserContextIdx = 0, pageIdx = 0, openType = "other", openTime = currentTime, lastStatusUpdateTime = currentTime, taskId = 0, relatedId = 0, misc = {} } = pageInfo ? pageInfo : {};
|
|
2512
2535
|
this.#page.pageInfo = { browserIdx, browserContextIdx, pageIdx, openType, openTime, lastStatusUpdateTime, taskId, relatedId, misc };
|
|
2513
2536
|
this.#pageId = `PuppeteerPage-${browserIdx}-${browserContextIdx}-${pageIdx}`;
|
|
2537
|
+
this.#userAgent = browserContext.userAgent();
|
|
2514
2538
|
this.#closeWhenFree = false;
|
|
2515
2539
|
this.#requestInterceptionNum = 0;
|
|
2516
2540
|
this.#responseInterceptionNum = 0;
|
|
@@ -3106,10 +3130,11 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
3106
3130
|
return await this.#lsdBrowserContext.setStateData(stateData);
|
|
3107
3131
|
}
|
|
3108
3132
|
async setUserAgent(userAgent) {
|
|
3109
|
-
if (!this.#page) {
|
|
3133
|
+
if (!this.#page || !userAgent) {
|
|
3110
3134
|
throw new Error("No valid page");
|
|
3111
3135
|
}
|
|
3112
3136
|
await this.#page.setUserAgent(userAgent);
|
|
3137
|
+
this.#userAgent = userAgent;
|
|
3113
3138
|
return true;
|
|
3114
3139
|
}
|
|
3115
3140
|
async setViewportSize(viewPortSize) {
|
|
@@ -3150,6 +3175,9 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
3150
3175
|
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
3151
3176
|
return true;
|
|
3152
3177
|
}
|
|
3178
|
+
userAgent() {
|
|
3179
|
+
return this.#userAgent;
|
|
3180
|
+
}
|
|
3153
3181
|
async waitForElement(selector, options = {}) {
|
|
3154
3182
|
if (!this.#page) {
|
|
3155
3183
|
throw new Error("No valid page");
|
|
@@ -3233,9 +3261,9 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3233
3261
|
#browserContext;
|
|
3234
3262
|
#browserContextCreationMethod;
|
|
3235
3263
|
/**
|
|
3236
|
-
*
|
|
3237
|
-
* * Notice: it is not the actual userAgent if !#userAgent (ignored if !#userAgent)
|
|
3264
|
+
* userAgent of BrowserContext
|
|
3238
3265
|
*/
|
|
3266
|
+
#bcUserAgent;
|
|
3239
3267
|
#userAgent;
|
|
3240
3268
|
#createTime;
|
|
3241
3269
|
#lastStatusUpdateTime;
|
|
@@ -3262,8 +3290,15 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3262
3290
|
if (this.#maxViewportOfNewPage) {
|
|
3263
3291
|
await lsdPage.maximizeViewport();
|
|
3264
3292
|
}
|
|
3265
|
-
if (this.#
|
|
3266
|
-
await lsdPage.setUserAgent(this.#
|
|
3293
|
+
if (this.#bcUserAgent) {
|
|
3294
|
+
await lsdPage.setUserAgent(this.#bcUserAgent);
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
if (!this.#userAgent && this.#lsdPages.length > 0) {
|
|
3298
|
+
const lsdPage = this.#lsdPages[0];
|
|
3299
|
+
const userAgent = await lsdPage.evaluate(() => navigator.userAgent);
|
|
3300
|
+
if (typeof userAgent === "string" && userAgent) {
|
|
3301
|
+
this.#userAgent = userAgent;
|
|
3267
3302
|
}
|
|
3268
3303
|
}
|
|
3269
3304
|
}
|
|
@@ -3280,6 +3315,7 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3280
3315
|
this.#browserContextIdx = browserContextIdx;
|
|
3281
3316
|
this.#browserContext = browserContext;
|
|
3282
3317
|
this.#browserContextCreationMethod = browserContextCreationMethod;
|
|
3318
|
+
this.#bcUserAgent = userAgent;
|
|
3283
3319
|
this.#userAgent = userAgent;
|
|
3284
3320
|
const currentTime = (0, import_utils8.getCurrentUnixTime)();
|
|
3285
3321
|
this.#createTime = currentTime;
|
|
@@ -3310,9 +3346,6 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3310
3346
|
const pageInfo2 = { browserIdx: this.#browserIdx, browserContextIdx: this.#browserContextIdx, pageIdx: this.#nextPageIdx++, openType: "other", openTime: currentTime2, lastStatusUpdateTime: currentTime2, taskId: 0, relatedId: 0, misc: {} };
|
|
3311
3347
|
const lsdPage = new PuppeteerPage(this, page, pageInfo2);
|
|
3312
3348
|
this.#lsdPages.push(lsdPage);
|
|
3313
|
-
if (this.#userAgent) {
|
|
3314
|
-
await lsdPage.setUserAgent(this.#userAgent);
|
|
3315
|
-
}
|
|
3316
3349
|
if (this.#maxViewportOfNewPage) {
|
|
3317
3350
|
await lsdPage.maximizeViewport();
|
|
3318
3351
|
}
|
|
@@ -3440,6 +3473,9 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3440
3473
|
return null;
|
|
3441
3474
|
}
|
|
3442
3475
|
const page = await this.#browserContext.newPage();
|
|
3476
|
+
if (this.#bcUserAgent) {
|
|
3477
|
+
await page.setUserAgent(this.#bcUserAgent);
|
|
3478
|
+
}
|
|
3443
3479
|
await (0, import_utils8.sleep)(2e3);
|
|
3444
3480
|
const pageInfo = page.pageInfo;
|
|
3445
3481
|
if (!pageInfo) {
|
|
@@ -3449,6 +3485,12 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3449
3485
|
}
|
|
3450
3486
|
lsdPage = this.#lsdPages.find((p) => p.isFree());
|
|
3451
3487
|
if (lsdPage) {
|
|
3488
|
+
if (!this.#userAgent) {
|
|
3489
|
+
const userAgent = await lsdPage.evaluate(() => navigator.userAgent);
|
|
3490
|
+
if (typeof userAgent === "string" && userAgent) {
|
|
3491
|
+
this.#userAgent = userAgent;
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3452
3494
|
lsdPage.use();
|
|
3453
3495
|
this.#freeGettingLock();
|
|
3454
3496
|
return lsdPage;
|
|
@@ -3555,6 +3597,9 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
3555
3597
|
return false;
|
|
3556
3598
|
}
|
|
3557
3599
|
}
|
|
3600
|
+
userAgent() {
|
|
3601
|
+
return this.#userAgent;
|
|
3602
|
+
}
|
|
3558
3603
|
_origBrowserContext() {
|
|
3559
3604
|
return this.#browserContext;
|
|
3560
3605
|
}
|
|
@@ -3672,8 +3717,8 @@ var PuppeteerBrowser = class _PuppeteerBrowser extends import_node_events6.defau
|
|
|
3672
3717
|
if (proxy?.proxyUrl) {
|
|
3673
3718
|
browserContextOptions.proxyServer = proxy.proxyUrl;
|
|
3674
3719
|
}
|
|
3720
|
+
let userAgent = options?.userAgent ? options.userAgent : this.#options.userAgent;
|
|
3675
3721
|
const browserContext = await this.#browser.createBrowserContext(browserContextOptions);
|
|
3676
|
-
const userAgent = options?.userAgent ? options.userAgent : "";
|
|
3677
3722
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
3678
3723
|
const lsdBrowserContext = new PuppeteerBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), userAgent, maxViewportOfNewPage);
|
|
3679
3724
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
@@ -4113,6 +4158,9 @@ var CheerioPage = class extends import_node_events7.default {
|
|
|
4113
4158
|
use() {
|
|
4114
4159
|
throw new Error("Not supported in CheerioPage.");
|
|
4115
4160
|
}
|
|
4161
|
+
userAgent() {
|
|
4162
|
+
throw new Error("Not supported in CheerioPage.");
|
|
4163
|
+
}
|
|
4116
4164
|
waitForElement() {
|
|
4117
4165
|
throw new Error("Not supported in CheerioPage.");
|
|
4118
4166
|
}
|
|
@@ -4125,7 +4173,9 @@ var CheerioPage = class extends import_node_events7.default {
|
|
|
4125
4173
|
};
|
|
4126
4174
|
|
|
4127
4175
|
// src/controller/controller.ts
|
|
4128
|
-
var
|
|
4176
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
4177
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
4178
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
4129
4179
|
var import_puppeteer = __toESM(require("puppeteer"), 1);
|
|
4130
4180
|
var import_playwright = __toESM(require("playwright"), 1);
|
|
4131
4181
|
var import_patchright = __toESM(require("patchright"), 1);
|
|
@@ -4476,8 +4526,8 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
4476
4526
|
const url = page.url();
|
|
4477
4527
|
const origCookies = await browserContext.cookies(url);
|
|
4478
4528
|
const cookies = origCookies.map((origCookie) => {
|
|
4479
|
-
const { name, value, domain, path, expires, httpOnly, secure, sameSite = "Lax" } = origCookie;
|
|
4480
|
-
return { name, value, domain, path, expires, httpOnly, secure, sameSite };
|
|
4529
|
+
const { name, value, domain, path: path2, expires, httpOnly, secure, sameSite = "Lax" } = origCookie;
|
|
4530
|
+
return { name, value, domain, path: path2, expires, httpOnly, secure, sameSite };
|
|
4481
4531
|
});
|
|
4482
4532
|
return cookies;
|
|
4483
4533
|
}
|
|
@@ -5360,6 +5410,9 @@ var PatchrightPage = class extends import_node_events8.default {
|
|
|
5360
5410
|
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
5361
5411
|
return true;
|
|
5362
5412
|
}
|
|
5413
|
+
userAgent() {
|
|
5414
|
+
return this.#lsdBrowserContext.userAgent();
|
|
5415
|
+
}
|
|
5363
5416
|
async waitForElement(selector, options = {}) {
|
|
5364
5417
|
if (!this.#page) {
|
|
5365
5418
|
throw new Error("No valid page");
|
|
@@ -5474,6 +5527,7 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5474
5527
|
#browserContextIdx;
|
|
5475
5528
|
#browserContext;
|
|
5476
5529
|
#browserContextCreationMethod;
|
|
5530
|
+
#userAgent;
|
|
5477
5531
|
#apiContext;
|
|
5478
5532
|
#createTime;
|
|
5479
5533
|
#lastStatusUpdateTime;
|
|
@@ -5501,8 +5555,15 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5501
5555
|
await lsdPage.maximizeViewport();
|
|
5502
5556
|
}
|
|
5503
5557
|
}
|
|
5558
|
+
if (!this.#userAgent && this.#lsdPages.length > 0) {
|
|
5559
|
+
const lsdPage = this.#lsdPages[0];
|
|
5560
|
+
const userAgent = await lsdPage.evaluate(() => navigator.userAgent);
|
|
5561
|
+
if (typeof userAgent === "string" && userAgent) {
|
|
5562
|
+
this.#userAgent = userAgent;
|
|
5563
|
+
}
|
|
5564
|
+
}
|
|
5504
5565
|
}
|
|
5505
|
-
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, maxViewportOfNewPage = true) {
|
|
5566
|
+
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, userAgent = "", maxViewportOfNewPage = true) {
|
|
5506
5567
|
if (!lsdBrowser || typeof lsdBrowser.browserContexts !== "function") {
|
|
5507
5568
|
throw new Error(`Invalid lsdBrowser parameter`);
|
|
5508
5569
|
}
|
|
@@ -5515,6 +5576,7 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5515
5576
|
this.#browserContextIdx = browserContextIdx;
|
|
5516
5577
|
this.#browserContext = browserContext;
|
|
5517
5578
|
this.#browserContextCreationMethod = browserContextCreationMethod;
|
|
5579
|
+
this.#userAgent = userAgent;
|
|
5518
5580
|
const apiRequestContext = browserContext.request;
|
|
5519
5581
|
this.#apiContext = new PatchrightApiContext(apiRequestContext);
|
|
5520
5582
|
const currentTime = (0, import_utils12.getCurrentUnixTime)();
|
|
@@ -5668,6 +5730,12 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5668
5730
|
}
|
|
5669
5731
|
lsdPage = this.#lsdPages.find((p) => p.isFree());
|
|
5670
5732
|
if (lsdPage) {
|
|
5733
|
+
if (!this.#userAgent) {
|
|
5734
|
+
const userAgent = await lsdPage.evaluate(() => navigator.userAgent);
|
|
5735
|
+
if (typeof userAgent === "string" && userAgent) {
|
|
5736
|
+
this.#userAgent = userAgent;
|
|
5737
|
+
}
|
|
5738
|
+
}
|
|
5671
5739
|
lsdPage.use();
|
|
5672
5740
|
this.#freeGettingLock();
|
|
5673
5741
|
return lsdPage;
|
|
@@ -5774,6 +5842,9 @@ var PatchrightBrowserContext = class extends import_node_events9.default {
|
|
|
5774
5842
|
return false;
|
|
5775
5843
|
}
|
|
5776
5844
|
}
|
|
5845
|
+
userAgent() {
|
|
5846
|
+
return this.#userAgent;
|
|
5847
|
+
}
|
|
5777
5848
|
_origBrowserContext() {
|
|
5778
5849
|
return this.#browserContext;
|
|
5779
5850
|
}
|
|
@@ -5843,7 +5914,7 @@ var PatchrightBrowser = class _PatchrightBrowser extends import_node_events10.de
|
|
|
5843
5914
|
}
|
|
5844
5915
|
const incognito = typeof options?.incognito === "boolean" ? options.incognito : true;
|
|
5845
5916
|
for (const browserContext of browserContexts) {
|
|
5846
|
-
const lsdBrowserContext = new PatchrightBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
5917
|
+
const lsdBrowserContext = new PatchrightBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), "", maxViewportOfNewPage);
|
|
5847
5918
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
5848
5919
|
}
|
|
5849
5920
|
browser.on("disconnected" /* BROWSER_DISCONNECTED */, () => {
|
|
@@ -5895,12 +5966,13 @@ var PatchrightBrowser = class _PatchrightBrowser extends import_node_events10.de
|
|
|
5895
5966
|
const { proxyUrl: server, username, password } = proxy;
|
|
5896
5967
|
browserContextOptions.proxy = { server, username, password };
|
|
5897
5968
|
}
|
|
5898
|
-
|
|
5899
|
-
|
|
5969
|
+
let userAgent = options?.userAgent ? options.userAgent : this.#options.userAgent;
|
|
5970
|
+
if (userAgent) {
|
|
5971
|
+
browserContextOptions.userAgent = userAgent;
|
|
5900
5972
|
}
|
|
5901
5973
|
const browserContext = await this.#browser.newContext(browserContextOptions);
|
|
5902
5974
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
5903
|
-
const lsdBrowserContext = new PatchrightBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
5975
|
+
const lsdBrowserContext = new PatchrightBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), userAgent, maxViewportOfNewPage);
|
|
5904
5976
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
5905
5977
|
return lsdBrowserContext;
|
|
5906
5978
|
}
|
|
@@ -6328,8 +6400,8 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
6328
6400
|
const url = page.url();
|
|
6329
6401
|
const origCookies = await browserContext.cookies(url);
|
|
6330
6402
|
const cookies = origCookies.map((origCookie) => {
|
|
6331
|
-
const { name, value, domain, path, expires, httpOnly, secure, sameSite = "Lax" } = origCookie;
|
|
6332
|
-
return { name, value, domain, path, expires, httpOnly, secure, sameSite };
|
|
6403
|
+
const { name, value, domain, path: path2, expires, httpOnly, secure, sameSite = "Lax" } = origCookie;
|
|
6404
|
+
return { name, value, domain, path: path2, expires, httpOnly, secure, sameSite };
|
|
6333
6405
|
});
|
|
6334
6406
|
return cookies;
|
|
6335
6407
|
}
|
|
@@ -7184,6 +7256,9 @@ var CamoufoxPage = class extends import_node_events11.default {
|
|
|
7184
7256
|
logdbg(`##browser LsdPage ${this.#pageId} is allocated`);
|
|
7185
7257
|
return true;
|
|
7186
7258
|
}
|
|
7259
|
+
userAgent() {
|
|
7260
|
+
return this.#lsdBrowserContext.userAgent();
|
|
7261
|
+
}
|
|
7187
7262
|
async waitForElement(selector, options = {}) {
|
|
7188
7263
|
if (!this.#page) {
|
|
7189
7264
|
throw new Error("No valid page");
|
|
@@ -7298,6 +7373,7 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7298
7373
|
#browserContextIdx;
|
|
7299
7374
|
#browserContext;
|
|
7300
7375
|
#browserContextCreationMethod;
|
|
7376
|
+
#userAgent;
|
|
7301
7377
|
#apiContext;
|
|
7302
7378
|
#createTime;
|
|
7303
7379
|
#lastStatusUpdateTime;
|
|
@@ -7325,8 +7401,15 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7325
7401
|
await lsdPage.maximizeViewport();
|
|
7326
7402
|
}
|
|
7327
7403
|
}
|
|
7404
|
+
if (!this.#userAgent && this.#lsdPages.length > 0) {
|
|
7405
|
+
const lsdPage = this.#lsdPages[0];
|
|
7406
|
+
const userAgent = await lsdPage.evaluate(() => navigator.userAgent);
|
|
7407
|
+
if (typeof userAgent === "string" && userAgent) {
|
|
7408
|
+
this.#userAgent = userAgent;
|
|
7409
|
+
}
|
|
7410
|
+
}
|
|
7328
7411
|
}
|
|
7329
|
-
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, maxViewportOfNewPage = true) {
|
|
7412
|
+
constructor(lsdBrowser, browserContext, browserContextCreationMethod, incognito = false, proxy = null, browserIdx = 0, browserContextIdx = 0, maxPagesPerBrowserContext = 20, maxPageFreeSeconds = 0, userAgent = "", maxViewportOfNewPage = true) {
|
|
7330
7413
|
if (!lsdBrowser || typeof lsdBrowser.browserContexts !== "function") {
|
|
7331
7414
|
throw new Error(`Invalid lsdBrowser parameter`);
|
|
7332
7415
|
}
|
|
@@ -7339,6 +7422,7 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7339
7422
|
this.#browserContextIdx = browserContextIdx;
|
|
7340
7423
|
this.#browserContext = browserContext;
|
|
7341
7424
|
this.#browserContextCreationMethod = browserContextCreationMethod;
|
|
7425
|
+
this.#userAgent = userAgent;
|
|
7342
7426
|
const apiRequestContext = browserContext.request;
|
|
7343
7427
|
this.#apiContext = new CamoufoxApiContext(apiRequestContext);
|
|
7344
7428
|
const currentTime = (0, import_utils16.getCurrentUnixTime)();
|
|
@@ -7492,6 +7576,12 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7492
7576
|
}
|
|
7493
7577
|
lsdPage = this.#lsdPages.find((p) => p.isFree());
|
|
7494
7578
|
if (lsdPage) {
|
|
7579
|
+
if (!this.#userAgent) {
|
|
7580
|
+
const userAgent = await lsdPage.evaluate(() => navigator.userAgent);
|
|
7581
|
+
if (typeof userAgent === "string" && userAgent) {
|
|
7582
|
+
this.#userAgent = userAgent;
|
|
7583
|
+
}
|
|
7584
|
+
}
|
|
7495
7585
|
lsdPage.use();
|
|
7496
7586
|
this.#freeGettingLock();
|
|
7497
7587
|
return lsdPage;
|
|
@@ -7598,6 +7688,9 @@ var CamoufoxBrowserContext = class extends import_node_events12.default {
|
|
|
7598
7688
|
return false;
|
|
7599
7689
|
}
|
|
7600
7690
|
}
|
|
7691
|
+
userAgent() {
|
|
7692
|
+
return this.#userAgent;
|
|
7693
|
+
}
|
|
7601
7694
|
_origBrowserContext() {
|
|
7602
7695
|
return this.#browserContext;
|
|
7603
7696
|
}
|
|
@@ -7667,7 +7760,7 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends import_node_events13.defaul
|
|
|
7667
7760
|
}
|
|
7668
7761
|
const incognito = typeof options?.incognito === "boolean" ? options.incognito : true;
|
|
7669
7762
|
for (const browserContext of browserContexts) {
|
|
7670
|
-
const lsdBrowserContext = new CamoufoxBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
7763
|
+
const lsdBrowserContext = new CamoufoxBrowserContext(this, browserContext, "launch", incognito, this.#proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), "", maxViewportOfNewPage);
|
|
7671
7764
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
7672
7765
|
}
|
|
7673
7766
|
browser.on("disconnected" /* BROWSER_DISCONNECTED */, () => {
|
|
@@ -7719,12 +7812,13 @@ var CamoufoxBrowser = class _CamoufoxBrowser extends import_node_events13.defaul
|
|
|
7719
7812
|
const { proxyUrl: server, username, password } = proxy;
|
|
7720
7813
|
browserContextOptions.proxy = { server, username, password };
|
|
7721
7814
|
}
|
|
7722
|
-
|
|
7723
|
-
|
|
7815
|
+
let userAgent = options?.userAgent ? options.userAgent : this.#options.userAgent;
|
|
7816
|
+
if (userAgent) {
|
|
7817
|
+
browserContextOptions.userAgent = userAgent;
|
|
7724
7818
|
}
|
|
7725
7819
|
const browserContext = await this.#browser.newContext(browserContextOptions);
|
|
7726
7820
|
const { maxViewportOfNewPage = this.#options.maxViewportOfNewPage } = options ? options : {};
|
|
7727
|
-
const lsdBrowserContext = new CamoufoxBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), maxViewportOfNewPage);
|
|
7821
|
+
const lsdBrowserContext = new CamoufoxBrowserContext(this, browserContext, "new", true, proxy, this.#browserIdx, this.#nextBrowserContextIdx++, this.#maxPagesPerBrowserContext(), this.#maxPageFreeSeconds(), userAgent, maxViewportOfNewPage);
|
|
7728
7822
|
this.#lsdBrowserContexts.push(lsdBrowserContext);
|
|
7729
7823
|
return lsdBrowserContext;
|
|
7730
7824
|
}
|
|
@@ -7813,21 +7907,23 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
7813
7907
|
}
|
|
7814
7908
|
this.#puppeteer = import_puppeteer.default;
|
|
7815
7909
|
this.#playwrightBrowserTypes = {
|
|
7910
|
+
chrome: import_playwright.default.chromium,
|
|
7816
7911
|
chromium: import_playwright.default.chromium,
|
|
7817
7912
|
firefox: import_playwright.default.firefox,
|
|
7818
7913
|
webkit: import_playwright.default.webkit
|
|
7819
7914
|
};
|
|
7820
7915
|
this.#patchrightBrowserTypes = {
|
|
7916
|
+
chrome: import_playwright.default.chromium,
|
|
7821
7917
|
chromium: import_patchright.default.chromium,
|
|
7822
7918
|
firefox: import_patchright.default.firefox,
|
|
7823
7919
|
webkit: import_patchright.default.webkit
|
|
7824
7920
|
};
|
|
7825
|
-
this.#osPlatform =
|
|
7921
|
+
this.#osPlatform = import_node_os.default.platform();
|
|
7826
7922
|
this.#nextBrowserIdx = 1;
|
|
7827
7923
|
_LsdBrowserController.#forbidConstructor = true;
|
|
7828
7924
|
}
|
|
7829
7925
|
#playwrightBrowserType(browserType, connectFlag = false) {
|
|
7830
|
-
if (browserType === "chromium") {
|
|
7926
|
+
if (browserType === "chrome" || browserType === "chromium") {
|
|
7831
7927
|
return this.#playwrightBrowserTypes.chromium;
|
|
7832
7928
|
} else if (connectFlag) {
|
|
7833
7929
|
throw new Error(`playwright only can connect to chromium browser, not support ${browserType} browser`);
|
|
@@ -7840,7 +7936,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
7840
7936
|
}
|
|
7841
7937
|
}
|
|
7842
7938
|
#patchrightBrowserType(browserType, connectFlag = false) {
|
|
7843
|
-
if (browserType === "chromium") {
|
|
7939
|
+
if (browserType === "chrome" || browserType === "chromium") {
|
|
7844
7940
|
return this.#patchrightBrowserTypes.chromium;
|
|
7845
7941
|
} else if (connectFlag) {
|
|
7846
7942
|
throw new Error(`patchright only can connect to chromium browser, not support ${browserType} browser`);
|
|
@@ -7870,6 +7966,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
7870
7966
|
throw new Error(`BrowserControllerType ${browserControllerType} doesnot support browserType ${browserType}`);
|
|
7871
7967
|
}
|
|
7872
7968
|
switch (browserType) {
|
|
7969
|
+
case "chrome":
|
|
7873
7970
|
case "chromium":
|
|
7874
7971
|
case "firefox":
|
|
7875
7972
|
case "webkit":
|
|
@@ -7883,6 +7980,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
7883
7980
|
throw new Error(`BrowserControllerType ${browserControllerType} doesnot support browserType ${browserType}`);
|
|
7884
7981
|
}
|
|
7885
7982
|
switch (browserType) {
|
|
7983
|
+
case "chrome":
|
|
7886
7984
|
case "chromium":
|
|
7887
7985
|
case "firefox":
|
|
7888
7986
|
case "webkit":
|
|
@@ -7917,6 +8015,7 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
7917
8015
|
// incognito
|
|
7918
8016
|
proxyPerBrowserContext = false,
|
|
7919
8017
|
userDataDir = "",
|
|
8018
|
+
userDataBaseDir = import_node_os.default.tmpdir(),
|
|
7920
8019
|
userAgent = ""
|
|
7921
8020
|
} = options ? options : {};
|
|
7922
8021
|
let browserPid = 0;
|
|
@@ -7943,6 +8042,18 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
7943
8042
|
args.splice(idx, 1);
|
|
7944
8043
|
}
|
|
7945
8044
|
let lsdBrowser;
|
|
8045
|
+
if (browserType === "chrome" && ["playwright", "patchright", "puppeteer"].includes(browserControllerType)) {
|
|
8046
|
+
if (!userDataDir) {
|
|
8047
|
+
if (!userDataBaseDir) {
|
|
8048
|
+
userDataBaseDir = import_node_os.default.tmpdir();
|
|
8049
|
+
}
|
|
8050
|
+
userDataDir = import_node_fs.default.mkdtempSync(import_node_path.default.join(userDataBaseDir, `lsd-${browserControllerType}-chrome-`));
|
|
8051
|
+
actOptions.userDataDir = userDataDir;
|
|
8052
|
+
}
|
|
8053
|
+
if (!executablePath) {
|
|
8054
|
+
throw new Error("Invalid executablePath when to launch chrome");
|
|
8055
|
+
}
|
|
8056
|
+
}
|
|
7946
8057
|
if (browserControllerType === "playwright") {
|
|
7947
8058
|
const launchOptions = { headless, timeout };
|
|
7948
8059
|
if (executablePath) {
|
|
@@ -7957,10 +8068,14 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
7957
8068
|
} else if (proxyPerBrowserContext && browserType === "chromium" && this.#osPlatform.startsWith("win")) {
|
|
7958
8069
|
launchOptions.proxy = { server: "proxyPerBrowserContext" };
|
|
7959
8070
|
}
|
|
7960
|
-
if (browserType === "chromium") {
|
|
8071
|
+
if (browserType === "chrome" || browserType === "chromium") {
|
|
8072
|
+
if (browserType === "chrome") {
|
|
8073
|
+
launchOptions.channel = "chrome";
|
|
8074
|
+
}
|
|
7961
8075
|
if (incognito) {
|
|
7962
8076
|
args.push("--incognito");
|
|
7963
|
-
}
|
|
8077
|
+
}
|
|
8078
|
+
if (userDataDir) {
|
|
7964
8079
|
args.push(`--user-data-dir=${userDataDir}`);
|
|
7965
8080
|
}
|
|
7966
8081
|
}
|
|
@@ -7998,10 +8113,14 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
7998
8113
|
} else if (proxyPerBrowserContext && browserType === "chromium" && this.#osPlatform.startsWith("win")) {
|
|
7999
8114
|
launchOptions.proxy = { server: "proxyPerBrowserContext" };
|
|
8000
8115
|
}
|
|
8001
|
-
if (browserType === "chromium") {
|
|
8116
|
+
if (browserType === "chrome" || browserType === "chromium") {
|
|
8117
|
+
if (browserType === "chrome") {
|
|
8118
|
+
launchOptions.channel = "chrome";
|
|
8119
|
+
}
|
|
8002
8120
|
if (incognito) {
|
|
8003
8121
|
args.push("--incognito");
|
|
8004
|
-
}
|
|
8122
|
+
}
|
|
8123
|
+
if (userDataDir) {
|
|
8005
8124
|
args.push(`--user-data-dir=${userDataDir}`);
|
|
8006
8125
|
}
|
|
8007
8126
|
}
|
|
@@ -8038,10 +8157,14 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
8038
8157
|
if (!args.includes("--no-sandbox")) {
|
|
8039
8158
|
args.push("--no-sandbox");
|
|
8040
8159
|
}
|
|
8041
|
-
if (browserType === "chromium") {
|
|
8160
|
+
if (browserType === "chrome" || browserType === "chromium") {
|
|
8161
|
+
if (browserType === "chrome") {
|
|
8162
|
+
launchOptions.channel = "chrome";
|
|
8163
|
+
}
|
|
8042
8164
|
if (incognito) {
|
|
8043
8165
|
args.push("--incognito");
|
|
8044
|
-
}
|
|
8166
|
+
}
|
|
8167
|
+
if (userDataDir) {
|
|
8045
8168
|
args.push(`--user-data-dir=${userDataDir}`);
|
|
8046
8169
|
}
|
|
8047
8170
|
if (proxy?.proxyUrl && proxy.proxyUrl !== "default") {
|