Skip to content

Commit

Permalink
Fix Firefox not closing the browser instance on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Aug 22, 2024
1 parent cd47ddc commit cf71c45
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions programs/develop/plugin-browsers/run-firefox/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import {exec} from 'child_process'
import {exec, ChildProcess} from 'child_process'
import {type Compiler} from 'webpack'
import {firefoxLocation} from './firefox-location'
import {browserConfig} from './firefox/browser-config'
Expand All @@ -8,11 +8,21 @@ import * as messages from '../browsers-lib/messages'
import {type PluginInterface} from '../browsers-types'
import {DevOptions} from '../../commands/dev'

let child: ChildProcess | null = null

process.on('SIGINT', () => {
if (child) {
// Send SIGINT to the child process
child.kill('SIGINT')
}
process.exit()
})

process.on('SIGTERM', () => {
if (child) {
// Send SIGTERM to the child process
child.kill('SIGTERM')
}
process.exit()
})

Expand Down Expand Up @@ -50,7 +60,7 @@ export class RunFirefoxPlugin {
const firefoxConfig = await browserConfig(compiler, this)
const cmd = `${firefoxLaunchPath} ${firefoxConfig}`

const child = exec(cmd, (error, _stdout, stderr) => {
child = exec(cmd, (error, _stdout, stderr) => {
if (error != null) throw error
if (stderr.includes('Unable to move the cache')) {
console.log(messages.browserInstanceAlreadyRunning(this.browser))
Expand Down Expand Up @@ -86,7 +96,7 @@ export class RunFirefoxPlugin {
let firefoxDidLaunch = false

compiler.hooks.done.tapAsync(
'run-chromium:module',
'run-firefox:module',
async (compilation, done) => {
if (compilation.compilation.errors.length > 0) {
done()
Expand Down

0 comments on commit cf71c45

Please sign in to comment.