title: Server side object lost when passed to client side code
body: <p>This is not the same than <a href="https://stackoverflow.com/q/49910268/1595451">Object property values lost on server side when object passed via google.script.run</a></p>
  
  <p>I'm trying to set my Google Apps Script add-on test framework. Since Test as add-on can't be used to test installable triggers, I'm wondering if I could pull server side code from a bounded project to be use as a library to test my sidebars that call server-side functions. </p>
  
  <p>If I run the below code using Run > Test as add-on... it shows my menu two times</p>
  
  <ol>
  <li>As a custom menu named "Sidebar", next to the Help menu</li>
  <li>As an add-on menu, on Add-ons > My Project</li>
  </ol>
  
  
  
  <ul>
  <li>When I click on Sidebar > Open, clicking on the sidebar buttons <code>getMail()</code> returns <code>undefined</code></li>
  <li>When I click on Add-on > My Project > Open, clicking on the sidebar buttons <code>getMail()</code>, as expected, returns the active user email address.</li>
  </ul>
  
  <p>The same happens, server side object lost, when I replace the <code>getMail()</code> function by another that use the Spreadsheet Service to return a cell value or even by one that return a primitive string.</p>
  
  <p>What am I missing?</p>
  
  <p>The bottom line is that I want to add a button on my sidebar that creates an installable trigger and get some values from the spreadsheet.</p>
  
  <h1>Spreadsheet to be used as library</h1>
  
  <h2>Code.gs</h2>
  
  <pre class="lang-js prettyprint-override"><code>function onOpen(e) {
    var ui = SpreadsheetApp.getUi();
    var menu = ui.createMenu('Sidebar');
    menu
      .addItem('Open', 'showSidebar')
      .addToUi();
  }
  
  function showSidebar() {
    var ui = HtmlService.createHtmlOutputFromFile('Sidebar')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setTitle('A Sidebar');
    SpreadsheetApp.getUi().showSidebar(ui);
  
  }
  
  function getEmail() {
    return Session.getActiveUser().getEmail();
  }
  </code></pre>
  
  <h2>Sidebar.html</h2>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
    &lt;base target="_top"&gt;
    &lt;script&gt;
      function updateButton(email, button) {
        console.log(email);
        button.value = 'Clicked by ' + email;
      }
    &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;input type="button" value="Not Clicked" onclick="google.script.run
            .withSuccessHandler(updateButton)
            .withUserObject(this)
            .getEmail()" /&gt;
    &lt;input type="button" value="Not Clicked" onclick="google.script.run
            .withSuccessHandler(updateButton)
            .withUserObject(this)
            .getEmail()" /&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  
  
  <h1>Examples of other functions used to replace getMail()</h1>
  
  <pre class="lang-js prettyprint-override"><code>function getCellValue(){
    return SpreadsheetApp.getActiveCell().getValue();
  }
  
  function getGreeting(){
    return 'Hello world';
  }
  </code></pre>
  
  <h1>Spreadsheet to be used as library client</h1>
  
  <ol>
  <li>Add the Library to the project</li>
  <li><p>Add the below code</p>
  
  <p>function onOpen(e) {
    aLib.onOpen(e);
  }</p>
  
  <p>function showSidebar(){
    aLib.showSidebar();
  }</p>
  
  <p>function getEmail(){
    aLib.getEmail();
  }</p></li>
  </ol>
  
  <h1>Test as add-on...</h1>
  
  <ol>
  <li>Click on Run > Test as add-on</li>
  <li>Add "Spreadsheet to be used as library client " as doc to be used to test as add-on</li>
  <li>Launch the doc</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/SguXm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SguXm.png" alt=""></a></p>