Document.save is not a function

async function OnClickSave()
{
  try {
    // error
    // document.save is not a function
    document.save();

    // error
    // Cannot read properties of undefined (reading 'psd')
    let entry = await require('uxp').storage.localFileSystem.getFileForSaving("target.psd");
    document.saveAs.psd(entry);
  }
  catch (error) {
    console.error(error);
  }
}
document.getElementById("btnSave").addEventListener("click", OnClickSave);

I have read this document and used it as is, but I am getting an error.
save docs

And I want to save as tga. No way?

You should sort out where and what type of document object you have. I see with document.getElementById("btnSave") you use DOM document, but with document.save() you try to use Ps Document, which probably is still the DOM one. These are completely different things.

     let entry = await require('uxp').storage.localFileSystem.getFileForSaving("target.psd");
     require('photoshop').app.activeDocument.saveAs.psd(entry);

There is no error, but it doesn’t work.

Did you try to output what you get for entry? Did you check the docs how getFileForSaving() should be used?

Have you defined “document” somewhere. The “document” in

document.getElementById("btnSave").addEventListener("click", OnClickSave);

is referring to your HTML document by default.

Your code makes it look like you are trying to save this HTML document when what I think you’re trying to do is save the active document in Photoshop, though I’m not entirely sure. However, if this is the case, you need to define the active document first:

const app = require('photoshop').app;
const doc = app.activeDocument;