0

目前,即使我正在等待来自 websocket 的数据,后台进程总是处于非活动状态。有没有办法绕过这个?该部门的文档完全不清楚(旧文档等)。这样做的“新”和正确方法是什么?

我的清单文件:

{
  "name": "Media 5",
  "manifest_version": 2,
  "description": "Html5 media center app for Chrome",
  "version": "0.1",
  "app": {
    "background": {
      "persistent": true,
      "scripts": ["background.js"]
    }
  },
  "icons": { "16": "small_icon.png", "128": "big_icon.png"     },
  "sandbox": {
    "pages": ["sandbox.html"]
  },
  "permissions": [
    "unlimitedStorage",
    "fullscreen",
    "notifications", 
    "webview"
  ]
}
4

2 回答 2

3

有很多方法可以防止您的活动页面被卸载,包括此处列出的方法:http: //developer.chrome.com/extensions/event_pages.html。试一试。打开一个消息端口,或将 chrome.alarms 警报设置为大约 5 秒的间隔。我不相信这是记录在案的行为,但事件页面通常会在 10 秒不活动后卸载,所以警报应该让你活着。

我已经提交了一个关于这个的错误;如果您使用的是 websockets,我们避免卸载可能会更聪明。

于 2013-03-17T03:36:31.033 回答
1

Another thing that keeps packaged apps alive is having an active callback. So, for example, you could use setTimeout with a timeout value of say 5 to ensure you app remains alive. This is only a workaround though, and there should be a better way to reconcile lifetime of websockets and packaged apps.

There is a Chromium bug (https://code.google.com/p/chromium/issues/detail?id=204573) tracking this issue.

As an FYI (because this is confusing), the "persistent": true line is currently ignored by Chrome. Packaged Apps (v2) are always set to "persistent": false.

于 2013-06-07T18:29:21.987 回答