unprint 0.18.18 → 0.18.20

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/app.js +22 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unprint",
3
- "version": "0.18.18",
3
+ "version": "0.18.20",
4
4
  "description": "Simplify common web scraping tasks while staying in control of the data.",
5
5
  "main": "src/app.js",
6
6
  "scripts": {},
package/src/app.js CHANGED
@@ -369,6 +369,15 @@ function prefixUrl(urlPath, originUrl, customOptions) {
369
369
  return null;
370
370
  }
371
371
 
372
+ if (/^http/.test(urlPath)) {
373
+ // this is already a complete URL
374
+ return urlPath;
375
+ }
376
+
377
+ if (!originUrl) {
378
+ return null;
379
+ }
380
+
372
381
  const options = {
373
382
  protocol: 'https',
374
383
  ...customOptions,
@@ -378,7 +387,7 @@ function prefixUrl(urlPath, originUrl, customOptions) {
378
387
 
379
388
  try {
380
389
  return new URL(urlPath, origin).href;
381
- } catch {
390
+ } catch (_error) {
382
391
  return null;
383
392
  }
384
393
  }
@@ -1238,6 +1247,12 @@ async function closeBrowser(client, options) {
1238
1247
  || (client.retired && client.active === 0)) { // this browser is retired to minimize garbage build-up
1239
1248
  // this browser won't be reused
1240
1249
  await client.browser.close();
1250
+
1251
+ events.emit('browser', {
1252
+ action: 'close',
1253
+ key: client.key,
1254
+ active: client.active,
1255
+ });
1241
1256
  }
1242
1257
  }
1243
1258
 
@@ -1301,6 +1316,12 @@ async function browserRequest(url, customOptions = {}) {
1301
1316
  return limiter.schedule(async () => {
1302
1317
  const client = await getBrowserInstance(options.client, options, agent instanceof undici.ProxyAgent);
1303
1318
 
1319
+ events.emit('browser', {
1320
+ action: 'open',
1321
+ key: client.key,
1322
+ active: client.active,
1323
+ });
1324
+
1304
1325
  client.active += 1;
1305
1326
 
1306
1327
  const page = await client.context.newPage();