browserless 10.7.7 → 10.7.8
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 +43 -39
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.8",
|
|
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": "d253216077d72daa09942484dba75f3cfe365a08"
|
|
68
68
|
}
|
package/src/index.js
CHANGED
|
@@ -79,12 +79,13 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
79
79
|
const getBrowserContext = () => _contextPromise
|
|
80
80
|
|
|
81
81
|
const createPage = async name => {
|
|
82
|
+
const duration = debug.duration('createPage')
|
|
82
83
|
const [browserProcess, browserContext] = await Promise.all([
|
|
83
84
|
getBrowser(),
|
|
84
85
|
getBrowserContext()
|
|
85
86
|
])
|
|
86
87
|
const page = await browserContext.newPage()
|
|
87
|
-
|
|
88
|
+
duration({
|
|
88
89
|
name,
|
|
89
90
|
id: page._client().id(),
|
|
90
91
|
contextId: browserContext.id,
|
|
@@ -95,12 +96,13 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
95
96
|
|
|
96
97
|
const closePage = async (page, name) => {
|
|
97
98
|
if (page && !page.isClosed()) {
|
|
99
|
+
const duration = debug.duration('closePage')
|
|
98
100
|
const [browserProcess, browserContext] = await Promise.all([
|
|
99
101
|
getBrowser(),
|
|
100
102
|
getBrowserContext(),
|
|
101
103
|
pReflect(page.close())
|
|
102
104
|
])
|
|
103
|
-
|
|
105
|
+
duration({
|
|
104
106
|
name,
|
|
105
107
|
id: page._client().id(),
|
|
106
108
|
contextId: browserContext.id,
|
|
@@ -109,48 +111,50 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
const withPage =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
114
|
+
const withPage = (fn, { timeout: evaluateTimeout } = {}) => {
|
|
115
|
+
const name = fn.name || 'anonymous'
|
|
116
|
+
|
|
117
|
+
return async (...args) => {
|
|
118
|
+
let isRejected = false
|
|
119
|
+
|
|
120
|
+
async function run () {
|
|
121
|
+
let page
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
page = await createPage(name)
|
|
125
|
+
setTimeout(() => closePage(page, name), timeout).unref()
|
|
126
|
+
const value = await fn(page, goto)(...args)
|
|
127
|
+
await closePage(page, `${name}:success`)
|
|
128
|
+
return value
|
|
129
|
+
} catch (error) {
|
|
130
|
+
await closePage(page, `${name}:error`)
|
|
131
|
+
if (!isRejected) throw ensureError(error)
|
|
130
132
|
}
|
|
133
|
+
}
|
|
131
134
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
const { message, attemptNumber, retriesLeft } = error
|
|
143
|
-
debug('retry', { attemptNumber, retriesLeft, message })
|
|
135
|
+
const task = () =>
|
|
136
|
+
pRetry(run, {
|
|
137
|
+
retries: retry,
|
|
138
|
+
onFailedAttempt: async error => {
|
|
139
|
+
debug('onFailedAttempt', { name: error.name, code: error.code, isRejected })
|
|
140
|
+
if (error.name === 'AbortError') throw error
|
|
141
|
+
if (isRejected || isDestroyedForced) throw new AbortError()
|
|
142
|
+
if (error.code === 'EBRWSRCONTEXTCONNRESET') {
|
|
143
|
+
_contextPromise = createBrowserContext(contextOpts)
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
const { message, attemptNumber, retriesLeft } = error
|
|
146
|
+
debug('retry', { attemptNumber, retriesLeft, message })
|
|
147
|
+
}
|
|
148
|
+
})
|
|
146
149
|
|
|
147
|
-
|
|
150
|
+
const timeout = evaluateTimeout || contextTimeout || globalTimeout
|
|
148
151
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
return pTimeout(task(), timeout, () => {
|
|
153
|
+
isRejected = true
|
|
154
|
+
throw browserTimeout({ timeout })
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
}
|
|
154
158
|
|
|
155
159
|
const evaluate = (fn, gotoOpts) =>
|
|
156
160
|
withPage(
|