0

I am a 'Chrome for Business and Education' admin for a group of chromebooks which I have configured to run in Single App Kiosk mode. The kiosk app in question is really simple. All I did was take the example code from this link (https://support.google.com/chrome/a/answer/3316168?hl=en#kiosk) that uses the 'webview tag' (without controls, as we need all the whole screen for the app in question from google form) and change the URL. The app has installed perfectly in all managed devices, Google form open up in my kiosk app, the users can fill in the form and submit it.

The problem now is I need to pass a value (it could be single character or number) back to my Kiosk app after form submit. I don't know how to pass value from Form's app script back to my created kiosk app, do anyone know how to make it work, thanks.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • Welcome to StackOverFlow please take this opportunity to take the [tour] and learn how to [ask], [format code](https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks), [mcve] and [Tag Info](https://stackoverflow.com/tags/google-apps-script/info) !!!! No Posted No Help – Cooper Dec 23 '20 at 19:05
  • You can't run apps script in Google form live/client side. Google form apps script is only for editing the form or backend modifications. – TheMaster Dec 23 '20 at 19:35

1 Answers1

0

You can

  • deploy your Apps Script project as a WebApp
  • return your value form the WebApp with
return contentService.createTextOutput(JSON.stringify({"myVar": "myValue"})).setMimeType(ContentService.MimeType.JAVASCRIPT);
  • Within your Chrome extension, perform an XMLHttp or fetch request to the WebApp URL

Sample code snippet to implement in your Chrome extension:

XMLCall(webAppUrl, callback);

function XMLCall(webAppUrl, callback) {
  const request = new XMLHttpRequest();
  request.onreadystatechange = function() {
     callback(request.response);
  }
  request.open("GET", webAppUrl, false);
  request.send('');
}
function callback(response) {
  var myValue = JSON.parse(response).myVar; 
}
ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • Thanks, I'm not familiar on client/server coding, can give me more hint, and prompt me more, where can I place the value return in App script, and where should I perform XML http or fetch request to webApp URL in Chrome extension. – Kelvin Yung Dec 28 '20 at 02:58
  • The value return will be at the end of your code. You did not show the code you have so far, but once you have the var you are intereste in, just return it with the line above. In you Chrome extension - incorporate the fetch request at the position where you need to use the var. – ziganotschka Dec 28 '20 at 08:06
  • Happy New Year, ziganotschka Below is an app script function in my test Google Form, I add the Trigger, when user click on the submit button in Google Form, will call this function, do you mean to place return value at the end of my function? var noKiosk=0; function onSubmit() { form = FormApp.getActiveForm(); formResponses = form.getResponses(); // do some job.. return contentService.createTextOutput(JSON.stringify({"myVar": noKiosk})).setMimeType(ContentService.MimeType.JAVASCRIPT); } How can I catch the return value in my Chrome extension? Thanks, appreciate. – Kelvin Yung Jan 04 '21 at 19:58
  • Once you deploy the WebApp, make e.g. an XML call to its deployment URL - as specified in my sample. Simply replace the placeholder `webAppUrl` through your real URL. – ziganotschka Jan 05 '21 at 10:12
  • Hi ziganotschka, I follow your instruction, publish to WebApp, then place XML call with my webAppUrl in chrome.app.runtime.onLaunched.addListener, and chrome.app.runtime.onRestarted.addListener under my custom coding extension, but not able get a value, can give more advice, below is example: chrome.app.runtime.onRestarted.addListener(function() { runApp(); XMLCall("https://script.google.com/macros/s/AKfycbxbm18gZQyAIlA6nheR2YcAnicwgI4Vxk59eYZU3u0EpmvhtWdQ/exec", callback); }); Thank You! – Kelvin Yung Jan 06 '21 at 15:10
  • Hi ziganotschka, I give you more info, purpose of my coding google extension. when my extension app run, will launch my google form, user fill up, then submit the form, after user submit the form, my extension app will close. Now I already able launch up, and close my extension app by specific shortcut key, but I need pass a value from submit form to my extension, let my extension read the value to decide what condition should close up the extension app instead using manually way, because don't want user can have control of closing app. Thanks so much your help, appreciate. – Kelvin Yung Jan 06 '21 at 15:25
  • I recently showed someone how to do it (also I am not sure if he got me) - see [here](https://stackoverflow.com/questions/65428733/pass-a-value-from-google-app-script-to-my-chrome-extension/65437912#65437912). – ziganotschka Jan 06 '21 at 16:15
  • Hi ziganotschka, I place the XML call under chrome.app.runtime.onRestarted.addListener and chrome.app.runtime.onLaunched.addListener handler in my background_main.js file in my coding google extension, but I still don't get a return value from my google form, do I call XML in wrong place or should someplace else in my Google extension, can you give me more hint and advice, thanks. – Kelvin Yung Jan 07 '21 at 17:28
  • Don't you get any response at all or do you get an empty value? – ziganotschka Jan 07 '21 at 19:36
  • Hi ziganotschka, I don't get response at all, so I doubt where in my background script file should call XMLCall function for getting return value from my google form after google form submit. I already test my Webapp URL, I can get value {"myVar":"1"}, can you tell me more how can I make an XMLCall in Chrome Extension background scrip file, thanks very much. – Kelvin Yung Jan 20 '21 at 00:45
  • You should implement the call when the user hits the submit button to send off the form. In your WebApp you could retrieve the values e.g. from the entries in the form response destination spreadsheet. Also, you can try to retrieve the responses by inspecting the related input elements, see [here](https://stackoverflow.com/questions/65142364/i-cant-find-name-attribute-while-inspecting-input-elements-of-google-form-ho/65143141#65143141). – ziganotschka Jan 20 '21 at 06:52