I have a Google Sheets Add-on which uses the dialog boxes provided by the App Script Ui service, i.e., SpreadSheetApp.getUi().alert(...)
. This normally works fine unless a user does not select an option or close the alert within 5 minutes (say they switch to a different tab or leave their computer), in which case a "Timed out" exception is thrown.
My code:
var ui = SpreadsheetApp.getUi();
var response = ui.alert(msg, ui.ButtonSet.YES_NO);
return (response == ui.Button.YES);
And the error in the Apps Script execution transcript:
[18-02-27 16:40:18:080 EST] Starting execution
[18-02-27 16:40:18:096 EST] SpreadsheetApp.getUi() [0 seconds]
[18-02-27 16:45:18:160 EST] Ui.alert([Are you sure you want to delete this
thing?, YES_NO]) [300.063 seconds]
[18-02-27 16:45:18:166 EST] Execution failed: Timed out waiting for user
response (line 289, file "Code") [300.066 seconds total runtime]
After the exception is thrown the alert is still visible, and if a user comes back and hits "Yes" the above function still does not return true. It just closes the dialog and the user has to try again.
If I only add a try/catch around the alert, the user won't know that the alert has become useless after 5 minutes. Ideally I could call something like alert.close()
but there is no methods like that I can find. Is there a better way of dealing with this, or should I just switch to using HTML/javascript for the alerts?