This is my preload.js file in electron application
window.onload = () => {
const $ = require('jquery');
//const sqlite3 = require('sqlite3').verbose();
//const db = new sqlite3.Database(':memory:');
var form_div="";
document.querySelector("#ppage_btn").addEventListener("click"()={
//console.log("ppage_btn renderer file");
$('#form-div input').each(function() {
$(this).attr('value', $(this).val());
});
form_div = $("#form-div").clone();
var elements = document.getElementsByClassName("cats");
while(elements.length > 0){
elements[0].parentNode.removeChild(elements[0]);
}
var divToPrint = document.getElementById("form-div");
var db_data = divToPrint.outerHTML;
db.serialize(function() {
db.run("CREATE TABLE invoices (codeblock TEXT)");
var stmt = db.prepare("INSERT INTO invoices VALUES (?)");
stmt.run(db_data);
stmt.finalize();
});
newWin= window.open("");
newWin.document.write(divToPrint.outerHTML);
newWin.print();
newWin.close();
});
}
Whenever i un-comment these lines
//const sqlite3 = require('sqlite3').verbose();
//const db = new sqlite3.Database(':memory:');
and click on #ppage_btn button to save and print the form ,no error shows and the whole app window crushes ..
is there any proper way to add sqlite3 in preload.js file ?