browserless 9.3.19 → 9.4.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 +7 -6
- package/src/driver.js +12 -21
- package/src/index.js +6 -8
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.
|
|
5
|
+
"version": "9.4.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
"text"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@browserless/errors": "^9.3.
|
|
35
|
-
"@browserless/goto": "^9.3.
|
|
36
|
-
"@browserless/pdf": "^9.3.
|
|
37
|
-
"@browserless/screenshot": "^9.3.
|
|
34
|
+
"@browserless/errors": "^9.3.21",
|
|
35
|
+
"@browserless/goto": "^9.3.21",
|
|
36
|
+
"@browserless/pdf": "^9.3.21",
|
|
37
|
+
"@browserless/screenshot": "^9.3.21",
|
|
38
38
|
"debug-logfmt": "~1.0.4",
|
|
39
|
+
"kill-process-group": "~1.0.2",
|
|
39
40
|
"mutexify": "~1.4.0",
|
|
40
41
|
"p-reflect": "~2.1.0",
|
|
41
42
|
"p-retry": "~4.6.1",
|
|
@@ -60,5 +61,5 @@
|
|
|
60
61
|
"timeout": "2m",
|
|
61
62
|
"verbose": true
|
|
62
63
|
},
|
|
63
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "b7b9b8bd304ff3246840c32d024856f122cbf9f3"
|
|
64
65
|
}
|
package/src/driver.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const killProcessGroup = require('kill-process-group')
|
|
3
4
|
const debug = require('debug-logfmt')('browserless')
|
|
4
5
|
const requireOneOf = require('require-one-of')
|
|
5
6
|
const pReflect = require('p-reflect')
|
|
6
|
-
const { promisify } = require('util')
|
|
7
|
-
|
|
8
|
-
const exec = promisify(require('child_process').exec)
|
|
9
7
|
|
|
10
8
|
// flags explained: https://peter.sh/experiments/chromium-command-line-switches
|
|
11
9
|
// default flags: https://github.com/puppeteer/puppeteer/blob/edb01972b9606d8b05b979a588eda0d622315981/src/node/Launcher.ts#L183
|
|
@@ -51,31 +49,24 @@ const spawn = ({
|
|
|
51
49
|
...launchOpts
|
|
52
50
|
} = {}) => puppeteer[mode]({ ignoreHTTPSErrors: true, args, ...launchOpts })
|
|
53
51
|
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return browserProcess.pid
|
|
52
|
+
const pid = subprocess => {
|
|
53
|
+
if ('pid' in subprocess) return subprocess.pid
|
|
54
|
+
const browserProcess = 'process' in subprocess ? subprocess.process() : undefined
|
|
55
|
+
if (browserProcess === undefined || browserProcess === null) return
|
|
56
|
+
return 'pid' in browserProcess ? browserProcess.pid : undefined
|
|
60
57
|
}
|
|
61
58
|
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
? exec(`taskkill /pid ${this.proc.pid} /T /F`)
|
|
65
|
-
: Promise.resolve(process.kill(-pid, signal))
|
|
66
|
-
|
|
67
|
-
const close = async (childProcess, { signal = 'SIGKILL', ...debugOpts } = {}) => {
|
|
68
|
-
const pid = getPid(childProcess)
|
|
69
|
-
if (!pid) return
|
|
59
|
+
const close = async (subprocess, { signal = 'SIGKILL', ...debugOpts } = {}) => {
|
|
60
|
+
if (pid(subprocess) === undefined) return
|
|
70
61
|
|
|
71
62
|
// It's necessary to call `browser.close` for removing temporal files associated
|
|
72
63
|
// and remove listeners attached to the main process; check
|
|
73
64
|
// - https://github.com/puppeteer/puppeteer/blob/778ac92469d66c542c3c12fe0aa23703dd6315c2/src/node/BrowserRunner.ts#L146
|
|
74
65
|
// - https://github.com/puppeteer/puppeteer/blob/69d85e874416d62de6e821bef30e5cebcfd42f15/src/node/BrowserRunner.ts#L189
|
|
75
|
-
await pReflect(
|
|
66
|
+
await pReflect('close' in subprocess ? subprocess.close() : killProcessGroup(subprocess, signal))
|
|
76
67
|
|
|
77
|
-
debug('close', { pid, signal, ...debugOpts })
|
|
78
|
-
return { pid }
|
|
68
|
+
debug('close', { pid: subprocess.pid, signal, ...debugOpts })
|
|
69
|
+
return { pid: subprocess.pid }
|
|
79
70
|
}
|
|
80
71
|
|
|
81
|
-
module.exports = { spawn,
|
|
72
|
+
module.exports = { spawn, pid, close, defaultArgs }
|
package/src/index.js
CHANGED
|
@@ -46,11 +46,9 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
46
46
|
|
|
47
47
|
promise.then(async browser => {
|
|
48
48
|
browser.once('disconnected', getBrowser)
|
|
49
|
-
const pid = driver.getPid(browser)
|
|
50
|
-
|
|
51
49
|
debug('spawn', {
|
|
52
50
|
respawn: isRespawn,
|
|
53
|
-
pid: pid || launchOpts.mode,
|
|
51
|
+
pid: driver.pid(browser) || launchOpts.mode,
|
|
54
52
|
version: await browser.version()
|
|
55
53
|
})
|
|
56
54
|
})
|
|
@@ -99,7 +97,7 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
99
97
|
getBrowserContext()
|
|
100
98
|
])
|
|
101
99
|
const page = await browserContext.newPage()
|
|
102
|
-
debug('createPage', { pid: driver.
|
|
100
|
+
debug('createPage', { pid: driver.pid(browserProcess), id: browserContext._id })
|
|
103
101
|
return page
|
|
104
102
|
}
|
|
105
103
|
|
|
@@ -110,7 +108,7 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
110
108
|
getBrowserContext(),
|
|
111
109
|
pReflect(page.close())
|
|
112
110
|
])
|
|
113
|
-
debug('closePage', { pid: driver.
|
|
111
|
+
debug('closePage', { pid: driver.pid(browserProcess), id: browserContext._id })
|
|
114
112
|
}
|
|
115
113
|
}
|
|
116
114
|
|
|
@@ -156,8 +154,8 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
156
154
|
const evaluate = (fn, gotoOpts) =>
|
|
157
155
|
wrapError(
|
|
158
156
|
page => async (url, opts) => {
|
|
159
|
-
const { response } = await goto(page, { url, ...gotoOpts, ...opts })
|
|
160
|
-
return fn(page, response)
|
|
157
|
+
const { response, error } = await goto(page, { url, ...gotoOpts, ...opts })
|
|
158
|
+
return fn(page, response, error)
|
|
161
159
|
},
|
|
162
160
|
gotoOpts
|
|
163
161
|
)
|
|
@@ -170,7 +168,7 @@ module.exports = ({ timeout: globalTimeout = 30000, ...launchOpts } = {}) => {
|
|
|
170
168
|
const id = browserContext._id
|
|
171
169
|
await pReflect(browserContext.close())
|
|
172
170
|
|
|
173
|
-
debug('destroyContext', { pid: driver.
|
|
171
|
+
debug('destroyContext', { pid: driver.pid(browserProcess), id })
|
|
174
172
|
}
|
|
175
173
|
|
|
176
174
|
return {
|