guocaoyi / create-chrome-ext

🍺 Scaffolding your Chrome extension! Boilerplates: react \ vue \ svelte \ solid \ preact \ alpine \ lit \ stencil \ inferno \ vanilla
MIT License
1.72k stars 125 forks source link

adding imports to background/index.ts breaks the extension #89

Open abdullah-tsx opened 3 months ago

abdullah-tsx commented 3 months ago
export const sendToContentScript = <T extends object>(
    message: ToastMessage,
) => {
    chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
        if (tabs.length > 0 && tabs[0].id !== undefined) {
            const activeTabId = tabs[0].id;
            chrome.tabs.sendMessage(activeTabId, message, (response: string) => {
                console.log(response);
            });
        }
    });
};

if this function is defined in background/index.ts it works just fine if i export it to another file background/utils.ts and then import it `import {sendToContentScript} from './utils'. the service worker fails to register and extension keeps flickering.

edit this is not limited to this function