I have a Chrome Packaged Web app (which is required as it needs to access the Serial Port), and I'd like to be able to launch it from my website (with some data) when I click on a link/button on that website.
It'd be even better if it could detect if the user wasn't running chrome or didn't have the web app installed and could direct them to the right place...
Are there any examples? It seems like an obvious thing to want to do, but I'm really struggling to find anything...
To launch an app you can use url_handlers
, a new feature recently landed (should make Chrome 31). You can pass data in the URL.
You can check if an app is already installed, and initiate the install if not, by using the chrome web store's inline install functionality.
Found a better solution to this problem.
In @Vincent Scheib solution you have to redirect the user to /some/url, or open a new window (that can be actually blocked as popup). All of this it's not so good from an UX aproach.
My solution is to create the app and configure the externally_connectable
. You have to pass the url domain of the web site that will try to open the app. For example:
"externally_connectable": {
"matches": ["*://developer.chrome.com/*"]
}
Then, in your packaged app in your background script, you can do something like this:
chrome.runtime.onMessageExternal.addListener(function(message) {
if(message.launch){ //This parameter will be passed in sendMessage method below
chrome.app.window.create("main.html");
}
});
Finally, to trigger the app open you have to send a message using your packaged app id. For example:
chrome.runtime.sendMessage("mdoedhlejmepngilmgoenbhmipoclckb", { launch: true });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With