browserless 10.7.8 → 10.7.9-beta.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/package.json +2 -2
- package/src/index.js +10 -5
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "browserless",
|
|
3
3
|
"description": "The headless Chrome/Chromium performance driver for Node.js",
|
|
4
4
|
"homepage": "https://browserless.js.org",
|
|
5
|
-
"version": "10.7.
|
|
5
|
+
"version": "10.7.9-beta.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"timeout": "2m",
|
|
65
65
|
"workerThreads": false
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "112999584d7b7137fb0eab858d31396eaf3c52e8"
|
|
68
68
|
}
|
package/src/index.js
CHANGED
|
@@ -111,7 +111,12 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
/**
|
|
115
|
+
* FIXME: Apparently there is a kind of race condition if you have more than one context and you close the page,
|
|
116
|
+
* the browser context is closed but the browser process is broken
|
|
117
|
+
* Related: https://github.com/search?q=repo%3Apuppeteer%2Fpuppeteer%20waitForScreenshotOperations&type=code
|
|
118
|
+
*/
|
|
119
|
+
const withPage = (fn, { closePage: withClosePage = true, timeout: evaluateTimeout } = {}) => {
|
|
115
120
|
const name = fn.name || 'anonymous'
|
|
116
121
|
|
|
117
122
|
return async (...args) => {
|
|
@@ -122,12 +127,12 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
122
127
|
|
|
123
128
|
try {
|
|
124
129
|
page = await createPage(name)
|
|
125
|
-
setTimeout(() => closePage(page, name), timeout).unref()
|
|
130
|
+
setTimeout(() => closePage(page, `${name}:timeout`), timeout).unref()
|
|
126
131
|
const value = await fn(page, goto)(...args)
|
|
127
|
-
await closePage(page, `${name}:success`)
|
|
132
|
+
if (withClosePage) await closePage(page, `${name}:success`)
|
|
128
133
|
return value
|
|
129
134
|
} catch (error) {
|
|
130
|
-
await closePage(page, `${name}:error`)
|
|
135
|
+
if (withClosePage) await closePage(page, `${name}:error`)
|
|
131
136
|
if (!isRejected) throw ensureError(error)
|
|
132
137
|
}
|
|
133
138
|
}
|
|
@@ -192,7 +197,7 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
192
197
|
html: evaluate(page => page.content()),
|
|
193
198
|
page: createPage,
|
|
194
199
|
pdf: withPage(createPdf({ goto })),
|
|
195
|
-
screenshot: withPage(createScreenshot({ goto })),
|
|
200
|
+
screenshot: withPage(createScreenshot({ goto }), { closePage: false }),
|
|
196
201
|
text: evaluate(page => page.evaluate(() => document.body.innerText)),
|
|
197
202
|
getDevice: goto.getDevice,
|
|
198
203
|
destroyContext,
|