0

Here I have taken permission for all the needed thing, if something missing here please let me know.

Manifest.json

  {

  "manifest_version": 2,

  "name": "SearchMood",
  "description": "This extension shows Google Web Search and Google Image 
   Search result.",
  "version": "1.4",
  "author":"Searchmood",

  "browser_action": {
    "default_icon": {
      "128": "icon-128.png",
      "16": "icon-16.png",
      "48": "icon-48.png"
    },
    "default_title": "SearchMood",
    "default_popup": "background.html"
  },

  "chrome_url_overrides" : {
    "newtab": "popup.html"
  },

  "icons": {
    "128": "icon-128.png",
    "16": "icon-16.png",
    "48": "icon-48.png"
  },
  "background": {
    "scripts": [ "background.js","popup.js" ]
    },
   "permissions": [
    "activeTab","management","https://ajax.googleapis.com/"
  ],

  "content_scripts": [
    {
      "matches": [ "http://search.searchmood.com/*" ],
      "js": [ "js/restoremodal.js" ],
      "all_frames": true,
      "run_at": "document_start"
    }
],
  "externally_connectable": {
  "matches": ["http://*.searchmood.com/*"]
}
}

Script on my web page I have:

     <div class="links">

                        <ul>

                         <li><a href="terms.php">Terms&Conditions</a></li>&nbsp;|&nbsp;

                         <li><a href="privacy.php">Privacy policy</a></li>|&nbsp;

                         <li><a href="Contact.php">Contact US</a></li>
             <li><span id="restoreLink" onclick="adi();">Reset Chrome</span></li>
                        </ul>

                      </div>


        <script type="text/javascript">

function adi(){
      var editorExtensionId = "pokioadkjpcbalcpfidmlebofahebkhb";
    // Make a simple request:
    chrome.runtime.sendMessage(editorExtensionId, {request: "uninstall"});
}
     </script>

And this is the code in my extension to listen To this message I have put this code in popup.js. Please guide me where to put that also.

 chrome.runtime.onMessageExternal.addListener(
  function(request, sender, sendResponse) {
    if (request == "uninstall") {
       var id = chrome.app.getDetails().id;
       chrome.management.setEnabled(id, false); 
    }
  });

This the script I have written. I have some other codes also but that is also not working.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

Yes I got the answer In the content Script File We can write code for taking the element from Website And their we will use SendMessage function Make sure You have taken permission for "Management" in manifest.json And persistent in Menifest.json should be "false".

Then you can use onmessage function and disable your extension Codes for your reference:

**HTML**`<span id="restorelink"> disable chrome extension</span>`

**menifest.json**

    {
  "manifest_version": 2,

  "name": "name",
  "description": "describe about you extension",
  "version": "1",

  "browser_action": {
    "default_icon": {
      "128": "icon-128.png",
      "16": "icon-16.png",
      "48": "icon-48.png"
    },
  "background": {
    "scripts": [ "background.js"],
    "persistent": false
    },
   "permissions": [
    "management"
  ],

  "content_scripts": [
    {
      "matches": [ "http://your site url where you want to apply the change, you can use more than one seperating with "," ],
      "js": [ "restoremodal.js" ],
      "all_frames": true
    }
]
}

**restoremodal.js**

     document.getElementById("restoreLink").addEventListener("click", adi);
 function adi(){
 chrome.runtime.sendMessage({ value: "anything"});
 }


**Background.js**
chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    if (request.value=="anything") {
    var id = chrome.app.getDetails().id;
    chrome.management.setEnabled(id, false); 
    }

  });