現在のタブ情報を取得する関数
background.js
async function getCurrentTab() {
let queryOptions = { active: true, currentWindow: true };
let [tab] = await chrome.tabs.query(queryOptions);
return tab;
}
使い方
background.js
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
getCurrentTab().then((tab) => {
console.log(tab.id);
});
return true;
});