browserless 9.3.14-alpha.1 → 9.3.14

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 +5 -6
  2. package/src/driver.js +12 -10
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.14-alpha.1",
5
+ "version": "9.3.14",
6
6
  "main": "src/index.js",
7
7
  "author": {
8
8
  "email": "hello@microlink.io",
@@ -32,15 +32,14 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "@browserless/errors": "^9.3.0",
35
- "@browserless/goto": "^9.3.14-alpha.1",
36
- "@browserless/pdf": "^9.3.14-alpha.1",
37
- "@browserless/screenshot": "^9.3.14-alpha.1",
35
+ "@browserless/goto": "^9.3.14",
36
+ "@browserless/pdf": "^9.3.14",
37
+ "@browserless/screenshot": "^9.3.14",
38
38
  "debug-logfmt": "~1.0.4",
39
39
  "mutexify": "~1.4.0",
40
40
  "p-reflect": "~2.1.0",
41
41
  "p-retry": "~4.6.1",
42
42
  "p-timeout": "~4.1.0",
43
- "pidtree": "~0.5.0",
44
43
  "require-one-of": "~1.0.15"
45
44
  },
46
45
  "devDependencies": {
@@ -61,5 +60,5 @@
61
60
  "timeout": "2m",
62
61
  "verbose": true
63
62
  },
64
- "gitHead": "bba42d6afadb84831522db8755017bd9b1ee565b"
63
+ "gitHead": "ab94c2a550d86631218340efe7864eee38d2c37e"
65
64
  }
package/src/driver.js CHANGED
@@ -3,7 +3,9 @@
3
3
  const debug = require('debug-logfmt')('browserless')
4
4
  const requireOneOf = require('require-one-of')
5
5
  const pReflect = require('p-reflect')
6
- const pidtree = require('pidtree')
6
+ const { promisify } = require('util')
7
+
8
+ const exec = promisify(require('child_process').exec)
7
9
 
8
10
  // flags explained: https://peter.sh/experiments/chromium-command-line-switches
9
11
  // default flags: https://github.com/puppeteer/puppeteer/blob/edb01972b9606d8b05b979a588eda0d622315981/src/node/Launcher.ts#L183
@@ -58,23 +60,23 @@ const getPid = childProcess => {
58
60
  return browserProcess.pid
59
61
  }
60
62
 
61
- const getChildrenPids = pid => pReflect(pidtree(pid)).then(({ value = [] }) => value)
63
+ const killProcesssGroupPID = (pid, signal) =>
64
+ process.platform === 'win32'
65
+ ? exec(`taskkill /pid ${this.proc.pid} /T /F`)
66
+ : Promise.resolve(process.kill(-pid, signal))
62
67
 
63
68
  const close = async (childProcess, { signal = 'SIGKILL', ...debugOpts } = {}) => {
64
69
  const pid = getPid(childProcess)
65
70
  if (!pid) return
66
71
 
67
72
  // It's necessary to call `browser.close` for removing temporal files associated
68
- // and remove listeners attached to the main process
69
- // see https://github.com/puppeteer/puppeteer/blob/778ac92469d66c542c3c12fe0aa23703dd6315c2/src/node/BrowserRunner.ts#L146
70
- await (childProcess.close
71
- ? pReflect(childProcess.close())
72
- : [...(await getChildrenPids(pid)), pid].map(pid =>
73
- pReflect(Promise.resolve(process.kill(pid, signal)))
74
- ))
73
+ // and remove listeners attached to the main process; check
74
+ // - https://github.com/puppeteer/puppeteer/blob/778ac92469d66c542c3c12fe0aa23703dd6315c2/src/node/BrowserRunner.ts#L146
75
+ // - https://github.com/puppeteer/puppeteer/blob/69d85e874416d62de6e821bef30e5cebcfd42f15/src/node/BrowserRunner.ts#L189
76
+ await pReflect(childProcess.close ? childProcess.close() : killProcesssGroupPID(pid, signal))
75
77
 
76
78
  debug('close', { pid, signal, ...debugOpts })
77
79
  return { pid }
78
80
  }
79
81
 
80
- module.exports = { spawn, getChildrenPids, getPid, close, defaultArgs }
82
+ module.exports = { spawn, getPid, close, defaultArgs }