I am working on a Chrome extension, and at some point I need to exit the browser's process.
I tried closing all windows using this code:
chrome.windows.getCurrent({}, function(window) {
chrome.windows.remove(window.id);
});
and it works on Windows and Linux but not on Mac (because on Mac, closing all windows doesn't mean closing the browser).
Is there a way to close the browser from the extension?
Thanks.
Install the bleeding-edge version of Chrome (get if from the dev channel or use Canary) and create an extension that uses the chrome.processes
API.
It seems that the browser's process has ID 0. So, the following code will terminate Chrome:
chrome.processes.terminate(0);
However, since this is not documented, I suggest to get a list of processes, loop through the list and terminate the browser's process:
chrome.processes.getProcessInfo([], false, function(processes) {
processes.forEach(function(process) {
if (process.type === 'browser') {
chrome.processes.terminate(process.id);
}
});
});
Alternative methods that work in all Chrome versions:
These methods are not very convenient, and all either binary code and/or external applications to work. Therefore, I recommend to use the approach I've outlined in my answer.