browserless 9.12.2-0 → 9.12.2
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/LICENSE.md +0 -0
- package/package.json +7 -6
- package/src/index.js +39 -37
package/LICENSE.md
CHANGED
|
File without changes
|
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": "9.12.2
|
|
5
|
+
"version": "9.12.2",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"superlock": "~1.0.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"ps-list": "7",
|
|
48
47
|
"@browserless/test": "^9.11.0",
|
|
49
|
-
"ava": "latest"
|
|
48
|
+
"ava": "latest",
|
|
49
|
+
"ps-list": "7"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": ">= 12"
|
|
@@ -54,13 +54,14 @@
|
|
|
54
54
|
"files": [
|
|
55
55
|
"src"
|
|
56
56
|
],
|
|
57
|
+
"scripts": {
|
|
58
|
+
"test": "ava"
|
|
59
|
+
},
|
|
57
60
|
"license": "MIT",
|
|
58
61
|
"ava": {
|
|
59
62
|
"serial": true,
|
|
60
63
|
"timeout": "30s",
|
|
61
64
|
"workerThreads": false
|
|
62
65
|
},
|
|
63
|
-
"
|
|
64
|
-
"test": "ava"
|
|
65
|
-
}
|
|
66
|
+
"gitHead": "39fe018b091749f5132a70d2644d500696878172"
|
|
66
67
|
}
|
package/src/index.js
CHANGED
|
@@ -109,46 +109,48 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
const withPage =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const task = () =>
|
|
131
|
-
pRetry(run, {
|
|
132
|
-
retries: retry,
|
|
133
|
-
onFailedAttempt: async error => {
|
|
134
|
-
debug('onFailedAttempt', { name: error.name, code: error.code, isRejected })
|
|
135
|
-
if (error.name === 'AbortError') throw error
|
|
136
|
-
if (isRejected) throw new AbortError()
|
|
137
|
-
if (error.code === 'EBRWSRCONTEXTCONNRESET') {
|
|
138
|
-
_contextPromise = createBrowserContext(contextOpts)
|
|
112
|
+
const withPage =
|
|
113
|
+
(fn, { timeout: evaluateTimeout } = {}) =>
|
|
114
|
+
async (...args) => {
|
|
115
|
+
let isRejected = false
|
|
116
|
+
|
|
117
|
+
async function run () {
|
|
118
|
+
let page
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
page = await createPage(args)
|
|
122
|
+
setTimeout(() => closePage(page), timeout).unref()
|
|
123
|
+
const value = await fn(page, goto)(...args)
|
|
124
|
+
await closePage(page)
|
|
125
|
+
return value
|
|
126
|
+
} catch (error) {
|
|
127
|
+
await closePage(page)
|
|
128
|
+
if (!isRejected) throw ensureError(error)
|
|
139
129
|
}
|
|
140
|
-
const { message, attemptNumber, retriesLeft } = error
|
|
141
|
-
debug('retry', { attemptNumber, retriesLeft, message })
|
|
142
130
|
}
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
const timeout = evaluateTimeout || contextTimeout || globalTimeout
|
|
146
131
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
132
|
+
const task = () =>
|
|
133
|
+
pRetry(run, {
|
|
134
|
+
retries: retry,
|
|
135
|
+
onFailedAttempt: async error => {
|
|
136
|
+
debug('onFailedAttempt', { name: error.name, code: error.code, isRejected })
|
|
137
|
+
if (error.name === 'AbortError') throw error
|
|
138
|
+
if (isRejected) throw new AbortError()
|
|
139
|
+
if (error.code === 'EBRWSRCONTEXTCONNRESET') {
|
|
140
|
+
_contextPromise = createBrowserContext(contextOpts)
|
|
141
|
+
}
|
|
142
|
+
const { message, attemptNumber, retriesLeft } = error
|
|
143
|
+
debug('retry', { attemptNumber, retriesLeft, message })
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
const timeout = evaluateTimeout || contextTimeout || globalTimeout
|
|
148
|
+
|
|
149
|
+
return pTimeout(task(), timeout, () => {
|
|
150
|
+
isRejected = true
|
|
151
|
+
throw browserTimeout({ timeout })
|
|
152
|
+
})
|
|
153
|
+
}
|
|
152
154
|
|
|
153
155
|
const evaluate = (fn, gotoOpts) =>
|
|
154
156
|
withPage(
|