0

hi there i am running into a big issue as i am trying to send some request to my server which serves over http which is not secure so basically what i am doing is when a certain page loaded in chrome i executed a content script and pass message to the background script and in background script i want to call ajax request which fetch data from my server and return back respose to the content script but its not working. can someone please help me to solve this ?

MY Background script code is below

    chrome.extension.onMessage.addListener( function (message, sender, res) {
     if(message.msg == "give key") {
       let key = localStorage.getItem('appkey')
       getUrls(message, sender, res)
       return true
     }
    })

   //this method never get called why ?
   async function getUrls(message, sender, response) {
     console.log(key)
     $.ajax({
        url: `http://xxxyyyyy/find?key=${key}`,
        method: 'GET',
        error: () => {
            response({error: 'error'})
        },
        success: function(d){
            response({key: 'MyKey'})
        }
     });
   }

and my content script code is below

  chrome.extension.sendMessage({msg: 'give key'}, function(response) { 
      key = response.key
      console.log(response)
  });
  • Sounds like your content script never runs, probably due to incorrect `matches` in manifest.json. See also [Accessing console and devtools of extension's background.js](https://stackoverflow.com/a/10258029) – wOxxOm Jan 21 '21 at 10:37
  • thanks a lot i was trying this for past 19 hrs, i appreciate your response error was in background script – PRIMIUM ROYAL Jan 21 '21 at 10:58

0 Answers0