-
-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Background service worker : document
is not defined
#392
Comments
Tried to add |
document
is not defined
The function And apparently emscripten has these document .. So I don't have much control over this. |
Same code works in plasmo |
Thanks for the report, I'm adding ESM support to the background (#398), so it should be working after that is in. I'll make sure to re-test this issue once that is merged. |
Thanks for the update. Will look into it. |
Fix released in import initWasm from "@vlcn.io/crsqlite-wasm";
import wasmUrl from "@vlcn.io/crsqlite-wasm/crsqlite.wasm?url";
export default defineBackground({
main() {
initSqlite();
},
});
async function initSqlite() {
const sqlite = await initWasm(() => wasmUrl);
const db = await sqlite.open("database.db");
await db.exec(
"CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY NOT NULL, name TEXT)"
);
const stmt = await db.prepare(
"INSERT OR IGNORE INTO users (name) VALUES (?)"
);
await stmt.run(db, `John Do. Born at ${new Date().toTimeString()}`);
const users = await db.execA<[bigint, string]>("SELECT * FROM users");
console.log("Saved users", users);
} Here's the full code based on your reproduction: working-wasm-example.zip |
- WXT dev fixed the blocking document undefined issue. See wxt-dev/wxt#392
Describe the bug
In background context : If imported code from third party librariries are using
document
, the background script may fail to start or load withUncaught ReferenceError: document is not defined
error.To Reproduce
https://github.com/lionelhorn/wxt-wasm-vlcn-repro
Steps to reproduce the bug using the reproduction:
pnpm i
pnpm dev
chrome://extensions/
wxt-wasm-vlcn-repro
extensionExpected behavior
Background script / service worker to start without errors.
Screenshots
Environment
The text was updated successfully, but these errors were encountered: