5

I have a Google docs add-on which is programmed to open the sidebar as soon as the document is open. Of course this requires the add-on to be installed and enabled in the document.

I see that, since a week, the sidebar auto open feature, which is very useful in our use case, no longer works.

In StackDriver logs I see this report :

onOpen():  {authMode=LIMITED, source=Document, user=} 
publi-2.0.72-2017-11-27-18-57               [this is the publication version tag]
2017-11-27T18:02:50.126Z : show menu 
2017-11-27T18:02:50.180Z : show sidebar 
Error showing sidebar  Exception: You do not have permission to call showSidebar 
2017-11-27T18:02:50.283Z : end onOpen 

So clearly, the add-on is in LIMITED mode and showSidebar() should succeed, according to the addon authorization lifecyle (just look at the column LIMITED in the table).

--> I suspect a bug or a new security limitation was introduced recently.

For the record here is a code snippet :

/**
 * Basic setup. At the beginning:
 * 1. Add a "Add-ons" menu item.
 * 2. Display the doxMaster sidebar.
 */
function onOpen(e) {
    console.log("onOpen(): ",e)
    console.log(addonversion);
    doServerLog("show menu");
    showMenu();
    doServerLog("show sidebar");
    showSidebar();
    doServerLog("end onOpen");
}

/**
 * Creates the Add-ons menu at the google drive panel.
 */
function showMenu() {
    DocumentApp.getUi().createAddonMenu()
        .addItem(translate("sidebarMenu"), showSidebar.name)
        .addItem(translate("joinFollowingParagraph"), insertJoinFollowingParaSymbol.name)
        .addItem(translate("importDocument"), importDocument.name)
        .addItem(translate("about"), about.name)
        .addToUi();

}

/**
 * Creates a doxMaster Add-on Sidebar.
 */
function showSidebar() {
    try {
        var htmlTemplate = HtmlService.createTemplateFromFile('sidebar');
        var html = htmlTemplate.evaluate().setTitle(translate("appTitle"));
        DocumentApp.getUi().showSidebar(html);
    }
    catch (e) {
        console.log("Error showing sidebar ", e); // Add-on has not been enabled in this document
    }
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
Yves
  • 159
  • 7
  • @SandyGood Any Updates on this? Because, if you try to use some of third party templates from Google Docs Template Gallery (e.g. Pandadoc Templates in Sales category), this add-ons can start automatically. – aaryan Jun 15 '18 at 12:45
  • @aaryan See [my answer](https://stackoverflow.com/a/57503369/1595451) – Rubén Aug 23 '20 at 16:56

3 Answers3

1

Yesterday we've noticed exactly the same problem as you Yves. However for us it occurs in a Google Sheets addon.

I've created an issue at Google: https://issuetracker.google.com/issues/69824548

Please star and comment so it gets picked up soon!

  • After some more test I see that even an add-on in which the sidebar.html file is reduced to a mere

    Hello World

    requests the new privilege "Display and run Third-party web content in prompts and sidebars inside Google Applications". -> This is weird because there is no such content in the add-on.
    – Yves Nov 28 '17 at 14:39
  • The referred issue was merged with https://issuetracker.google.com/issues/69238694 which is marked as "Won't Fix" – Rubén Aug 23 '20 at 16:52
0

I retested, and I see that :

  • on installing the Add-On, mode is set to FULL
  • then opening a document mode is set to None
  • on opening the add-on then, closing the document then reopens, mode is LIMITED.

That is consistent with the expected lifecycle, except that :

  • createTemplate fails under LIMITED mode
  • in LIMITED mode the event has {user=} with no value :

08:22:36.457 onOpen(): {authMode=LIMITED, source=Document, user=}

I think the user permissions are somewhat lost.

Yves
  • 159
  • 7
0

From https://developers.google.com/gsuite/add-ons/concepts/editor-auth-lifecycle

Note: Add-ons can't open sidebars or dialogs while executing in AuthMode.LIMITED. You can use menu items to open sidebars and dialogs since these run in AuthMode.FULL.

From Error "You do not have permission to call showSidebar" in onOpen and onEdit (an issue from the Google Apps Script issue tracker)

Status: Won't Fix (Intended Behavior) Sorry for the delayed reply here. After many conversations with the engineering team it was decided that we cannot support opening UI elements (sidebars, dialogs) in onOpen and onEdit. The authorization lifecycle documentation has been updated to make it clear that you can only add menu items in those modes:

https://developers.google.com/gsuite/add-ons/concepts/addon-authorization#authorization_modes

We understand this impacts the possible user experiences you can provide and we apologize for the suddenness of the change.

Rubén
  • 34,714
  • 9
  • 70
  • 166