I don't use Frames, but as far as I know, a Frame physically consists of at least two "layers".
This is a folder and a layer within that folder.
The result may depend on whether the "folder" or layer within it is currently active.
By @r-bin
Good point, my code above only works if the frame is selected, not the content of the frame (if it exists).
EDIT: This revision will hopefully work better:
/*
Active Frame Dimensions.jsx
v1.1 - 28th April 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-extendscript-frame-bounds/td-p/14583991
*/
#target photoshop
// Frame content active
if (app.activeDocument.activeLayer.parent.name != app.activeDocument.name) {
app.activeDocument.activeLayer = app.activeDocument.activeLayer.parent;
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var frameRect = executeActionGet(ref).getObjectValue(stringIDToTypeID("framedGroup")).getObjectValue(stringIDToTypeID("framedGroupRect"));
var frameRectWidth = new UnitValue(frameRect.getDouble(stringIDToTypeID("right")) - frameRect.getDouble(stringIDToTypeID("left")), "px");
var frameRectHeight = new UnitValue(frameRect.getDouble(stringIDToTypeID("bottom")) - frameRect.getDouble(stringIDToTypeID("top")), "px");
app.activeDocument.activeLayer = app.activeDocument.activeLayer.layers[0];
alert("Frame dimensions - W: " + frameRectWidth.value + "px X H: " + frameRectHeight.value + "px");
// Frame active
} else {
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var frameRect = executeActionGet(ref).getObjectValue(stringIDToTypeID("framedGroup")).getObjectValue(stringIDToTypeID("framedGroupRect"));
var frameRectWidth = new UnitValue(frameRect.getDouble(stringIDToTypeID("right")) - frameRect.getDouble(stringIDToTypeID("left")), "px");
var frameRectHeight = new UnitValue(frameRect.getDouble(stringIDToTypeID("bottom")) - frameRect.getDouble(stringIDToTypeID("top")), "px");
alert("Frame dimensions - W: " + frameRectWidth.value + "px X H: " + frameRectHeight.value + "px");
}