How to properly debug WebApps deployed in google scripts? - google-apps-script

I have some experience debugging with google app scripts, but I have encountered myself with this problem since I deployed my first WebApp and haven't been able to find a way to solve it.
The webapp can be accessed by anyone who has the link in order to fill a tiny form, and the information is saved on a google sheets file. The thing is, that after the form is filled out it should redirect you to "Page 1" or "Page 2" depending on one of the answers. The main problem is that when the user is redirected to "Page 1" there is no problem, but when the redirection is supposed to be made to "page 2" takes a lot of time and sometimes it just does not do it.
The thing is when I test the page as a common user with my google account logged in (the owner's account of the deployment) , I am able to see details about the errors on the app scripts panel, but when any other user enters the webApp I am not able to see further details about the errors on the app scripts panel. I have some code lines such as:
console.log('Entered 1st step successfully');
to keep track of my process, these logs are indeed registered when I use the WebApp with my google account logged in, but they are not made when the webApp is accessed by any other user, and there are some errors that I just haven´t been able to reproduce, thus corrected them.
Does anyone know how could I properly get the errors information when the users use the WebApp?
I attach an image of the google apps scripts panel which I am referring to.
App scripts panel view

Instead of console.log (which executed on the browser and routes the output to the user running the app), use the Logger class so they show up on the Execution Transcripts on the Google platform.
Hope this helps!

Related

How to troubleshoot Google login appearing when using Anonymous Web App

I am new to apps-scripts and want anonymous users to access my web app script that is container bound to a spreadsheet.
The web app displays a form that collects information that the script stores in the containing spreadsheet, it works perfectly when I am logged into my google account, but when logged out the web app url displays a google login screen instead of my form.
I am struggling for the way to troubleshoot this. I have checked:
the script is deployed to execute as 'me' and with access by anyone + anonymous
I am using the 'exec' url
I have put the oauth scopes into the manifest and reduced scope as I can
I have approved the unverified app.
Here are some extra elements that I don't know whether they are causing issues or not:
I add a single query parameter to the web app exec url before sending it to the user for them to use anonymously.
I have a number of other functions in the script apart from the doget(), these process data from the web app form, write data to the containing spreadsheet and return some of it to the user. In the same script I also add a menu to the containing spreadsheet.
There seem very few ways to get logging or troubleshooting information for this problem - especially with container bound scripts. Can anyone with more experience please explain why this problem might occur and suggest how I can troubleshoot and resolve it? As I say the web app url works perfectly when I'm logged in, but when I'm logged out or in incognito mode I get a Google account sign in form. Thank you.
I solved this whilst creating a minimal reproducible example as requested.
The problem lay in my confusion over deployments, /exec, /dev and V8 versus rhino.
This answer about /dev /exec is very helpful.
What I discovered is:
/dev always asks you to login to your google account if you're not logged in in your browser e.g. incognito mode.
As commented there has been some confusion under what circumstances V8 getUrl() returns /dev or /exec.
My suggestions for troubleshooting this for an anonymous web app:
Be very careful when testing anonymous web app using /dev - it will always lead to login request
Check very carefully what getURL() is returning - in combination with whether you are using rhino or V8.
I solved my particular problem by 'downgrading' to rhino by putting into the manifest: "runtimeVersion": "DEPRECATED_ES5"

Google Script ~ How to automate authorization for app?

I've made an app in Google Apps Script to use in an iframe on my site. Problem is I have to go through a bunch of steps every time someone new wants to use the app.
My goal:
What I would like to do is automate the app so it just approves anyone who authorizes it when they're initially prompted. Given that the users initial confirmation is the important part, I don't see why it would be a problem to just have the app allow them in, without them having to wait for me to confirm their confirmation.
The Breakdown:
The permissions settings for the app are as follows:
"Execute the app as:" = "User accessing the web app"
"Who has access to the app:" = "Anyone"
The user must obviously have a Google account to use this app, and they have to authorize the app before they can use it. When they do, an email gets sent to me, I have to find it, open it, and click the "Open sharing settings" link which opens the apps script file, then click "send" on the popup just to allow that one person to use the app.
Many people will be requesting authorization, and I don't want to have to check my gmail every day and manually confirm 5 or 10 new authorizations. That's way too much for me, and too much of a pain for the people using it. Despite having put almost a year into coding this thing, I'd rather not deploy it than bother with that. Yea, I definitely should've scoped this out better before coding the bulk of it.
Potential Solution:
This is a relatively naive guess, but would it work for me to make a second app that runs on a schedule, and opens the initial app's script file in an iframe, using sandbox="allow-same-origin allow-popus" attribute, then maybe use javascript to toggle "send" on the "share with others" pop-up?

Google Drive Page Not Found - Sorry, unable to open the file at this time

I'm using google scripts to deploy a web app. I've done about 5-10 in the same account. When I try and run the web app/script, I'm now getting: a "Google Drive: Page not found" in the title and the message
Sorry, unable to open the file at this time. Please check the address and try again.
I published it to run as the owner, but accessible to "Anyone, even anonymous".
I then tried creating a new small project with a doGet() method that returns a small static web page, with the same result.
Code.gs:
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('Test');
}
Test.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
This is a test
</body>
</html>
I tried publishing the same spreadsheet/code above in my personal account and it works fine. Since I already have some web apps deployed with the account that's having the error, is there a quota on the number of web apps per account?
I tried a different browser, a different account, re-publishing, and logging out and back in. Same error message. The "Test your web app with the latest code" link also fails. I can directly call the doGet() method in the IDE and it works fine, and I see output in the logs.
I don't see anything in the logs for the page not found error, which is what I expect with the page not found - not even getting to code execution, thus no logs.
I think you are logged in with two gmail account: That is why (/u/1,/u/0) may have been appended to script address (may be a bug).
So what you have to do is remove /u/0 or whatever is appended.
ForExample:
https://script.google.com/macros/u/1/s/ffffsdds/exec becomes https://script.google.com/macros/s/ffffsdds/exec
I have several Gmail accounts open at once and kept having this problem. I found it helped to close the Drive window, log out of the email account related to it, and then log back into the Gmail account and open Drive again.
You need to add your organization domain to the URL, as in https://script.google.com/a/yourdomain.com/macros/s/ffffsdds/exec - note that a/domain.com has been added. If you're not using a custom domain, use a/gmail.com.
It works when you are logged in to multiple accounts and redirects to
https://script.google.com/macros/s/ffffsdds/exec when you are not logged-in to the particular domain account.
Background info:
https://script.google.com/macros/u/1/s/ffffsdds/exec - does not work if you are logged-in with multiple accounts
In https://script.google.com/macros/s/ffffsdds/exec - "/u/x" has been removed but if you visit that URL, it will still redirect to https://script.google.com/macros/u/1/s/ffffsdds/exec and (1) problem remains when you are logged into multiple accounts (however it works if you are not).
It looks like it's related to this issue: https://issuetracker.google.com/issues/69270374. Authentication is broken for multiple signed-in accounts.
As Google developers suggests, you should:
Signing out of all accounts and using only 1 account: or
Using an incognito tab to sign in
source (comment 292).
What is sad is that, as they said:
The issue originally reported is due to recent improvements in Sheets' ability to handle multiple logged in accounts.
source (comment 11)
So by improving multiple logged in accounts, they also broke it.
Now the "good" news: we can expect this to be fixed in about 1 year I would say.
Our team plans to begin to work on multi-login support for the new Apps Script IDE and container-bound scripts in Q3 ‘21.
source (comment 292)
All the above answers are relevant. But for me, the issue was due to lack of space in Google account. I've used all 15GB space provided by Google and then all my Google Forms started showing the above error.
Solutions are:
Buy extra space from Google, it wont cost much. For 100GB, it costs Rs.130/month or Rs.1300/year
Free up your space. Go through the Google Drive and you may find a lot of unwanted files. Delete it and make some free spaces.

Launching the Google Drive sharing dialog in an app. What should be the APP_ID value?

I'm following this article, trying to add a sharing dialog in a web app.
I got the button working in opening the modal popup, but it just prints this error in the console:
Refused to display 'https://drive.google.com/share?id=SOME_LONG_ID&foreignService=explorer&shareService=explorer&shareProtocolVersion=2&command=init&subapp=10&popupWindowsEnabled=true&shareUiType=default&rand=1386925457304&theme=2&client=postMessage&appId=MY_APP_ID&embedOrigin=http%3A%2F%2Fmy_app.appspot.com'
in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
And the modal itself just shows the message "Sorry, sharing is unavailable at this time. Please try again later."
For the checklist at the bottom of the article:
The user is signed in to Google True
The user has installed your app False How do I ask them to install?
The URL of the page that launches the dialog must have the same origin as the Open URL registered for the app. True
So I have 2 questions:
How do I ask them to install my app? It's supposed to be a web app, where there's 1 button to select Drive files via the Picker API (which is now working), and then another button which will sow this Drive sharing dialog to set the permissions of the selected files. There's no need for installation. Will it work for this setup?
What should be the value for the APP_ID? I'm guessing it's the ID in the "Drive SDK" section of the Cloud Console? The console is so confusing and there's so many values for keys, ids, etc. that I have no idea which to use. Here's a screenshot of what I mean by the ID and what I'm trying to use.
(1) Installing means you have to get the user to accept the drive.install scope - instructions here. This will integrate your app with the "open with" menu in Google Drive. But before that can work you will need to tell the Google Cloud Console what url to go to when the user clicks "open" - more instructions. In your case, since you don't actually want to allow the user to open files from Drive you won't be defining any file types, so in reality there won't actually be any visible integration with Drive.
Note that the share dialog will only work on the one page which has the url you specify as the target for "open" (the instructions say this and from experience it seems to be true).
(2) Client ID You can find this in the Google Cloud Console - see above. Mine is a 12 digit number, so yours will probably be too.
I had the same problem. The iFrame error shows up when you call setItemIds if your app_id is wrong. No idea why. Anyway, it started working for me when I used the right app_id -- the one that shows up like in your screenshot.

GAS: This application was created by another user, not by Google

I have made a script that is running as a 'Apps Script Gadget' in Google Sites. The script has access to my email and calender etc. because I need notifications if someone has used my script.
When I go to the site as "noname" user I get the message "This application was created by another user, not by Google. This application has access to the following personal information: email address." How do I get rid of this, the user is not interested if the script sends me a email or not.
Thank you for any advises.
Same thing happened to me; I commented out all references to the Session object but I still got the popup message.
When I removed the commented code entirely and re-published, everything worked fine. The message about access to the email info was gone.
I guess the google code holds onto an internal library reference even if there is commented code. Does not make much sense to me. But hope this helps.
If your script is not reliant on any of the users' information, I would suggest when deploying the web app to "Execute the app as" me. In the Publish > Deploy As Web App... pop-up, there's a dropdown for this.