unprint 0.16.4-beta → 0.17.0
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 +11 -3
- package/package.json +1 -1
- package/src/app.js +6 -4
package/README.md
CHANGED
|
@@ -205,15 +205,23 @@ Extracts the CSS `url()` background from a style attribute. Alias for `query.sty
|
|
|
205
205
|
* `unprint.request(url, body, [options], [method])`
|
|
206
206
|
|
|
207
207
|
Options
|
|
208
|
-
* `select`: Pre-query and initialize a specific element on the page
|
|
209
|
-
* `selectAll`: Pre-query and initialize multiple specific element on the page
|
|
208
|
+
* `select`: Pre-query and initialize a specific element on the page.
|
|
209
|
+
* `selectAll`: Pre-query and initialize multiple specific element on the page.
|
|
210
210
|
|
|
211
211
|
Use Playwright with Chromium (experimental)
|
|
212
212
|
* `unprint.browserRequest(url, [options])`
|
|
213
213
|
* `unprint.closeAllBrowsers()`
|
|
214
214
|
|
|
215
215
|
Additional options
|
|
216
|
-
* `
|
|
216
|
+
* `scope`: Browser instance to (re)use, default `main`.
|
|
217
|
+
* `browser`: Options object passed to Playwright's `launch`, requires new scope.
|
|
218
|
+
* `browser.headless`: Headless mode, set to `false` to launch visible browser, default `true`.
|
|
219
|
+
* `context`: Options object passed to Playwright's `newContext`, requires new scope.
|
|
220
|
+
* `page`: Options object passed to Playwright's `goto`.
|
|
221
|
+
|
|
222
|
+
This requires you to install the Chromium executable:
|
|
223
|
+
* `sudo npx patchright install-deps`
|
|
224
|
+
* `npx patchright install`
|
|
217
225
|
|
|
218
226
|
Returns
|
|
219
227
|
```javascript
|
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -1046,17 +1046,19 @@ function setProxy(instance, options, url) {
|
|
|
1046
1046
|
const clients = new Map();
|
|
1047
1047
|
|
|
1048
1048
|
/* eslint-enable no-param-reassign */
|
|
1049
|
-
async function getBrowserInstance(scope) {
|
|
1049
|
+
async function getBrowserInstance(scope, options) {
|
|
1050
1050
|
if (clients.has(scope)) {
|
|
1051
1051
|
return clients.get(scope);
|
|
1052
1052
|
}
|
|
1053
1053
|
|
|
1054
1054
|
const browser = await chromium.launch({
|
|
1055
|
-
headless:
|
|
1055
|
+
headless: true,
|
|
1056
|
+
...options.browser,
|
|
1056
1057
|
});
|
|
1057
1058
|
|
|
1058
1059
|
const context = await browser.newContext({
|
|
1059
1060
|
userAgent: 'unprint',
|
|
1061
|
+
...options.context,
|
|
1060
1062
|
});
|
|
1061
1063
|
|
|
1062
1064
|
const client = { context, browser };
|
|
@@ -1126,11 +1128,11 @@ async function browserRequest(url, customOptions = {}) {
|
|
|
1126
1128
|
};
|
|
1127
1129
|
|
|
1128
1130
|
return limiter.schedule(async () => {
|
|
1129
|
-
const { context, browser } = await getBrowserInstance(options.scope);
|
|
1131
|
+
const { context, browser } = await getBrowserInstance(options.scope, options);
|
|
1130
1132
|
const page = await context.newPage();
|
|
1131
1133
|
|
|
1132
1134
|
const res = await page.goto(url, {
|
|
1133
|
-
...options.
|
|
1135
|
+
...options.page,
|
|
1134
1136
|
});
|
|
1135
1137
|
|
|
1136
1138
|
const status = res.status();
|