Google Sheets Add-on Script Template error

16 views
Skip to first unread message

Brad Smith

unread,
May 26, 2015, 12:11:33 PM5/26/15
to google-ca...@googlegroups.com
I'm working on a Sheets Add-on and chose the Google Sheets Add-on Script  as a starting point rather than creating a blank project.  The canned script included in the template has sample code for opening a dialog and sidebar from the add-on menu of the associated spreadsheet.  The script adds the sub-menus,: 'Show dialog' and 'Show sidebar'.  However, when I select either of those menu items the script errors out before full execution with the following error showing in the Java Console:

Uncaught Error: SES not supported, aborting taming frame initialization.

After much hair pulling and research, I learned that adding the following line to the script will fix the problem:
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
Here are the codes for the two affected functions created by default when the user creates a script using the  Google Sheets Add-on Script template:

function showSidebar() {
 
var ui = HtmlService.createTemplateFromFile('Sidebar')
     
.evaluate()
     
.setTitle(SIDEBAR_TITLE);
 
SpreadsheetApp.getUi().showSidebar(ui);
}

function showDialog() {
  var ui = HtmlService.createTemplateFromFile('Dialog')
      .evaluate()
      .setWidth(400)
      .setHeight(190);
  SpreadsheetApp.getUi().showModalDialog(ui, DIALOG_TITLE);
}


The following are the above functions modified to add SandboxMode:

function showSidebar() {
 
var ui = HtmlService.createTemplateFromFile('Sidebar')
     
.evaluate()
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
     
.setTitle(SIDEBAR_TITLE);
 
SpreadsheetApp.getUi().showSidebar(ui);
}


function showDialog() {
 
var ui = HtmlService.createTemplateFromFile('Dialog')
     
.evaluate()
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
     
.setWidth(400)
     
.setHeight(190);
 
SpreadsheetApp.getUi().showModalDialog(ui, DIALOG_TITLE);
}


Executing the codes as modified work flawlessly.

My reason for posting this is twofold:
1.  Persuade Google to update its templates to correct coding that no longer works, specifically the Google Sheets Add-on Script template in this example, nut there may be others.
2.  Provide help for users experiencing similar issues. Other postings to the google forums relating to the Java Console error are confusing and provides no insight how to fix this particular problem



Mike Stay

unread,
May 26, 2015, 12:18:45 PM5/26/15
to Google Caja Discuss
Perhaps people will see your post and it will help them; I hope so.
As far as solving the problem goes, Caja is tech *used by* Google Apps
Script; we have no control over what they put on their pages.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Google Caja Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-caja-dis...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Mike Stay - meta...@gmail.com
http://www.cs.auckland.ac.nz/~mike
http://reperiendi.wordpress.com
Reply all
Reply to author
Forward
0 new messages