Check whether user has a Chrome extension installed

Google Chrome Extensions are browser extensions that modify the Google Chrome browser. These extensions are written using web technologies like HTML, JavaScript, and CSS. Google Chrome Extensions are downloadable through the Chrome Web Store.In this post i am going to show you how you can check whether user has a Chrome extension installed.

Chrome now has the ability to send messages from the website to the extension so today i am going to use that ability. basically  i will try to send message from web application and try to get response and if  we got proper response it means user has a Chrome extension installed otherwise  we can ask user to install specific extension.

So this is how your extension (i.e .js file)  will looks like:

chrome.runtime.onMessageExternal.addListener(
function(req, sender, callback) {
if (req) {
if (req.message) {
if (req.message == "installed") {
callback(true);
}
}
}
return true;
});

Now go to your manifest.json file and make sure you have add “externally_connectable” which is used to add domains list which can send message to your extension you can add multiple domains in form of array. It will looks like this:-

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

 

Now you are ready to send message from your website to extension now use following code in your website to check if app installed:-

function IsExist(extensionId,callback){
chrome.runtime.sendMessage(extensionId, { message: "installed" },
function (reply) {
if (reply) {
callback(true);
}else{
callback(false);
}
});
}

 

and now you can use this function as bellow:-

 

IsExist("Your extension id",function(installed){
if(!installed){
alert("Please install extension ");
}
});

 

 

 

 

Add a Comment

Your email address will not be published. Required fields are marked *