How do I handle options in a packaged Chrome App?

ⅰ亾dé卋堺 提交于 2019-12-10 22:49:58

问题


I want to deploy an existing JS app as a Packaged Crome App to make it distributable in the Chrome Web Store.

In "legacy packaged apps", there is/used to be a way to specify an options_ui page (in old legacy (legacy-legacy?) apps it was options_page) which would be accessible via a special link from your app, or by automatic link from from within chrome://extensions.

There doesn't seem to be any mention about how to migrate the options_* feature, but if the manifest.json of a Chrome App has the options_ui key it generates the following warning on the extensions page:

  • 'options_ui' is only allowed for extensions and legacy packaged apps, but this is a packaged app.

(References)

  • Chrome Developer: Migrating from a Packaged App to a Chrome App or Extension
  • Stack Overflow: Difference between a Packaged App and a Legacy Packaged App in Chrome

回答1:


You can create a context menu item on your icon to open your options.

Add the "contextMenus" permission, then add something like this to your background page:

chrome.runtime.onInstalled.addListener(function() {
  chrome.contextMenus.create({ id: "options", title: "Options", contexts: ["launcher"] })
})

chrome.contextMenus.onClicked.addListener(function(info) {
  if(info.menuItemId == "options") {
    chrome.app.window.create("options.html")
  }
})


来源:https://stackoverflow.com/questions/31645683/how-do-i-handle-options-in-a-packaged-chrome-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!