从网页激活Chrome应用程序? [英] Activate chrome app from web page?

查看:93
本文介绍了从网页激活Chrome应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个打包的Chrome应用程序(因为我想访问chrome.socket,所以需要它)。我有一个网站,我想通过点击一个链接来呼叫我的应用程序(如果已安装或要求用户安装它)。这可能吗 ?找不到任何简单的工作流程。

>可能是实现此目的的最佳方式。您也可以使用externally_connectable清单属性声明您的网站可以连接到您的应用程序,然后调用 chrome.runtime.sendMessage chrome.runtime.connect 并在 chrome.runtime中进行处理.onMessage 处理程序。

哪一个更适合取决于您的需求。 url_handlers 是一种更简单的方法,但它会永久性地将链接上的URL分配给您的应用程序,所以如果应用程序不能使用它已安装。 externally_connectable 是一种更难的方式,但它可以在您的网站和应用程序之间进行更加精细的双向通信。



如果需要,您甚至可以使用这两种方法的组合:使用 url_handlers 功能启动应用程序,然后在应用程序启动后建立一个通信频道回到网站启动并运行。


I am building a packaged chrome app (It is needed as I want to access chrome.socket). I have a website from which I would like to call my app (if installed or ask the user to install it) by clicking a link. Is this possible ? Not able to find any easy way for this workflow.

解决方案

The url_handlers might be the best way to achieve this.

You can also use the externally_connectable manifest property to declare that your website can connect to your app, then call chrome.runtime.sendMessage or chrome.runtime.connect from your webpage and handle it in an chrome.runtime.onMessage handler in the app.

Which one is better suited depends on your needs. The url_handlers is an easier way, but it will permanently assign the URL on your link to your app, so you won't be able to use it for anything else if the app is installed. The externally_connectable is a harder way, but it enables a much more elaborate bidirectional communication between your website and the app.

You can even use a combination of the two approaches, if you need: launch the app using the url_handlers feature, then establish a communication channel back to the website once the app is up and running.

这篇关于从网页激活Chrome应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆