Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching Chrome Packaged Web App from Website

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...

like image 293
Gordon Williams Avatar asked Sep 13 '13 09:09

Gordon Williams


2 Answers

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.

like image 63
Vincent Scheib Avatar answered Oct 23 '22 16:10

Vincent Scheib


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 });
like image 23
edrian Avatar answered Oct 23 '22 16:10

edrian