Google 网络应用 google.script.run 不工作

Google Web App google.script.run not working

我有以下 .gs:

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('index')
}

function goToMaster() {
  const ss = SpreadsheetApp.getActiveSpreadsheet()
  const sheet = ss.getSheetByName('Master Projects')
  sheet.activate()
}

goToMaster() 函数激活一个名为“Master Projects”的 sheet

当运行函数本身时,它可以正常工作。但是,我创建了一个 index.html ui 来通过单击 div:

来触发此功能
<!DOCTYPE html>
<html>

<head>
  <base target="_top">
  <link rel="icon" href="/images/favicon.svg" />
  <script src="https://kit.fontawesome.com/abd2f5db30.js" crossorigin="anonymous"></script>
</head>

<body>
<div class="card card--1" id="master-projects">
      <div class="container">
        <h2>Master Projects</h2>
        <i class="fa-solid fa-diagram-project"></i>
      </div>
<script>
    const masterProjects = document.getElementById('master-projects');
    masterProjects.addEventListener('click', doStuff);

  function doStuff() {
    google.script.run.goToMaster();
  }    

  </script>
</body>  

 </html>

单击 div 时,没有任何反应!我到处寻找解决方案,但到目前为止没有任何效果。

知道是什么原因造成的吗?

像这样尝试

html:

<!DOCTYPE html>
<html>

<head>
  <base target="_top">
  <link rel="icon" href="/images/favicon.svg" />
  <script src="https://kit.fontawesome.com/abd2f5db30.js" crossorigin="anonymous"></script>
</head>

<body>
<div class="card card--1">
      <div class="container">
        <h2>Master Projects</h2>
        <i class="fa-solid fa-diagram-project"  id="master-projects"></i>
      </div>
<script>
  window.onload = function() {
    const masterProjects = document.getElementById('master-projects');
    masterProjects.addEventListener('click', doStuff);
  }
  
  function doStuff() {
    google.script.run.goToMaster();
  }    
  </script>
</body>  

 </html>

gs:

function goToMaster() {
  const ss = SpreadsheetApp.getActiveSpreadsheet()
  const sheet = ss.getSheetByName('Master Sheet')
  sheet.activate()
}

function launchadialog() {
  const ui =  SpreadsheetApp.getUi();
  ui.showModelessDialog(HtmlService.createHtmlOutputFromFile("ah2"),"Title")
  
}