0

I have an apps script web-app with, in code.gs, this:

function doGet() {
 return HtmlService.createTemplateFromFile('index').evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
  
}

function getEmail() {
  return(Session.getActiveUser().getEmail());
}

This code creates an html output and lets in be embedded as well as making a function to get the email. This is index.html:

<!DOCTYPE html>
<html>
  <body>
<script>
 var email;
  function onSuccess(emailParam) {
email = emailParam;
alert(email);
}
google.script.run.withSuccessHandler(onSuccess).getEmail();
</script></body>
<button onclick = "google.script.run.withSuccessHandler(onSuccess).getEmail();">Get Email</button>
</html>

It instantly alerts your email and has a button that will alert your email. However, I want to run JavaScript that invokes the function and alerts your email in the page with something like a bookmarklet. In theory I could do this: javascript:google.script.run.withSuccessHandler(onSuccess).getEmail();, but it doesn't work.

EDIT:

Note: This is specific to apps script. Apps script blocks requests like this; I am wondering if there is a workaround.

henxdl
  • 118
  • 14
  • Apps script changes your initial code and puts it in another iframe, while obfuscating it, so I'm wondering if you can still execute your existing function client-side and how. – henxdl Nov 04 '22 at 01:03

0 Answers0