6

I want to create a gmail add-on. I've already created the quick start application:

https://developers.google.com/gmail/add-ons/guides/quickstart

So, trigger function for that example is :

    function buildAddOn(e) {
  // Activate temporary Gmail add-on scopes.
  var accessToken = e.messageMetadata.accessToken;
  GmailApp.setCurrentMessageAccessToken(accessToken);

  var messageId = e.messageMetadata.messageId;
  var senderData = extractSenderData(messageId);
  var cards = [];

  // Build a card for each recent thread from this email's sender.
  if (senderData.recents.length > 0) {
    senderData.recents.forEach(function(threadData) {
      cards.push(buildRecentThreadCard(senderData.email, threadData));
    });
  } else {
    // Present a blank card if there are no recent threads from
    // this sender.
    cards.push(CardService.newCardBuilder()
      .setHeader(CardService.newCardHeader()
        .setTitle('No recent threads from this sender')).build());
  }
  return cards;
}

In apps script editor, you can debug this function, but, since we are not in gmail, we can not get the "e" parameter, so actually you can not debug it with the real data.

I have deployed that example as a developer add-on and I can use it in my gmail account. I tried to find the function somewhere in the code, I put debugger; or console.log() but I was not able to debug in browser.

So, how can I debug gmail add-on script with real gmail data ?

Rubén
  • 34,714
  • 9
  • 70
  • 166
esayli
  • 61
  • 4
  • hi there did you get an answer to this? For some reason I cannot see the add on when I open an email in gmail – BenKoshy Jul 10 '18 at 15:41
  • I'm having the same issue; I suspect that since the plugin is not running in the script editor, you can't really use the Logger service. I think stackdriver might be an option (though that adds a level of complexity to an otherwise simple framework), or otherwise just adding it as a UI element while in development (effectively going back to debugging with print statements :( – askvictor Feb 11 '19 at 09:55

2 Answers2

2

Gmail addons can't run client-side code so the browser console will not be very helpful but we could use Logger to log messages to Script Editor or to use console to log messages to Stackdriver.

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

I'd suggest using the built in Logger: https://developers.google.com/apps-script/reference/base/logger.

You can view logs each time your add on runs.

Justin Bailey
  • 1,487
  • 11
  • 15
  • Thank you for your answer. I am using logger for debugging, but the question was how can I use my script like it is running in gmail. Let me explain more clearly, Currently, in app script, under "run" tab, there is "test as add-on" feature. When you use that you can run your add-on with any document, and you can do real testing on the real document. I was asking is there a way to do something like that with gmail ? Since I am writing a "gmail add-on" – esayli Nov 10 '17 at 13:05
  • Unfortunately I don't know. I suspect not (for now). – Justin Bailey Nov 17 '17 at 19:10