Regression: Chrome's Native Messaging stops when all windows closed

206 views
Skip to first unread message

Jerry Krinock

unread,
Sep 8, 2023, 4:56:37 PM9/8/23
to Chromium Extensions
I am developing a manifest v3 Chrome extension, with Native Messaging implemented in a Service Worker.  If I load this  extension unpacked into Google Chrome 116,  then close all windows in Chrome, the Native Messaging process exits and, of course, native messages fail.  This same unexpected exit now occurs for users with the currently shipped manifest v2 version of my extension.  (Of course, the manifest v2 version has Native Messaging implemented in a Background Page.)

I am quite certain that such unexpected exits did not occur in earlier versions of Chrome, several years ago, and definitely these exits are not seen in current versions of other Chromium-based browsers such as Microsoft Edge.  With my same shipped extension installed in Microsoft Edge, Native Messaging continues to work even if all Edge windows are closed.

This new behavior causes an edge case bug for extensions such as, for example, bookmarks syncing.  Users may close all browser windows but still expect their bookmarks to be synced via Chrome Sync to Chrome on other devices.  

The issue does not seem to be that my Service Worker is becoming inactive.  My manifest v3 extension calls `chrome.runtime.onStartup.addListener(() => {});` as correctly suggested in another conversation.  After one of these unexpected exits has occurred, if I open a browser window, a new Native Messaging process is launched, and native messaging resumes working.  The Extensions window does not ever indicate that my Service Worker is inactive.

A possible workaround is that if my native app gets no response and/or AppleScript says that Chrome has no windows open, my native app could quit and relaunch Chrome, or defer the syncing until later.  This would "fix" the problem because Chrome always opens a window upon launching.  But such a kludge would be dangerous, fragile and annoying to the user.

What is the best way to get some attention to this issue?  Is there a better place to report it than in Google Chrome > main menu > Help > Report an Issue ?

wOxxOm

unread,
Sep 9, 2023, 4:55:50 AM9/9/23
to Chromium Extensions, Jerry Krinock
It may be a bug in Chrome on Mac. Note though in Windows and Linux this behavior is correct because when all windows are closed the browser is terminated entirely along with any processes it launched. Try adding "background" to "permissions" in your manifest.json so that your extension still works after the last window is closed. Note this feature can be disabled by the user in browser settings: "Continue running background apps when Google Chrome is closed".

Jerry Krinock

unread,
Sep 9, 2023, 1:32:08 PM9/9/23
to Chromium Extensions, wOxxOm, Jerry Krinock
+10 to wOxxOm!  Adding background  to permissions in manifest.json fixes the problem.

I cannot find a Continue running background apps when Google Chrome is closed  setting in the current version of Chrome, 116.  I see it in the screenshot in Step 4 of this article, which must be of an earlier version of Chrome.  I see the other two settings in that screenshot, but not Continue running background apps….  So that's also good news … apparently the setting has been removed from Chrome so users can no longer disable it, which will mean fewer support emails for me to answer.  Thank you, Chrome :)

Reply all
Reply to author
Forward
0 new messages