New official WXT package! Use @wxt-dev/is-background to check if the current JS context is a background script or service worker.
import { isBackground } from '@wxt-dev/is-background';
isBackground() // true or falseThis is most useful to package developers whose library needs to know if it's running in the background or not, but you're welcome to use it directly in web extensions as well.
Tested and works in Chromium, Firefox, and Safari, both MV2 and MV3.