Starting with Photoshop 2026 v27.9, I began getting reports that batchPlay that ran using the return value when closing a modal dialog was giving errors. The attached plugin demonstrates this problem.
The plugin has only one button that opens a modal dialog window.
The code for this button is as follows:
async function openModal(){
document.querySelector("#modalDialog").uxpShowModal({ title: "Modal Dialog", resize: "both", size: { width: 480, height: 200 } });
} //end openModal() function
document.getElementById("openModal").addEventListener("click", openModal);
This is the modal dialog window that the button opens:
Clicking each of the buttons closes the modal dialog and passes the return value to function called “runModalDialogFunction()” :
//Clicking "Cancel" button
document.getElementById('buttonCANCEL').addEventListener('click', function(evt){
evt.preventDefault();
document.getElementById('modalDialog').close("Cancel");
runModalDialogFunction(document.getElementById('modalDialog').returnValue);
});
//Cliking "OK" button
document.getElementById('buttonOK').addEventListener('click', function(evt){
evt.preventDefault();
document.getElementById('modalDialog').close("OK");
runModalDialogFunction(document.getElementById('modalDialog').returnValue);
});
//Cliking "OK + setTimeout" button
document.getElementById('buttonOKplusSetTimeout').addEventListener('click', function(evt){
evt.preventDefault();
document.getElementById('modalDialog').close("OK + setTimeout");
runModalDialogFunction(document.getElementById('modalDialog').returnValue);
});
The “runModalDialogFunction()” takes the return value, logs it out to the UDT console, and, in the case of the “OK” button and the “OK + setTimeout” button, attempts to run a function called “duplicateChanne()” and log the results to the UDT console.
The “OK + setTimeout” button adds an extra 100-ms delay before executing the “duplicateChanne()” function.
function runModalDialogFunction (returnValue) {
console.log(returnValue)
if (returnValue === "OK") { duplicateChannel(); }
if (returnValue === "OK + setTimeout") { setTimeout(function(){ duplicateChannel(); }, 100); }
};
The “duplicateChanne()” function includes batchPlay which duplicates the Red channel using calculations:
async function duplicateChannel () {
try {await exeModal(targetFunction, {"commandName": "Progress..."});}
catch(e) {
if (e.number == 9) {showAlert('Some other plugin is using Photoshop');}
else {showAlert(e)}
};
async function targetFunction(executionControl) {
///////////////////// Start modal execution /////////////////////
await batchPlay([
//Select RGB
{ "_obj": "select", "_target": [ { "_ref": "channel", "_enum": "channel", "_value": "RGB" } ]},
//Duplicate Red Channel using Calculations
{ "_obj": "make", "new": { "_class": "channel" }, "using": { "_obj": "calculation", "to": { "_ref": [ { "_ref": "channel", "_enum": "channel", "_value": "red" }, { "_ref": "layer", "_enum": "ordinal", "_value": "merged" } ] }, "source2": { "_ref": [ { "_ref": "channel", "_enum": "channel", "_value": "red" }, { "_ref": "layer", "_enum": "ordinal", "_value": "merged" } ] } }},
//Select RGB
{ "_obj": "select", "_target": [ { "_ref": "channel", "_enum": "channel", "_value": "RGB" } ]},
],{}).then(result=>console.log(result), error=>console.log(error));
///////////////////// Stop modal execution /////////////////////
} // end targetFunction()
};
When the “OK” button is clicked, the “//Duplicate Red Channel using Calculations” batchPlay fails. The following is the result in the console:
When the “OK + setTimeout” button is clicked, the “//Duplicate Red Channel using Calculations” batchPlay properly executes. The following is the result in the console:
On my Widows computer I have found that I can set the timeout to as little as 10-ms, and the batchPlay will successfully execute, so it appears that 100-ms is plenty of time.
I’m not an expert in modal dialog windows, but this is similar to the code I’ve been using in my other plugins. I only started getting reports of errors from users starting with Photoshop 2026 v27.9.
Am I doing something wrong or is this a new Photoshop bug?
Tagging @karan per Ingo’s recommendation at today’s Office Hours.
modalDialog_PS.ccx (9.7 KB)



