“Cannot read property of undefined” when using chrome.tabs or other chrome API in content script

Content script can only use chrome.i18n, chrome.dom, chrome.storage, and a subset of chrome.runtime/chrome.extension.

Most chrome APIs such as chrome.tabs are only available the background script (service worker in MV3), popup script, etc.

Solution

Pass a message from the content script to the background script and use the API there.

Leave a Comment