简体   繁体   English

如何通过javascript启动Chrome打包应用?

[英]How can I launch a Chrome Packaged App through javascript?

I want to be able to launch my packaged chrome app via javascript either on-page or through an extension. 我希望能够通过javascript在页面上或通过扩展程序启动我的打包chrome应用程序。 Am I able to do this? 我能做到吗? I have done a fair amount of research with no answer in either direction. 我做了大量的研究,没有任何一个方向的答案。 Can somebody at least point me in the right direction? 有人至少能指出我正确的方向吗?

chrome.management.launchApp can be used to launch an app in an extension. chrome.management.launchApp可用于在扩展中启动应用程序。

The API reference is available here: https://developer.chrome.com/extensions/management.html#method-launchApp . API参考可在此处获得: https//developer.chrome.com/extensions/management.html#method-launchApp

You can make certain resources in your extension available, and then you should be able to "window.location" to that. 您可以在扩展中提供某些资源,然后您应该能够“window.location”。

The URL scheme is chrome-extension://[PACKAGE ID]/[PATH] . URL方案是chrome-extension://[PACKAGE ID]/[PATH]

Example: 例:

//This is **not** in your packaged app, but in another web page
window.location = "chrome-extension://abdecbedphjijkaed/index.html";

In your packaged app, you'll need to declare which resources can be reached via a url in your manifest: 在您打包的应用程序中,您需要通过清单中的URL声明可以访问哪些资源:

"web_accessible_resources": [
    "images/my-awesome-image1.png",
    "images/my-amazing-icon1.png",
    "index.html"
]

See more: https://developer.chrome.com/extensions/manifest.html#web_accessible_resources 查看更多: https//developer.chrome.com/extensions/manifest.html#web_accessible_resources

NOTE: This might not work. 注意:这可能不起作用。 While the user can use "chrome://" urls, I'm not sure if web pages can 虽然用户可以使用“chrome://”网址,但我不确定网页是否可以

This feature is coming. 此功能即将推出。 See Issue 111422 : Add ability for apps to register for URL handling. 请参阅问题111422 :添加应用程序注册URL处理的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM