How to properly kill a lighthouse process prematurely?
See original GitHub issueLet’s say for some reason I want to kill the lighthouse process and all it’s child processes before the run has completed, how could I achieve this? In an asynchronous way would be best, so I can stop program execution until I know all the chrome processes have been killed properly.
Is it as simple as chrome.kill()
, assuming chrome is an instance of chrome-launcher, and lighthouse is running on this via port
?
The reason I am doing this is because I want to run lots and lots of lighthouse instances sequentially in a single node.js process. It seems to work fairly smoothly and reliably if the lighthouse runs finish properly, but not so well if my custom timeout function fires, triggering chrome.kill
and then going to the next url to audit.
I’m purposefully leaving out any error messages I have been getting so that the bot doesn’t pick them up and sideline me! 😉
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (1 by maintainers)
Top GitHub Comments
For anyone reading this, I’ve tried just about everything including
execa()
, bluebird, loads of promise/process libraries, with varying amounts of success (biased to our use-case) and found that the simplest way was to usechromelauncher
, and justchrome.kill()
instance when I need to abort. I have had to accept that some buffer time is necessary to ensure chrome dies and cleans up properly before trying the next run.If you just need the LHR object in memory (and not the artifacts) you can send the JSON output to stdout out and parse it in your node script to avoid hitting the filesystem.
One of our implementations does this for example and only pulls in the artifacts from disk for debug runs (see link below)
https://github.com/patrickhulce/dzl-lighthouse/blob/c77e0b37ca05777d24d3c232878c6987b2e855ab/cli/lib/collectors/local.js#L83-L101
And don’t forget you’re always free to write your own javascript file that invokes LH, puts the result wherever you need them to go and run that script in a separate process instead of LH directly too 😃