Apps Script won't get any logs from HTML page

Viewed 164

I am trying to run a function from Google Apps Script in a HTML page. Basically, I want to get a log message that says "Someone Clicked the Button" whenever the button is clicked. However, I click the button and still get nothing in my logs. I wonder what I'm doing wrong. Here's my code:

function doGet(){
  return HtmlService.createHtmlOutputFromFile("page");
}

function userClicked(){
  Logger.log("Someone Clicked the Button");
}
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
  
    <h1>Hello</h1>
    
    <button id="btn">Run It</button>
    
    <script>
    
    document.getElementById("btn").addEventListener("click",doStuff);
    
    function doStuff(){
      google.script.run.userClicked();
    }
    
    </script>
  </body>
</html>

Any help will be appreciated!

2 Answers
  1. If you are using the new editor you can create a new deployment and then copy the url and go to another window paste and run it and you should see your button.
  2. Then if you project is not a Cloud Platform Project, goto Project Setting and uncheck this item Log uncaught exceptions to Cloud logs
  3. Now go to Executions and then move to the tab with your web app and click it and move back to the executions page and in a short time you should see a userClicked entree and if you open it, in the logs in the bottom of the screen.

Hopefully this will work the same for you.

How about this?

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
  
    <h1>Hello</h1>
    
    <button id="btn" onclick="google.script.run.userClicked()">Run It</button>
    
  </body>
</html>
Related