【发布时间】:2012-10-29 03:53:40
【问题描述】:
此问题始于 Google Chrome 23 版。当启动事件触发时,我的 Chrome 应用程序会打开一个选项卡以显示其 UI。
chrome.app.runtime.onLaunched.addListener(function()
{
chrome.tabs.create(
{
url: "../../index.html"
});
});
此方案在 Google Chrome 版本 23 之前有效。现在在运行我的应用程序时收到以下异常。
Error in event handler for 'app.runtime.onLaunched': Cannot call method 'create' of undefined TypeError: Cannot call method 'create' of undefined
在开发人员工具中检查chrome 对象后,我注意到chrome.tabs 未定义。
我知道我不必在 manifest.json 中明确设置“tabs”权限,因为根据http://developer.chrome.com/extensions/tabs.html,创建、更新和删除方法不需要“tabs”权限。
在尝试将“tabs”权限显式添加到 manifest.json 文件后,我在 chrome://chrome/extensions/ 上收到此应用程序的消息。
There were warnings when trying to install this extension: 'tabs' is only allowed for extensions and legacy packaged apps, and this is a packaged app.
如果我按照https://developers.google.com/chrome/web-store/docs/choosing 给出的图表并选择了打包的应用程序,因为我的应用程序的 UI 不小,我不打算扩展 Chrome 的 UI 并且我无法使用 chrome.tabs,那么我该如何打开我的应用程序的 UI 在一个新的或现有的选项卡中,而不必创建一个弹出窗口(这很烦人而且对用户不友好)?
【问题讨论】:
-
我没有看到用于 chrome 扩展的 API
chrome.app.runtime,它仅适用于 chrome 应用程序。 developer.chrome.com/apps/api_index.html -
对,它是一个打包的应用程序..
-
所以我认为打包应用程序没有
chrome.tabsAPI。 developer.chrome.com/apps/api_index.html
标签: javascript google-chrome google-chrome-extension google-chrome-devtools