0

I'm trying to send a request from popup.js to background.js:

chrome.runtime.sendMessage({
 type: 'login',
 data: {  token: utoken, botname: botname }
}, function(response) {
 console.log(response);
})

In background.js I send the request via fetch and return the response in popup.js:

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
   if (request.type === "login") {
      sendResponse(sendRequestToApi('/login', 'POST', request.token, request.data))
   }
});

function sendRequestToApi(uri, method, token, data) {
   return fetch(global.apiUrl + uri, {
      method: method,
      body: JSON.stringify(data),
      headers: new Headers({
         'Authorization': 'Bearer ' + token,
         'Content-Type': 'application/x-www-form-urlencoded'
      })
   });
}

I still don't get an answer, I don't understand what the problem is

Sdafs Fasafs
  • 109
  • 5

0 Answers0