Closed Capacity-Dev closed 1 year ago
I don't know if you can load it in the preload script directly.
I load it in the main script and connect it to the preload script with ipcMain
. Then, in the preload script, I use exposeInMainWorld
.
More or less like this:
main.js
import sqlite from "node-sqlite3-wasm";
let database;
ipcMain.handle("db-open", (_evt, path, fileMustExist) => {
database = new sqlite.Database(path, { fileMustExist });
});
preload.js
contextBridge.exposeInMainWorld("db", {
open: (path, fileMustExist) => ipcRenderer.invoke("db-open", path, fileMustExist),
});
renderer.js
await window.db.open(path, false);
I don't know if you can load it in the preload script directly. I load it in the main script and connect it to the preload script with
ipcMain
. Then, in the preload script, I useexposeInMainWorld
.More or less like this:
main.js
import sqlite from "node-sqlite3-wasm"; let database; ipcMain.handle("db-open", (_evt, path, fileMustExist) => { database = new sqlite.Database(path, { fileMustExist }); });
preload.js
contextBridge.exposeInMainWorld("db", { open: (path, fileMustExist) => ipcRenderer.invoke("db-open", path, fileMustExist), });
renderer.js
await window.db.open(path, false);
It Works, Thank you !
I'm creating an electron App then i want to use node-sqlite3-wasm I was using better-sqlite3 before, to switch to node-sqlite3-wasm, I just changed the lines:
to
of course I also changed the request methods like
db.prepare()
to equivalents...but when i run my app, i get this error :
i included the module from
preload.js
and serve it toindex.html
viacontextBridge.exposeInMainWorld
can sameone tell me how to solve this problem please ?