• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microlinkhq / browserless / 15132629720

20 May 2025 08:26AM UTC coverage: 85.158%. First build
15132629720

Pull #615

github

web-flow
Merge 9fa660b6e into ed927a9e3
Pull Request #615: chore: use null-prototype-object

219 of 254 branches covered (86.22%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

1158 of 1363 relevant lines covered (84.96%)

2714.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.43
/packages/browserless/src/driver.js
1
'use strict'
2✔
2

2✔
3
const killProcessGroup = require('kill-process-group')
2✔
4
const debug = require('debug-logfmt')('browserless')
2✔
5
const requireOneOf = require('require-one-of')
2✔
6
const pReflect = require('p-reflect')
2✔
7

2✔
8
// flags explained: https://peter.sh/experiments/chromium-command-line-switches
2✔
9
// features explained: https://niek.github.io/chrome-features/
2✔
10
// popular flags: https://github.com/GoogleChrome/chrome-launcher/blob/main/docs/chrome-flags-for-tools.md
2✔
11
// default flags: https://github.com/puppeteer/puppeteer/blob/f2ce480285709a08c385d10df29230d5aac86f59/packages/puppeteer-core/src/node/ChromeLauncher.ts#L200
2✔
12
// AWS Lambda flags: https://github.com/alixaxel/chrome-aws-lambda/blob/78fdbf1b9b9a439883dc2fe747171a765b835031/source/index.ts#L94
2✔
13
const defaultArgs = [
2✔
14
  '--autoplay-policy=user-gesture-required', // https://source.chromium.org/search?q=lang:cpp+symbol:kAutoplayPolicy&ss=chromium
2✔
15
  '--disable-blink-features=PrettyPrintJSONDocument,AutomationControlled', // https://blog.m157q.tw/posts/2020/09/11/bypass-cloudflare-detection-while-using-selenium-with-chromedriver/
2✔
16
  '--disable-domain-reliability', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableDomainReliability&ss=chromium
2✔
17
  '--disable-features=CalculateNativeWinOcclusion,InterestFeedV2,site-per-process', // https://source.chromium.org/search?q=file:content_features.cc&ss=chromium
2✔
18
  '--disable-notifications', // https://source.chromium.org/search?q=lang%3Acpp+symbol%3AkDisablePermissionsAPI&ss=chromium
2✔
19
  '--disable-print-preview', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisablePrintPreview&ss=chromium
2✔
20
  '--disable-setuid-sandbox', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSetuidSandbox&ss=chromium
2✔
21
  '--disable-site-isolation-trials', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSiteIsolation&ss=chromium
2✔
22
  '--disable-speech-api', // https://source.chromium.org/search?q=lang:cpp+symbol:kDisableSpeechAPI&ss=chromium
2✔
23
  '--ash-no-nudges', // https://source.chromium.org/search?q=lang:cpp+symbol:kAshNoNudges&ss=chromium
2✔
24
  '--ignore-gpu-blocklist', // https://source.chromium.org/search?q=lang:cpp+symbol:kIgnoreGpuBlocklist&ss=chromium
2✔
25
  '--no-default-browser-check', // https://source.chromium.org/search?q=lang:cpp+symbol:kNoDefaultBrowserCheck&ss=chromium
2✔
26
  '--no-pings', // https://source.chromium.org/search?q=lang:cpp+symbol:kNoPings&ss=chromium
2✔
27
  '--no-sandbox', // https://source.chromium.org/search?q=lang:cpp+symbol:kNoSandbox&ss=chromium
2✔
28
  '--no-zygote' // https://source.chromium.org/search?q=lang:cpp+symbol:kNoZygote&ss=chromium
2✔
29
]
2✔
30

2✔
31
const spawn = ({
2✔
32
  puppeteer = requireOneOf(['puppeteer', 'puppeteer-core', 'puppeteer-firefox']),
12✔
33
  mode = 'launch',
12✔
34
  args = defaultArgs,
12✔
35
  headless = true,
12✔
36
  ...launchOpts
12✔
37
} = {}) => puppeteer[mode]({ ignoreHTTPSErrors: true, args, headless, ...launchOpts })
12✔
38

2✔
39
const getPid = subprocess => {
2✔
40
  if ('pid' in subprocess) return subprocess.pid
65!
41
  const browserProcess = 'process' in subprocess ? subprocess.process() : undefined
65!
42
  if (browserProcess === undefined || browserProcess === null) return
65!
43
  return 'pid' in browserProcess ? browserProcess.pid : undefined
65!
44
}
65✔
45

2✔
46
const close = async (subprocess, { signal = 'SIGKILL', ...debugOpts } = {}) => {
2✔
47
  const pid = getPid(subprocess)
12✔
48
  if (pid === undefined) return
12!
49

12✔
50
  // It's necessary to call `browser.close` for removing temporal files associated
12✔
51
  // and remove listeners attached to the main process; check
12✔
52
  // - https://github.com/puppeteer/puppeteer/blob/778ac92469d66c542c3c12fe0aa23703dd6315c2/src/node/BrowserRunner.ts#L146
12✔
53
  // - https://github.com/puppeteer/puppeteer/blob/69d85e874416d62de6e821bef30e5cebcfd42f15/src/node/BrowserRunner.ts#L189
12✔
54
  await pReflect('close' in subprocess ? subprocess.close() : killProcessGroup(subprocess, signal))
12!
55

12✔
56
  debug('close', { pid, signal, ...debugOpts })
12✔
57
  return { pid }
12✔
58
}
12✔
59

2✔
60
module.exports = { spawn, pid: getPid, close, defaultArgs }
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc