Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome.app.isInstalled always returns false for Google Chrome extensions?

why does chrome.app.isInstalled always return false for Google Chrome extensions?

Dynamically I add a link element on page load:

<link type="text/css" rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/itemID">

The following is some Javascript that executes when a button has been clicked:

if (!chrome.app.isInstalled) {
 alert('extension is about to be installed!');
 install_extension();
}else{
  alert('extension is installed already.');
}

The first time I clicked the button, Google Chrome asked me if I wanted to install the extension. I agree and the extension was installed correctly. When I refreshed the page, I clicked the button once again and Google CHrome asked me to install the extension once again even when I had installed it 2 minutes ago. In other words, chrome.app.isInstalled always return false even when the extension is installed. Why?

like image 370
oabarca Avatar asked Aug 16 '13 14:08

oabarca


People also ask

How do I get rid of extensions in Chrome that keep coming back?

1) Go to your online Google Account to reset your sync. https://www.google.com/settings/chrome/sync and click the Reset Sync button. This will delete all saved Chrome bookmarks, extensions, and other data from Google's server.

Why do my Chrome extensions keep disabling?

If you see a message saying "Extensions Disabled," it's because Chrome has turned off one or more of your extensions to keep your data safe while you're browsing the Internet. The extensions that Chrome turned off either didn't come from the Chrome Web Store or were determined unsafe.


2 Answers

See chrome.app.isInstalled Always Returns as "false":

chrome.app.isInstalled is meant for use by hosted apps (which define a set of URLs that encompass the app). Extensions can instead indicate that they're installed already by injecting a DOM node into the page (see second half of https://developers.google.com/chrome/web-store/docs/inline_installation#already-installed).

That link describes a strategy for testing if your extension is installed:

  1. Have a content script inject a DOM node into every page. This node should have a very specific ID, e.g., <div id='my-extension-installed-with-id-sdgdthsdfgdtyjufwknsdkos'>

  2. On button press, have your page test if that node exists.

  3. If the node exists, the content script is running; therefore, the extension is installed. If it does not exist, assume the extension is not installed.

Injecting a DOM node won't affect the state of app.isInstalled. Instead, you check for the existence of the DOM node as proof of the extensions presence.

like image 72
apsillers Avatar answered Sep 19 '22 14:09

apsillers


Another solution is to employ externally_connectable.

Since inline install happens from a verified site, you have a set domain on which you want to check that extension exists. Let's say, example.com and its subdomains.

Then, you can define the following in your manifest:

"externally_connectable" : {
  "matches" : [
    "*://*.example.com/*"
  ]
}

This will expose chrome.runtime.sendMessage to the example.com domain.

You can then set up a message listener for onMessageExternal in your extension that will reply to a "ping" from the page.

For more details see this answer.

like image 43
Xan Avatar answered Sep 21 '22 14:09

Xan