unprint 0.19.16 → 0.19.17
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/package.json +1 -1
- package/src/app.js +19 -10
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -1225,6 +1225,10 @@ async function getBrowserContext(browser, options, useProxy) {
|
|
|
1225
1225
|
server: `${options.proxy.host}:${options.proxy.port}`,
|
|
1226
1226
|
},
|
|
1227
1227
|
}),
|
|
1228
|
+
extraHTTPHeaders: {
|
|
1229
|
+
...options.headers,
|
|
1230
|
+
cookie: getCookie(options),
|
|
1231
|
+
},
|
|
1228
1232
|
});
|
|
1229
1233
|
}
|
|
1230
1234
|
|
|
@@ -1259,10 +1263,11 @@ async function getBrowserInstance(scope, options, useProxy = false, useRemote =
|
|
|
1259
1263
|
: chromium.launch({
|
|
1260
1264
|
headless: true,
|
|
1261
1265
|
...options.browser,
|
|
1262
|
-
})).then(async (browser) => {
|
|
1263
|
-
|
|
1266
|
+
})).then(async (browser) => { // eslint-disable-line arrow-body-style
|
|
1267
|
+
// legacy
|
|
1268
|
+
// const context = await getBrowserContext(browser, options, useProxy);
|
|
1264
1269
|
|
|
1265
|
-
return { browser
|
|
1270
|
+
return { browser };
|
|
1266
1271
|
});
|
|
1267
1272
|
|
|
1268
1273
|
const client = {
|
|
@@ -1432,19 +1437,18 @@ async function browserRequest(url, customOptions = {}) {
|
|
|
1432
1437
|
|
|
1433
1438
|
client.active += 1;
|
|
1434
1439
|
|
|
1435
|
-
const
|
|
1436
|
-
|
|
1437
|
-
await page.setExtraHTTPHeaders(curateHeaders({
|
|
1438
|
-
'user-agent': options.browserUserAgent || options.userAgent,
|
|
1439
|
-
...options.headers,
|
|
1440
|
-
cookie: getCookie(options),
|
|
1441
|
-
}, options));
|
|
1440
|
+
const context = await getBrowserContext(client.browser, options, useProxy);
|
|
1441
|
+
const page = await context.newPage();
|
|
1442
1442
|
|
|
1443
1443
|
const res = await page.goto(url, {
|
|
1444
1444
|
...options.page,
|
|
1445
1445
|
}).catch((error) => error);
|
|
1446
1446
|
|
|
1447
1447
|
if (res instanceof Error) {
|
|
1448
|
+
await context.close();
|
|
1449
|
+
await page.close();
|
|
1450
|
+
await closeBrowser(client, options);
|
|
1451
|
+
|
|
1448
1452
|
return {
|
|
1449
1453
|
ok: false,
|
|
1450
1454
|
status: null,
|
|
@@ -1469,6 +1473,8 @@ async function browserRequest(url, customOptions = {}) {
|
|
|
1469
1473
|
|
|
1470
1474
|
client.active -= 1;
|
|
1471
1475
|
|
|
1476
|
+
await page.close();
|
|
1477
|
+
await context.close();
|
|
1472
1478
|
await closeBrowser(client, options);
|
|
1473
1479
|
|
|
1474
1480
|
return curateResponse({
|
|
@@ -1494,6 +1500,8 @@ async function browserRequest(url, customOptions = {}) {
|
|
|
1494
1500
|
} catch (error) {
|
|
1495
1501
|
client.active -= 1;
|
|
1496
1502
|
|
|
1503
|
+
await page.close();
|
|
1504
|
+
await context.close();
|
|
1497
1505
|
await closeBrowser(client, options);
|
|
1498
1506
|
|
|
1499
1507
|
events.emit('controlError', {
|
|
@@ -1519,6 +1527,7 @@ async function browserRequest(url, customOptions = {}) {
|
|
|
1519
1527
|
const data = await page.content();
|
|
1520
1528
|
|
|
1521
1529
|
await page.close();
|
|
1530
|
+
await context.close();
|
|
1522
1531
|
|
|
1523
1532
|
events.emit('requestSuccess', {
|
|
1524
1533
|
...feedbackBase,
|