Я нашел ответ в Google Docs:
Избегайте перекрестных выборок в скриптах контента
Старый скрипт контента, делая перекрестныйисходная выборка:
var itemId = 12345;
var url = "https://another-site.com/price-query?itemId=" +
encodeURIComponent(request.itemId);
fetch(url)
.then(response => response.text())
.then(text => parsePrice(text))
.then(price => ...)
.catch(error => ...)
Новый скрипт содержимого, запрашивающий его фоновую страницу для извлечения данных:
chrome.runtime.sendMessage(
{contentScriptQuery: "queryPrice", itemId: 12345},
price => ...);
Новый фон расширениястраницы, извлекаемые из известного URL и ретранслирующие данные:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.contentScriptQuery == "queryPrice") {
var url = "https://another-site.com/price-query?itemId=" +
encodeURIComponent(request.itemId);
fetch(url)
.then(response => response.text())
.then(text => parsePrice(text))
.then(price => sendResponse(price))
.catch(error => ...)
return true; // Will respond asynchronously.
}
});
https://www.chromium.org/Home/chromium-security/extension-content-script-fetches