popup.htmlのid='tmpBtn'がクリックされた際にbackground.jsにオブジェクトを渡す処理です。
popup.js側の処理
document.getElementById("tmpBtn").onclick = function(e){ chrome.tabs.query({ active: true, lastFocusedWindow: true }, (tabs) => { let curerntTab = tabs[0]; sendBackground(curerntTab); }); } function sendBackground(curerntTab) { chrome.runtime.sendMessage({ tab: curerntTab.id }, (response) => { document.getElementById("tmpdiv").textContent = response.msg; }); }
background.js 側の処理
chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { sendResponse({ msg: request.tab; }); } );