browserless 9.6.0 → 9.6.3
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 +7 -7
- package/src/index.js +16 -19
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.6.
|
|
5
|
+
"version": "9.6.3",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@browserless/errors": "^9.3.21",
|
|
35
|
-
"@browserless/goto": "^9.6.
|
|
36
|
-
"@browserless/pdf": "^9.6.
|
|
37
|
-
"@browserless/screenshot": "^9.6.
|
|
35
|
+
"@browserless/goto": "^9.6.2",
|
|
36
|
+
"@browserless/pdf": "^9.6.2",
|
|
37
|
+
"@browserless/screenshot": "^9.6.2",
|
|
38
38
|
"debug-logfmt": "~1.0.4",
|
|
39
39
|
"kill-process-group": "~1.0.3",
|
|
40
|
-
"mutexify": "~1.4.0",
|
|
41
40
|
"p-reflect": "~2.1.0",
|
|
42
41
|
"p-retry": "~4.6.1",
|
|
43
42
|
"p-timeout": "~4.1.0",
|
|
44
|
-
"require-one-of": "~1.0.16"
|
|
43
|
+
"require-one-of": "~1.0.16",
|
|
44
|
+
"superlock": "~1.0.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@browserless/test": "latest",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"timeout": "2m",
|
|
62
62
|
"verbose": true
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "8dbf4161e851ea9c51341301150c32cf1afaab9c"
|
|
65
65
|
}
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const createScreenshot = require('@browserless/screenshot')
|
|
|
5
5
|
const debug = require('debug-logfmt')('browserless')
|
|
6
6
|
const createGoto = require('@browserless/goto')
|
|
7
7
|
const createPdf = require('@browserless/pdf')
|
|
8
|
-
const
|
|
8
|
+
const { withLock } = require('superlock')
|
|
9
9
|
const pReflect = require('p-reflect')
|
|
10
10
|
const pTimeout = require('p-timeout')
|
|
11
11
|
const pRetry = require('p-retry')
|
|
@@ -14,7 +14,7 @@ const { AbortError } = pRetry
|
|
|
14
14
|
|
|
15
15
|
const driver = require('./driver')
|
|
16
16
|
|
|
17
|
-
const lock =
|
|
17
|
+
const lock = withLock()
|
|
18
18
|
|
|
19
19
|
module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
20
20
|
const goto = createGoto({ timeout: globalTimeout, ...launchOpts })
|
|
@@ -58,28 +58,23 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
58
58
|
|
|
59
59
|
let browserProcessPromise = spawn()
|
|
60
60
|
|
|
61
|
-
const createBrowserContext =
|
|
62
|
-
getBrowser().then(browser => browser.createIncognitoBrowserContext())
|
|
61
|
+
const createBrowserContext = contextOpts =>
|
|
62
|
+
getBrowser().then(browser => browser.createIncognitoBrowserContext(contextOpts))
|
|
63
63
|
|
|
64
64
|
const getBrowser = async () => {
|
|
65
65
|
if (isClosed) return browserProcessPromise
|
|
66
66
|
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return browserProcess
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
await respawn()
|
|
76
|
-
release()
|
|
67
|
+
const browserProcess = await lock(async () => {
|
|
68
|
+
const browserProcess = await browserProcessPromise
|
|
69
|
+
if (browserProcess.isConnected()) return browserProcess
|
|
70
|
+
respawn()
|
|
71
|
+
})
|
|
77
72
|
|
|
78
|
-
return getBrowser()
|
|
73
|
+
return browserProcess || getBrowser()
|
|
79
74
|
}
|
|
80
75
|
|
|
81
|
-
const createContext = async ({ retry = 2, timeout: contextTimeout } = {}) => {
|
|
82
|
-
let _contextPromise = createBrowserContext()
|
|
76
|
+
const createContext = async ({ retry = 2, timeout: contextTimeout, ...contextOpts } = {}) => {
|
|
77
|
+
let _contextPromise = createBrowserContext(contextOpts)
|
|
83
78
|
|
|
84
79
|
const getBrowserContext = () => _contextPromise
|
|
85
80
|
|
|
@@ -87,7 +82,7 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
87
82
|
const browserProcess = context.browser()
|
|
88
83
|
browserProcess.once('disconnected', async () => {
|
|
89
84
|
await getBrowser()
|
|
90
|
-
_contextPromise = createBrowserContext()
|
|
85
|
+
_contextPromise = createBrowserContext(contextOpts)
|
|
91
86
|
})
|
|
92
87
|
})
|
|
93
88
|
|
|
@@ -137,7 +132,9 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
137
132
|
debug('onFailedAttempt', { name: error.name, code: error.code, isRejected })
|
|
138
133
|
if (error.name === 'AbortError') throw error
|
|
139
134
|
if (isRejected) throw new AbortError()
|
|
140
|
-
if (error.code === 'EBRWSRCONTEXTCONNRESET')
|
|
135
|
+
if (error.code === 'EBRWSRCONTEXTCONNRESET') {
|
|
136
|
+
_contextPromise = createBrowserContext(contextOpts)
|
|
137
|
+
}
|
|
141
138
|
const { message, attemptNumber, retriesLeft } = error
|
|
142
139
|
debug('retry', { attemptNumber, retriesLeft, message })
|
|
143
140
|
}
|