【问题标题】:Google Chrome 'onLaunched' error in plugin插件中的 Google Chrome 'onLaunched' 错误
【发布时间】:2012-09-20 15:17:40
【问题描述】:

我在 http://developer.chrome.com/trunk/apps/first_app.html 上关注 google chrome 网络应用程序开发,但网络应用程序没有启动。当我单击页面上的应用程序图标时,它会关闭选项卡。我已经从 github 下载了示例应用程序和插件,但是当我查看控制台时它们也无法正常工作,我收到此错误,请不要我在 chrome://flags 中启用了实验性 API。

Uncaught TypeError: Cannot read property 'onLaunched' of undefined 

我已将我的 chrome 浏览器更新到版本 22.0.1229.79。我的 manifest.json 文件是

{
"name": "Hello World!",
"description": "My first packaged app.",
"manifest_version": 2,

"version": "0.1",
"app": {
    "background": {
        "scripts": ["background.js"]
    }
},
"icons": {
    "16": "calculator-16.png", 
    "128": "calculator-128.png"
}

}

还有我的 background.js 文件

   chrome.app.runtime.onLaunched.addListener(function() {
    chrome.app.window.create('window.html', {
        'width': 400,
        'height': 500
    });
});

谁能指出我哪里出错了?

【问题讨论】:

  • 我有一个类似的问题 (see here),在我重新启动浏览器后似乎已经解决了。我一直在运行许多选项卡,并且浏览器已经打开了一段时间。
  • 我最终将清单更改为如下所示 { "name": "Qlipe", "description": "Qlipe Chrome app", "manifest_version": 2, "version": "0.1", "app": { "launch": { "local_path": "index.html" } }, "icons": { "16": "Qlipe-16.png", "128": "Qlipe-128.png" }, "permissions": [ "http://www.qlipe.com/api/feed", "http://0.0.0.0:6543/api/feed", "unlimitedStorage" ] 注意我删除了背景 js
  • 有趣。当我有机会时,我会玩它。您是否尝试过指定 background.html 并将 javascript 嵌入其中?

标签: google-chrome google-chrome-extension google-chrome-app


【解决方案1】:

仅在 Chrome 23(目前在开发通道中,很快将在测试通道中)及更高版本中支持新样式的打包应用程序(在清单中的 app 部分中带有 background 键)。

【讨论】:

  • 我们什么时候可以期待它达到稳定,在那之前推荐的解决方法是什么? (在打包的 chrome 应用中做背景页面)
【解决方案2】:

您可以关注 Chromium 开发日历here

【讨论】:

    【解决方案3】:

    获取至少版本 23 的 Chrome 的开发/测试版副本。

    我还必须将以下行添加到 manifest.json 文件中,然后才能运行示例

    {
      ...,
      "minimum_chrome_version": "23",
      ...
    }
    

    【讨论】:

      【解决方案4】:

      如果您在 manifest.json 中省略 "app": {} 声明,也会发生此错误。

      "background": { "scripts": [ "background.js" ] }, 会报这个错误。

      "app": { "background": { scripts": ["background.js"] }, 将正常工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多