title: Why can't I call a server function from the sidebar in Google AppScript for Sheets?
body: <p>I'm having problems calling a server-side Apps Script function from a html sidebar in Google Sheets.</p>
  <p>I've replicated my issue with the simple example code below.</p>
  <h3>What it should do</h3>
  <p>Clicking the button should call <code>alert</code> in my Code.gs script and display an alert to the user.</p>
  <h3>What actually happens</h3>
  <p>Clicking the button shows the error:</p>
  <pre class="lang-none prettyprint-override"><code>We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED.
  </code></pre>
  <p>There are no entries in the 'executions' section of the Apps Script dashboard for <code>alert()</code>, so it seems like the function never even gets called?</p>
  <h3>Code.gs:</h3>
  <pre class="lang-js prettyprint-override"><code>function onOpen() {
    const ui = SpreadsheetApp.getUi();
    ui.createMenu('Matthew')
      .addItem('Show Sidebar', 'sidebar')
      .addToUi();
  };
  
  function sidebar() {
    const html = HtmlService.createHtmlOutputFromFile('test.html')
      .setTitle('Matthew Experiment')
      .setWidth(300);
  
    SpreadsheetApp.getUi().showSidebar(html);
  
  
  }
  
  function alert() {
    SpreadsheetApp.getUi().alert(&quot;alert!&quot;); 
  }
  
  </code></pre>
  <h3>test.html (well the body)</h3>
  <pre class="lang-html prettyprint-override"><code>  &lt;body&gt;
      &lt;div class=&quot;container&quot;&gt;
         &lt;button class=&quot;btn btn-success&quot; onclick=&quot;doSomething()&quot;&gt;Click Me!&lt;/button&gt;
      &lt;/div&gt;
      &lt;script&gt;
              function doSomething() {
            google.script.run.withFailureHandler(function(error) {
              console.log(&quot;error&quot;)
              console.log(error.message)
            }).withSuccessHandler(function(result) {
              console.log(&quot;done!&quot;)
            }).alert();
          }
      &lt;/script&gt;
    &lt;/body&gt;
  </code></pre>
  <p>I've confirmed that the client-code is getting properly inflated with server-side function names, it's just calling the function that doesn't work.</p>
  <p><a href="https://i.stack.imgur.com/3jZar.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3jZar.png" alt="" /></a></p>
  <p>My code seems to be the same as all of the getting started guides, but I don't see anyone else posting about this issue. Hoping someone here has deeper knowledge of the problem than I do.</p>
  <h3>Update, even weirder</h3>
  <p>I opened a private window and it <strong>worked</strong>, so I thought, maybe this is an extension causing problems? But even disabling all extensions doesn't fix it in the main window. I've logged out/in to my google account but still can't get it to work without opening a private browser window.</p>
  <p>This problem is consistent across chrome/edge/firefox.</p>