unprint 0.18.17 → 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 +26 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unprint",
3
- "version": "0.18.17",
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,
@@ -376,7 +385,11 @@ function prefixUrl(urlPath, originUrl, customOptions) {
376
385
 
377
386
  const origin = originUrl?.replace(/^.*?:/, `${options.protocol}:`);
378
387
 
379
- return new URL(urlPath, origin).href;
388
+ try {
389
+ return new URL(urlPath, origin).href;
390
+ } catch (_error) {
391
+ return null;
392
+ }
380
393
  }
381
394
 
382
395
  function queryUrl(context, selector = 'a', customOptions) {
@@ -1234,6 +1247,12 @@ async function closeBrowser(client, options) {
1234
1247
  || (client.retired && client.active === 0)) { // this browser is retired to minimize garbage build-up
1235
1248
  // this browser won't be reused
1236
1249
  await client.browser.close();
1250
+
1251
+ events.emit('browser', {
1252
+ action: 'close',
1253
+ key: client.key,
1254
+ active: client.active,
1255
+ });
1237
1256
  }
1238
1257
  }
1239
1258
 
@@ -1297,6 +1316,12 @@ async function browserRequest(url, customOptions = {}) {
1297
1316
  return limiter.schedule(async () => {
1298
1317
  const client = await getBrowserInstance(options.client, options, agent instanceof undici.ProxyAgent);
1299
1318
 
1319
+ events.emit('browser', {
1320
+ action: 'open',
1321
+ key: client.key,
1322
+ active: client.active,
1323
+ });
1324
+
1300
1325
  client.active += 1;
1301
1326
 
1302
1327
  const page = await client.context.newPage();