File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 1
1
import fs from 'fs'
2
2
// import path from 'path'
3
3
import LambdaChromeLauncher from './launcher'
4
- import { debug } from './utils'
4
+ import { debug , processExists } from './utils'
5
5
import DEFAULT_CHROME_FLAGS from './flags'
6
6
7
7
const DEVTOOLS_PORT = 9222
@@ -28,7 +28,7 @@ export default async function launch ({
28
28
} = { } ) {
29
29
const chromeFlags = [ ...DEFAULT_CHROME_FLAGS , ...flags ]
30
30
31
- if ( ! chromeInstance ) {
31
+ if ( ! chromeInstance || ! processExists ( chromeInstance . pid ) ) {
32
32
if ( process . env . AWS_EXECUTION_ENV || forceLambdaLauncher ) {
33
33
chromeInstance = new LambdaChromeLauncher ( {
34
34
chromePath,
Original file line number Diff line number Diff line change @@ -24,3 +24,18 @@ export function makeTempDir () {
24
24
. toString ( )
25
25
. trim ( )
26
26
}
27
+
28
+ /**
29
+ * Checks if a process currently exists by process id.
30
+ * @param pid number process id to check if exists
31
+ * @returns boolean true if process exists, false if otherwise
32
+ */
33
+ export function processExists ( pid ) {
34
+ let exists = true
35
+ try {
36
+ process . kill ( pid , 0 )
37
+ } catch ( error ) {
38
+ exists = false
39
+ }
40
+ return exists
41
+ }
You can’t perform that action at this time.
0 commit comments