Chrome Extension: close background page after closing Chrome
Asked Answered
R

1

7

I have an extension with a background page, and by default this causes Chrome to persist after you close all windows, and puts the Chrome icon in the system-tray. I would like to avoid this -- I do not want my extension to cause the Chrome process to persist after closing all Chrome windows, nor do I want to cause Chrome to appear in the systray.

According to the only docs I could find on this indicates that the user can set this option globally across all extensions, but that isn't what I'm trying to do. I'd like the extension to be unassuming / unobtrusive, and don't want to change the user's browser behavior. Does anyone know how to accomplish this while retaining the ability to have a background page?

Rhythmist answered 16/8, 2012 at 18:18 Comment(3)
this is simalar to #10152232 but rather than closing the background page right away, I would want to close it when all tabs have been closed, and I also don't want the systray iconRhythmist
You could use event pages instead of the background page. This is the new preferred method anyway as it doesn't require your code to be running constantly, only when it needs to be. developer.chrome.com/dev/extensions/event_pages.htmlDrooff
event pages look awesome! Can't wait for them to become officially released.Reis
R
4

UPDATE

With manifest version 2 you can now run event pages that are not persistent. Event pages are very similar to background pages but are only loaded when needed by the extension.

Example from the event pages doc on setting a non persistent event script in your manifest:

{
  "name": "My extension",
  ...
  "background": {
    "scripts": ["eventPage.js"],
    "persistent": false
  },
  ...
}

Here is a tutorial on migrating your Chrome extension to manifest version 2.


OLD ANSWER

Currently, if your extension has a background defined in the manifest.json file, it will run before Chrome is launched and continue after all windows of Chrome are closed. That is unless the user changes their settings like you mentioned. There may be future versions of Google Chrome that allow for different functionality but you, the developer, won't be able to get around this issue at this time.

An excerpt from the background manifest docs

Makes Chrome start up early and and shut down late, so that apps and extensions can have a longer life.

When any installed hosted app, packaged app, or extension has "background" permission, Chrome runs (invisibly) as soon as the user logs into their computer—before the user launches Chrome. The "background" permission also makes Chrome continue running (even after its last window is closed) until the user explicitly quits Chrome.

Reis answered 17/8, 2012 at 0:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.