You Are Here: Home » How-To » Programming

How To Prevent An Extension To Communicate With Your Chrome Extension? [Chrome App Dev]

By Debjit on July 18th, 2013 
Advertisement

Chrome Applications Development provides you with an API using which you can easily communicate with various other extensions which the user might have installed. Vice-Versa is also possible which means another Chrome application / extension can also communicate with your extension.The technical jargon for above in Chrome Dev terms is known as message passing, and you might already know this.

At times it is possible that you might not want a particular extension to send any data to the extension that you have built. How can we do this? Here is a simple code snippet using which you can disable any other Chrome Extension to communicate with your chrome extension.

Step 1: Get the ID of the Chrome Extension to which you want to block the access. You can get the ID of any Chrome Web Extension from the URL of the extension in the Chrome Webstore:

Chrome Extension get ID from Chrome webstore

Chrome Extension get ID from Chrome webstore

 

Step 2: Now, put the following code snippet in the background script file of your extension. Please note that you have to replace the word blacklistedExtension in the code below with the ID of the extension that you got from above step.

// For simple requests:
chrome.runtime.onMessageExternal.addListener(
  function(request, sender, sendResponse) {
    if (sender.id == blacklistedExtension)
      return;  // don't allow this extension access
    else if (request.getTargetData)
      sendResponse({targetData: targetData});
    else if (request.activateLasers) {
      var success = activateLasers();
      sendResponse({activateLasers: success});
    }
  });

Now, you have successfully blacklisted a chrome extension from communicating with your chrome extensions using message passing. These are useful in cases where malware extensions are deliberately trying to send junk data to your extension. Please let us know if this was helpful. You can also talk to us or hire us for all your Chrome Application development requirements or any other queries in general.

Advertisement







How To Prevent An Extension To Communicate With Your Chrome Extension? [Chrome App Dev] was originally published on Digitizor.com on July 18, 2013 - 2:10 am (Indian Standard Time)