Photoshop API. Why the examples don't work?

Does anyone know why the documentation contains examples in JavaScript that do not work? Is there a lot of that there?

In fact you need to know what you are trying to do. I used this recent example for a project.


Could you provide a version of the code to take a look at?

If you just want to create a selection…

document.querySelector("#test2").addEventListener('click',async () =>{   
  await core.executeAsModal(async () => {	  
   const { app, constants } = require("photoshop");
const doc = app.activeDocument;

await doc.selection.selectRectangle(
    {top: 700, left: 700, bottom: 2500, right: 3000},
doc.selection.bounds; // {{top: 50, left: 50, bottom: 100, right: 100}
doc.selection.solid;  // true 
   await app.batchPlay([], {});

app.activeDocument has no property selection


DevTools console

We finished Selection DOM in summer 2023.

So you need PS 25.0+ as documentation says.

And you also need apiVersion 2 in manifest file. It will get turned on by default if your minVersion is high enough. Otherwise, you need to state it explicitly or rather bump min PS version.