Cleaning up Chrome's background mode behavior on Mac

1,914 views
Skip to first unread message

Avi Drissman

unread,
Nov 11, 2022, 3:33:10 PM11/11/22
to chromium-...@chromium.org
Hi folks! A note from the Chrome Mac team.

Since the inception of background mode in Chrome, Chrome on the Mac has added itself as a login item if there was an extension requesting background mode. This was never documented, and it doesn't keep an extension running while Chrome is not running.

Given that, and given new complications with running code at login on new releases of macOS, starting with Chrome 109 we will no longer be automatically adding Chrome as a login item in this situation.

If having Chrome launched on login specifically benefits your extension, you may want to add instructions to your help center for adding Chrome as a login item.

Thank you for your extensions,

Avi and the Chrome Mac team

Jackie Han

unread,
Nov 12, 2022, 12:02:57 AM11/12/22
to Avi Drissman, chromium-...@chromium.org
This was never documented, and it doesn't keep an extension running while Chrome is not running.

This is actually documented here.
Screenshot 2022-11-12 at 12.52.06.png

Hi Avi,

I don't care about "Open at Login" for Chrome. I only care about running extensions when the user close the last tab (no window, but Chrome still runs), i.e. "Allow in the Background". Is there a way for Chrome to support this? Details see this discussion https://groups.google.com/a/chromium.org/g/chromium-extensions/c/n9uReJzQv1I/m/E6nS0MfcAwAJ
Screenshot 2022-11-12 at 12.48.59.png




--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/CACWgwAZCy9Ajmq%3D_qwvJK-KqbfAo4dEi6ALceXcmrNWLYF3OOQ%40mail.gmail.com.

Jackie Han

unread,
Nov 12, 2022, 12:16:24 AM11/12/22
to Avi Drissman, chromium-...@chromium.org
Because the user can easily close all the tabs, this results in no window, and all the extension background scripts can't work at this point.

Extensions usually do some background tasks, for example:
  • check for new emails every a few minutes (using alarm api
  • notify user custom reminders (send notifications by alarm)
  • monitor battery level
  • prevent computer sleep (using chrome.power api)

Avi Drissman

unread,
Nov 12, 2022, 12:20:56 AM11/12/22
to Jackie Han, chromium-...@chromium.org
Chrome on the Mac, like all Mac apps, continues to run even when the user closes all windows. As long as the user does not quit Chrome, the lack of open windows should not prevent it from executing background scripts.

Jackie Han

unread,
Nov 12, 2022, 12:29:33 AM11/12/22
to Avi Drissman, chromium-...@chromium.org
As long as the user does not quit Chrome, the lack of open windows should not prevent it from executing background scripts.

Yes, this is the behavior I expect. However, currently Chrome is not this behavior (probably used to be this behavior). In my tests, Chrome stops all extensions' background scripts and normal websites service worker if no one extension has the "background" permission. Is this a bug?

Avi Drissman

unread,
Nov 12, 2022, 12:43:42 AM11/12/22
to Jackie Han, chromium-...@chromium.org
Whatever the behavior of Chrome Mac is with regards to running background scripts with no windows open but Chrome still running, it would be unrelated to and unaffected by the login item change that I made.

Please file a bug with the extensions team, and they can look into it.

Avi

Jackie Han

unread,
Nov 12, 2022, 1:24:36 AM11/12/22
to Avi Drissman, chromium-...@chromium.org
I will file a bug soon.

Another question: When Chrome is initially installed, is the "Allow in the Background"(not "Open at Login") enabled in macOS system settings? I found when it is enabled, background scripts work; when it is disabled or not in there, background scripts can't work.

Jackie Han

unread,
Nov 12, 2022, 2:50:19 AM11/12/22
to Avi Drissman, chromium-...@chromium.org
The bug is submitted: https://bugs.chromium.org/p/chromium/issues/detail?id=1383679

Please help triage it, and notify the extensions team. Thanks

Avi Drissman

unread,
Nov 12, 2022, 2:03:00 PM11/12/22
to Jackie Han, chromium-...@chromium.org
Nothing in that "Allow in the Background" section should have any effect on background scripts. That is referring to our updater system.

Jackie Han

unread,
Nov 12, 2022, 3:20:01 PM11/12/22
to Avi Drissman, chromium-...@chromium.org
Ok, thanks for the clarification to "Allow in the Background". 

Currently, if an extension has no "background" permission in manifest.json on macOS, background scripts can't work when there is no browser window. If this is a bug (background script should work without that permission), I think the new change(don't add Chrome as a login item if the extension has "background" permission) is reasonable (I don't like it either).

I also tested it on Windows 11. When enabled the browser setting "Continue running background apps when Google Chrome is closed",
  • If no extension adds the "background" permission, when the user closes the last window,  Chrome quits completely. Therefore no extensions work.
  • If one extension adds the "background" permission, when the user closes the last window, Chrome and extension background scripts still work.

hrg...@gmail.com

unread,
Nov 12, 2022, 3:49:59 PM11/12/22
to Chromium Extensions, Jackie Han, chromium-...@chromium.org, a...@chromium.org
Also, the "background" permission makes Chrome to auto-start at user logon.
I quote:
"When any installed extension has "background" permission, Chrome runs (invisibly) as soon as the user logs into their computer—before the user launches Chrome."

Jackie Han

unread,
Nov 12, 2022, 10:10:21 PM11/12/22
to hrg...@gmail.com, Chromium Extensions, a...@chromium.org
given new complications with running code at login on new releases of macOS, starting with Chrome 109 we will no longer be automatically adding Chrome as a login item in this situation.

I may have misunderstood the meaning of this sentence. This sentence does not say to remove "background" permission, just remove "open Chrome when login". In other words, the "background" permission has two behaviors:
  1. open browser when user login computer: This behavior will be removed on macOS.
  2. keep browser and extension background scripts running when the user closes the last window: This behavior is not affected and still works. If so, please confirm.

Avi Drissman

unread,
Nov 12, 2022, 10:31:17 PM11/12/22
to Jackie Han, hrg...@gmail.com, Chromium Extensions
1. Chrome will no longer add itself as a login item if there is an extension with background mode. Whether or not Chrome actually launches on user login will depend on whether the user themselves added Chrome as a login item, whether macOS relaunches it, etc.

2. I have made no change in this area. Again, if Chrome is not behaving in this area as you expect, file a bug, but my changes do not have any effect in this area.

Avi

Jackie Han

unread,
Nov 12, 2022, 10:52:32 PM11/12/22
to Avi Drissman, hrg...@gmail.com, Chromium Extensions
Thanks for the confirmation.

I also tested on Chrome Canary 110.0.5415.0.
1. login behavior removed
2. background running behavior still work when no window
Reply all
Reply to author
Forward
0 new messages