в фоновом скрипте
function new_url_listener(tabId, info, tab) {
if(info.url){
get_template(info.url).then(function(template){
console.log(template);
if (template){
chrome.tabs.sendMessage(tab.id, {test:"test"}, function(response) {
console.log(response);
});
}
})
}
}
chrome.tabs.onUpdated.addListener(new_url_listener);
в content.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});
отправляет сообщение, когда chrome.tabs.sendMessage не содержится в get_template.then ()вызов, но мне нужно иметь возможность отправить переменную шаблона в скрипт содержимого
почему он не отправляет в течение вызова тогда?
get_template делает вызов API и получает JSONназад как переменная шаблона