🔴 ERROR | import() is not allowed in service workers.

I'm trying to import Supabase in a service worker to push save some images but I got this error in the console and I have no idea what I'm doing wrong. Any idea? Here is my background.tsx code:
import { supabase } from "~store";

chrome.action.onClicked.addListener(async tab => {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
chrome.tabs.sendMessage(tabs[0].id, { type: "openKapture" });
});
});

async function getBase64(blob: Blob): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = () => resolve(reader.result as string);
reader.onerror = error => reject(error);
});
}

chrome.runtime.onMessage.addListener(async request => {
switch (request.action) {
case "save-image":
{
const res = await fetch(request.url);
const blob = await res.blob();
const base64 = await getBase64(blob);
await supabase.storage.from("images").upload("test.png", base64);
}
break;
}
});

export {};
import { supabase } from "~store";

chrome.action.onClicked.addListener(async tab => {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
chrome.tabs.sendMessage(tabs[0].id, { type: "openKapture" });
});
});

async function getBase64(blob: Blob): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = () => resolve(reader.result as string);
reader.onerror = error => reject(error);
});
}

chrome.runtime.onMessage.addListener(async request => {
switch (request.action) {
case "save-image":
{
const res = await fetch(request.url);
const blob = await res.blob();
const base64 = await getBase64(blob);
await supabase.storage.from("images").upload("test.png", base64);
}
break;
}
});

export {};
5 Replies
Arcane
Arcane•2y ago
@cdedreuille has reached level 3. GG!
Charles de Dreuille
Charles de DreuilleOP•2y ago
By the way, it doesn't seem to be a problem when importing the store but when I'm adding the line await supabase.storage.from("images").upload("test.png", base64); We can't use any library in a service worker?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Charles de Dreuille
Charles de DreuilleOP•2y ago
Thanks a lot @p6l.richard for looking into it. That's what I ended up doing. I'm new to service workers.
YAGPDB.xyz
YAGPDB.xyz•2y ago
Gave +1 Rep to @p6l.richard
Want results from more Discord servers?
Add your server