-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
index.js
41 lines (33 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import process from 'node:process';
import fkill from 'fkill';
import psList from 'ps-list';
import windows from './windows.js';
export default async function killTabs(options = {}) {
const list = process.platform === 'win32' ? await windows(options) : await psList();
const processes = {
chrome: process.platform === 'darwin' ? 'Chrome Helper' : 'chrome',
chromium: process.platform === 'darwin' ? 'Chromium Helper' : 'chromium',
brave: process.platform === 'darwin' ? 'Brave Browser Helper' : 'brave',
edge: process.platform === 'darwin' ? 'Microsoft Edge Helper' : 'edge',
};
if (options.chromium === false) {
delete processes.chromium;
}
if (options.chrome === false) {
delete processes.chrome;
}
if (options.brave === false) {
delete processes.brave;
}
if (options.edge === false) {
delete processes.edge;
}
const pids = list
.filter(process_ =>
Object.keys(processes).some(name => process_.cmd.includes(processes[name]))
&& process_.cmd.includes('--type=renderer')
&& !process_.cmd.includes('--extension-process'),
)
.map(process_ => process_.pid);
return fkill(pids, {force: true});
}