Reputation: 1
I am working on a Chrome extension that uses a C++ Native Host. In a background.js script (persistent set to false), using chrome.onstartup event, I create the connection to the C++ Host.
I want my Host to be running for as long as the user is actively using Chrome.
If I close all my current Chrome tabs, independent Chrome processes still appear in the "Background section" of the Task Manager (including my Host process that must be explicitly killed).
I understood that the user can configure the Chrome not to run background processes, but can I design my extension to kill the Host process(disconnect the port) when the user closes all Chrome tabs?
Moreover, the problem becomes more serious if I disable the extension. The Host process becomes a detached process in the background. If enable the extension again, kill all Chrome processed and restart Chrome (as my extension connects to Host on startup of Chrome), I will have multiple Host processes.
Upvotes: 0
Views: 1678
Reputation: 3361
When Chrome terminates or your extension is unloaded, it will send -1
message to your native messaging host. You will have to check for that value, assuming your native messaging host is written in C++ then this is what you should do:
int read_char = ::getchar();
if (read_char == -1) {
// Do termination work here...
}
Upvotes: 2