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.
Apps can now (as of Chrome 31 I believe) register to handle urls by adding url_handlers in their manifest and detecting the url causing the app to launch in the chrome.app.runtime.onLaunched event. If the app doesn't launch, your hosted web site will be loaded an can present an inline installation with chrome.webstore.install.
Related
I'm developing a chrome packaged app and chrome extension, both of them communicate with one another, and i want to lunch my packaged app from a chrome extension, is there any way to do it?
Note:
I've tried using the launchApp method of chrome management api, but for some unknown reason the chrome.management is undefined in my chrome extension JS code, although i have specified management permission in my manifest file like so:
"permissions": ["management"]
Does anyone have a idea what is the problem, or there are any other way i can do it ?
Thanks for help:)
There are 2 possible reasons for not being able to use chrome.management.
You have not reloaded your extension properly
You are trying to call this from a content script; you can't do that, since a content script has very restricted access to Chrome API. You need to message a background page to do this for you.
That said, there is a better way to do it if you write both your extension and your app. "management" permission is a big hammer and will generate a warning to the user on installation.
Instead, you can send a cross-extension message to your app. It will wake it up and you can launch your main window from there. See this answer for details.
I am creating a Chrome app and I have made a Logout button in the app.
How can I restart/reset the app? (background.js / background page should be restarted)
chrome.runtime API is your friend.
chrome.runtime.reload()
Reloads the app or extension.
Note that this will probably close all windows opened by the app.
Thinking about the user experience I'm not sure if chrome.runtime.reload() is the best what you can do.
It is far much better if you just create a some king of cleanup function which will release unused resources (user's data I mean). The same thing in the app window. If you are using some framework it is probably easy. But in the end reconsider cleaning up instead of rebooting the app.
For my Chrome App, I followed Using Inline Installation guide, and when a website user clicks the installation button the app gets installed.
At the installation time (i.e. chrome.runtime.onInstalled.addListener(function() {}) in background.js), how can the app read a value (of DOM element or JavaScript variable - an ID of the logged in site visitor) from the HTML page hosting the installation button?
All online advise I found, is to use content scripts for extensions. The above-mentioned guide says: "Extensions can communicate with the embedding page via content scripts".
What is a solution for apps?
Sorry, but I don't believe that apps are able to get to the underlying page that they are installed from at all. The idea is that they should be sandboxed in their own private universe and not be able to affect anything outside their own window.
Extensions, on the other hand, are made to be able to access DOM of web pages.
So, I believe to do what you ask you will need to make an extension instead of an app.
If you just need to communicate some small piece of information from the web page to your app, look for another (out of band) method to do this.
I am creating an HTML5 offline web app for use on iOS and Android.
Is there a mechanism for notifying the user that an update is available - e.g., a red dot on the application's shortcut icon? If there isn't, would I be able to achieve this maybe with push notifications or some other way?
I understand that I can use the manifest file to declare which files the app should attempt to update from the server - but my client is asking if the app would be able to visually notify to the user of the need to update.
No, None of the app's code will run unless you launch the app, at which point it will automatically update based on the manifest if you are online. If you are off line then there is no way for the app to check if it needs to be updated.
I have begun using Google Chrome as a primary browser, but I miss my Evernote extension, which can clip a web page directly to the local Evernote application. Is it possible for me to write an extension in Chrome that can do this?
Yes it is possible, through NPAPI, but your local application should be prepared for external communication. Code running in an NPAPI plugin has the full permissions of the current user and is not sandboxed or shielded from malicious input by Google Chrome in any way.
All this is described here:
http://code.google.com/chrome/extensions/npapi.html
To avoid the NPAPI way, another idea would be to communicate with a custom local http server binded to localhost and send requests to it.
Disclaimer: Never tried it but theoretically it should work.
I don't think chrome allows this, simply because it would be dangerous to let plugins have extended priviledges, they even run in an extra, low-rights thread and only communicate with chrome itself through pipes.