class ui.showModalDialog throws LocalStorage Security exception when ‘Block Third-Party cookies’ is enabled in chrome browser.

149 views
Skip to first unread message

rajatha k

unread,
Feb 26, 2021, 9:38:27 AM2/26/21
to Google Apps Script Community
Currently in our application (Both Google editor add-on and Google Workspace add-on), we are using showModalDialog to load a different URL in an iFrame. LinkHere is the code snippet for the same:
var html = HtmlService.createHtmlOutputFromFile(‘top’).setWidth(700)
                 .setHeight(620).setSandboxMode(HtmlService.SandboxMode.IFRAME)
                 .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
  DocumentApp.getUi().showModalDialog(html, “My Page”);
‘Top’ is a html page with iframe which hosts the URL. This modal dialog appears properly when user click on a button in HTML page / card interface page hosted on the sidebar of the add-on.  This works fine when ‘Allow all cookies’ is enabled.The exception occurs only when user set ‘Block Third-Party cookies’ in chrome browser cookie settings.  After disabling Third-Party cookies, when user click on button in the sidebar, dialog appears and it couldn’t render the page and throws security exception.I see the below local storage security exception in console logs of the browser.

Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

How do i fix this issue? Is there anyway to set cookie via storage API from google apps script?

Clark Lind

unread,
Feb 28, 2021, 8:14:27 AM2/28/21
to Google Apps Script Community
 Apps script doesn't allow real interaction with the browser, so you can use the cache service instead.

rajatha k

unread,
Mar 3, 2021, 2:19:41 AM3/3/21
to Google Apps Script Community
   We are trying to show our existing implementation of a file picker to maintain uniformity across the applications. We are using iframe to show the file picker as a dialog. The way the communication between the iframe and the google App script is via Post Message.
So How to use cache services to set the cookies in this case?
Reply all
Reply to author
Forward
0 new messages