Beginner here :)
I am getting the following error: Failed to make request: Cannot read properties of undefined (reading 'writeText')
I made a button in my embedded js file that would copy to clipboard a global variable (html table that was generated by js) in a GET request.
It doesn't work locally and even if that was the issue I tested it on the secure website (https) and it also didn't work.
Everything I can find is made for the DOM and as far as I understand I can't use that in a JS with express js file.
app.get("/copyToClipboard", async (req, res) => { try { console.log("inside copy to clip"); await navigator.clipboard.writeText(tableFull); res.render("index.ejs"); } catch (error) { console.error("Failed to make request:", error.message); res.render("index.ejs", { error: error.message, }); } // res.sendFile(__dirname +"/index.html");});
I tried using a clipboard tool:clipboardjs.com
It also uses DOM, so didn't work. In desperation, I tried sending it with a POST request, which didn't make sense to me, but I tried anyway.
I tried to find the npm install code for the Clipboard API, but I couldn't find any other packages than what I showed above. It seems like it can find navigator.clipboard, but the problem is arising with writeText