unprint 0.17.0 → 0.17.1

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/README.md CHANGED
@@ -210,10 +210,11 @@ Options
210
210
 
211
211
  Use Playwright with Chromium (experimental)
212
212
  * `unprint.browserRequest(url, [options])`
213
- * `unprint.closeAllBrowsers()`
213
+ * `unprint.closeAllBrowsers()`: Close reused browser instances.
214
214
 
215
215
  Additional options
216
- * `scope`: Browser instance to (re)use, default `main`.
216
+ * `control`: Async function to interface with Playwright page passed as argument
217
+ * `scope`: Browser instance to (re)use, set to `null` to force new scope every request, default `main`.
217
218
  * `browser`: Options object passed to Playwright's `launch`, requires new scope.
218
219
  * `browser.headless`: Headless mode, set to `false` to launch visible browser, default `true`.
219
220
  * `context`: Options object passed to Playwright's `newContext`, requires new scope.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unprint",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
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
@@ -1063,7 +1063,9 @@ async function getBrowserInstance(scope, options) {
1063
1063
 
1064
1064
  const client = { context, browser };
1065
1065
 
1066
- clients.set(scope, client);
1066
+ if (scope) {
1067
+ clients.set(scope, client);
1068
+ }
1067
1069
 
1068
1070
  return client;
1069
1071
  }
@@ -1171,7 +1173,11 @@ async function browserRequest(url, customOptions = {}) {
1171
1173
  const data = await page.content();
1172
1174
 
1173
1175
  await page.close();
1174
- // await browser.close();
1176
+
1177
+ if (options.scope === null) {
1178
+ // this browser won't be reused
1179
+ await browser.close();
1180
+ }
1175
1181
 
1176
1182
  return curateResponse({
1177
1183
  data,
package/tests/browser.js CHANGED
@@ -5,7 +5,10 @@ const unprint = require('../src/app');
5
5
  async function initTest() {
6
6
  await Promise.all([
7
7
  unprint.browser('https://tools-httpstatus.pickup-services.com/200?sleep=5000', {
8
- headless: false,
8
+ browser: {
9
+ headless: false,
10
+ },
11
+ scope: null,
9
12
  async control(_page) {
10
13
  //
11
14
  },
@@ -16,7 +19,10 @@ async function initTest() {
16
19
  }, 1000);
17
20
  }).then(async () => {
18
21
  await unprint.browser('https://tools-httpstatus.pickup-services.com/200?sleep=2000', {
19
- headless: false,
22
+ browser: {
23
+ headless: false,
24
+ },
25
+ scope: null,
20
26
  async control(_page) {
21
27
  //
22
28
  },