0

I am new to the extension development so I am making a chrome extension which gets the content of the web page. It is working but the main problem is i have to reload the page every time to get the data and also the extension. Can you guys help me how to fix this?

myscript.js

var c;
chrome.runtime.onConnect.addListener(function(port){
  port.onMessage.addListener(function(res){
    
var myurl;
  myurl=url goes here; 
  myurl+=params;
      c = res.prd; ///using the response from the content script for further use
      myurl+=c;
      alert(myurl);
      var settings = {
  "async": true,
  "crossDomain": true,
  "url":myurl,
  "method": "GET",
  "headers": {
    "content-type": "application/json"
  }
}
      
$.ajax(settings).done(function (response) {
  console.log(response);
  var a = document.getElementById('result');
  a.innerHTML = "hellow there";

});  //ajax
  }); //onmsg
}); //oncnt

This above code listens the response from the web page and then the myurl variable is for another ajax call and that is for processing the response that came from the content script. But the thing is i have to reload the page every time from which my content script is reading the data from. Can you help me..

this is my manifest file

{
 "manifest_version" : 2 ,
 "name" : "my",
 "version" : "1.0",
 "browser_action":
 {
  "default_popup" : "abc.html"
 },
 "content_scripts": [
     {
        "matches": ["https://www.amazon.in/*","https://www.flipkart.com/*"],
        "js": ["jquery-3.2.1.js","mycontentscript.js"]
     }
    ],
 /*"background" :{
  "scripts" : ["background.js"]
 }, */
 "content_security_policy": "script-src 'self' https://*/ default-src 'self'  "
}

see the thing,, is i am trying to read the DOM contents of the amazon or flipkart like title of the product and etc. But the problem is i have to reload the page every single time, to get the data.. So is there anyway i dont have to reload the page again and again to do the same..?

Dev Solanki
  • 101
  • 1
  • 1
  • 9

0 Answers0