chromeの拡張機能で、「ngWord.json」内のデータを「background.js」経由で「content_script.js」に格納しようとしていたのですが、上手くいきません。コードでおかしな点等あれば、ご教授頂けないでしょうか。
【background.js】
fetch('ngWord.json')
.then(response => response.json())
.then(data => {
// content_script.jsにデータを送信
chrome.runtime.sendMessage({ngWords: data});
});
【content_script.js】
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.ngWords) {
const ngWords = message.ngWords;
console.log(ngWords); // 受信したデータを表示
}
});
JavaScript の質問用スレッド vol.125
■ このスレッドは過去ログ倉庫に格納されています
767デフォルトの名無しさん (ワッチョイ a3ad-a1qf [210.250.191.46])
2023/03/20(月) 19:47:12.99ID:PTBUy+ct0■ このスレッドは過去ログ倉庫に格納されています
