browserless 9.3.20 → 9.3.21

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.
Files changed (2) hide show
  1. package/package.json +7 -6
  2. package/src/driver.js +16 -20
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.3.20",
5
+ "version": "9.3.21",
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.19",
35
- "@browserless/goto": "^9.3.19",
36
- "@browserless/pdf": "^9.3.19",
37
- "@browserless/screenshot": "^9.3.19",
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.1",
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": "9309d51940645ef5225c425cbc6d68b4d89beb4e"
64
+ "gitHead": "1cad664def78a0bc695a98bb5e1786fb41ee90f0"
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,29 @@ const spawn = ({
51
49
  ...launchOpts
52
50
  } = {}) => puppeteer[mode]({ ignoreHTTPSErrors: true, args, ...launchOpts })
53
51
 
54
- const getPid = childProcess => {
55
- if (!childProcess) return null
56
- if (childProcess.pid) return childProcess.pid
57
- const browserProcess = childProcess.process ? childProcess.process() : undefined
58
- if (!browserProcess) return null
59
- return browserProcess.pid
52
+ const getProcess = subprocess => {
53
+ if (!subprocess) return
54
+ if ('process' in subprocess) return subprocess.process()
55
+ if ('pid' in subprocess) return subprocess
60
56
  }
61
57
 
62
- const killProcesssGroupPID = (pid, signal) =>
63
- process.platform === 'win32'
64
- ? exec(`taskkill /pid ${this.proc.pid} /T /F`)
65
- : Promise.resolve(process.kill(-pid, signal))
58
+ const getPid = input => {
59
+ const subprocess = getProcess(input)
60
+ return subprocess ? subprocess.pid : undefined
61
+ }
66
62
 
67
- const close = async (childProcess, { signal = 'SIGKILL', ...debugOpts } = {}) => {
68
- const pid = getPid(childProcess)
69
- if (!pid) return
63
+ const close = async (input, { signal = 'SIGKILL', ...debugOpts } = {}) => {
64
+ const subprocess = getProcess(input)
65
+ if (!subprocess) return
70
66
 
71
67
  // It's necessary to call `browser.close` for removing temporal files associated
72
68
  // and remove listeners attached to the main process; check
73
69
  // - https://github.com/puppeteer/puppeteer/blob/778ac92469d66c542c3c12fe0aa23703dd6315c2/src/node/BrowserRunner.ts#L146
74
70
  // - https://github.com/puppeteer/puppeteer/blob/69d85e874416d62de6e821bef30e5cebcfd42f15/src/node/BrowserRunner.ts#L189
75
- await pReflect(childProcess.close ? childProcess.close() : killProcesssGroupPID(pid, signal))
71
+ await pReflect('close' in subprocess ? subprocess.close() : killProcessGroup(subprocess, signal))
76
72
 
77
- debug('close', { pid, signal, ...debugOpts })
78
- return { pid }
73
+ debug('close', { pid: subprocess.pid, signal, ...debugOpts })
74
+ return { pid: subprocess.pid }
79
75
  }
80
76
 
81
- module.exports = { spawn, getPid, close, defaultArgs }
77
+ module.exports = { spawn, getPid, getProcess, close, defaultArgs }