Расширение Google Chrome: chrome.runtime.sendmessage - PullRequest
0 голосов
/ 16 марта 2019

Чтобы предотвратить блокировку перекрестного чтения (CORB) -Команда Chromium рекомендует для запросов fetch или xhr выполняться в фоновом сценарии, а не в сценариях содержимого.

function request() {
let fetchedData;
Chrome.runtime.sendmessage ({type: 'fetchdata'},
(res) => {
 console.log(res)// The response is seen on the console
fetchedData = res;
});

return fetchedData;
}

console.log(request())//Returns undefined or nothing.

Как передать возвращенный ответ в переменную fetchedData.

...