How to tell if an Extension is installed from a web page?

212 views
Skip to first unread message

Richard Bernstein

unread,
May 11, 2019, 5:35:59 AM5/11/19
to Chromium Extensions
I have web app that needs to know if my extension is installed on the PC. The Extension popup is not opened. Is the background task running at all times? What I want to do is 1) determine if my extension is installed 2) change the default icon and the popup of my Extension. I have been trying to send an External Message by calling this javascript from my html page without much luck:

$(document).ready(function(){
var editorExtensionId = "lamacgnkfoieghfknfigbmhdaei";
alert("here");
// Make a simple request:
chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode",
function(response) {
if (!response.success)
handleError(url);
})

}


I am wondering if the problem is that the Extension (in its closed state) cannot get a message? On the Extension side in the background task I have tried both of these without any luck:

1)
//added to handle message from controller
chrome.runtime.onConnectExternal.addListener(function(port) {
  port.onMessage.addListener(function(msg) {
    // See other examples for sample onMessage handlers.
  });
});


2)
chrome.runtime.onMessageExternal.addListener(
  function(request, sender, sendResponse) {
    if (sender.url == blocklistedWebsite)
      return;  // don't allow this web page access
    if (request.openUrlInEditor)
      openUrl(request.openUrlInEditor);
  });


I have been watching the Network tab in the Chrome Debugger and don't see any messages coming over. I have also added this to my manifest.json

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

Any ideas?

Richard Bernstein

unread,
May 11, 2019, 11:28:28 AM5/11/19
to Chromium Extensions
Thanks Decklin. I am not planning to change the attributes of the Extension from the webpage. Instead I am planning to send a webpage to extension message telling the Extension to change itself. I also plan to send some other instructions, once in a while to the extension from the webpage. Should I be concerned about the security in this scheme? One more security question? My plan is to have the Extension directly upload screen images (under user control) to my AWS S3 data store. This is an archival system. The user can only write, not read. Is this a security hole? Of course access to this function is "controlled" by the web page giving permission to the extension.

Simeon Vincent

unread,
May 13, 2019, 8:14:19 PM5/13/19
to Chromium Extensions
In case others are curious, website-extension messaging is described in the Message Passing documentation.

Assuming you're using an event page ("persistent": false in your manifest.json), I doubt the problem is caused by your background page being suspended. By registering a listener on chrome.runtime.onMessageExternal you're explicitly telling Chrome to restart your suspended background page and to invoke your callback.

I just threw together a demo on Glitch, hopefully it'll help you get on track: https://tourmaline-motion.glitch.me/. Some of the potential issues you might run into are
  1. The extension's ID doesn't match the ID the site expects 
    • By default an unpacked extension will generate a new extension ID on first load
    • You can get a static ID by including the extension's public key in a "key" field of your manifest.json
  2. The URL for your site doesn't match what the extension expects
    • It's very common to use different URLs for your test server when developing locally.
    • The easiest way to address this is to modify externally_connectable URL in manifest.json to match your environment.
    • For the adventurous, you can map your "real" URL to your local machine by modifying your hosts file.

I have been watching the Network tab in the Chrome Debugger and don't see any messages coming over

Messages are passed internally in Chrome, not over the network stack. As such, you won't see extension messages in the network tab. Devtools doesn't have a way to inspect extension messages. Maybe I should an extension to help debug messaging issues…

Simeon - @dotproto
Extensions Developer Advocate

Richard Bernstein

unread,
May 16, 2019, 9:56:27 AM5/16/19
to Chromium Extensions
Thanks. That worked great. No real surprise coding wise, which makes me think it is s problem with my web page which is creating the message. I am using codeigniter to generate the html pages that get displayed to a user. I think my problem is in "calling" the javascript from my html page, or in embedding the javascript in the html generated by codeigniter. I looked in your https://tourmaline-motion.glitch.me/ to see exactly how you are calling the "message sender" and copied both the calling javascript into my html and your alert into my extension's background.  The alert is not firing. Without being able trace the steps with either the chrome debugger's network tab nor with Wireshark, I am unable to see if the payload is being sent correctly. I installed your background code into my extension and also changed  persistent to false, and reloaded the extension. It MUST be the way in which the javascript is being called in the html page, IMO.   

Richard Bernstein

unread,
May 17, 2019, 11:03:44 AM5/17/19
to Chromium Extensions
I got it going. Turned out that the externally connectable in manifest was set to my real URL instead of localhost, that I am testing on!
 Thanks for your help! 

On Saturday, May 11, 2019 at 5:35:59 AM UTC-4, Richard Bernstein wrote:
Reply all
Reply to author
Forward
0 new messages