Chrome扩展程序:关闭Chrome后关闭背景页面 [英] Chrome Extension: close background page after closing Chrome

查看:245
本文介绍了Chrome扩展程序:关闭Chrome后关闭背景页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有背景页面的扩展程序,默认情况下,这会导致Chrome在关闭所有窗口后仍然存在,并将Chrome图标放在系统托盘中.我想避免这种情况-我不想让我的扩展程序在关闭所有Chrome窗口后导致Chrome进程继续存在,也不想让Chrome出现在系统托盘中.

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.

根据仅能找到的文档表示 user 可以在所有扩展程序中全局设置此选项,但这不是我要尝试的方法.我希望扩展名不张扬/不引人注目,并且不想更改用户的浏览器行为.有谁知道如何做到这一点,同时又保留拥有背景页面的功能?

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?

推荐答案

更新

在清单版本2中,您现在可以运行不是持久性的事件页面.事件页面与后台页面非常相似,但仅在扩展程序需要时才加载.

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
  },
  ...
}

此处是有关m .

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

旧答案

当前,如果您的扩展程序在manifest.json文件中定义了背景,则该扩展程序将在启动Chrome之前运行,并在关闭所有Chrome浏览器窗口后继续运行.除非用户像您提到的那样更改其设置.可能会有将来版本的Google Chrome浏览器支持不同的功能,但是您(开发人员)目前无法解决此问题.

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.

背景清单文档

使Chrome提前启动,然后延迟关闭,以便使应用和扩展程序的使用寿命更长.

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

当任何已安装的托管应用,打包应用或扩展程序具有背景"字样时,权限,则在用户启动Chrome之前,Chrome就会(无形地)在用户登录到计算机后立即运行. 背景"指的是背景".权限还会使Chrome继续运行(即使在关闭最后一个窗口之后),直到用户明确退出Chrome.

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.

这篇关于Chrome扩展程序:关闭Chrome后关闭背景页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆