Google Script App Fails in Incognito Mode - google-apps-script

I have a simple Google Script published as a web app with anonymous access. The code is available here and the web app is available here.
code.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile("index").setTitle("Google Script")
}
index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p>Hello</p>
</body>
</html>
The script web app works in normal Chrome mode but returns a 500 error when the page is viewed in the incognito mode of Chrome or Firefox.
The script fails with a 500 error in both V8 and DEPRECATED_ES5 runtime.
See screenshot.

Yes it is consistently reproducible in a new project.
I have the same problem... It is related to the HtmlService
The app script was workng for about a year, but yesterday started to return the error "Google Docs encountered an error".
return HtmlService.createHtmlOutput("<p>Hello World</p>");
If I login it works, however the script is meant to return dynamic list as html when people visit my website, hence why it is needed to run as "as anyone, even anonymous".
Partial Workaround:
Some of my scripts are API's returning just strings, the workaround for these is to use ContentService instead of HtmlService.
return ContentService.createTextOutput("Hello World");

Thank you for looking into this issue.
It looks like a problem at Google's end and they have acknowledged the bug as well. We'll have to wait until they issue fix.
Update: Looks like Google has rolled out an update and the issue is automatically resolved. The web app is now working as before.

Related

Google Apps Script doGet(e) createHtmlOutput returning broken Google Drive error page on Safari [duplicate]

I have a simple Google Script published as a web app with anonymous access. The code is available here and the web app is available here.
code.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile("index").setTitle("Google Script")
}
index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p>Hello</p>
</body>
</html>
The script web app works in normal Chrome mode but returns a 500 error when the page is viewed in the incognito mode of Chrome or Firefox.
The script fails with a 500 error in both V8 and DEPRECATED_ES5 runtime.
See screenshot.
Yes it is consistently reproducible in a new project.
I have the same problem... It is related to the HtmlService
The app script was workng for about a year, but yesterday started to return the error "Google Docs encountered an error".
return HtmlService.createHtmlOutput("<p>Hello World</p>");
If I login it works, however the script is meant to return dynamic list as html when people visit my website, hence why it is needed to run as "as anyone, even anonymous".
Partial Workaround:
Some of my scripts are API's returning just strings, the workaround for these is to use ContentService instead of HtmlService.
return ContentService.createTextOutput("Hello World");
Thank you for looking into this issue.
It looks like a problem at Google's end and they have acknowledged the bug as well. We'll have to wait until they issue fix.
Update: Looks like Google has rolled out an update and the issue is automatically resolved. The web app is now working as before.

How to close parent window in an Apps Script Web App?

I have a web app in Google Apps Script and I need that when I have click in a Button, the browser tab closes. I tried with different solutions but it does not work as I require it.
This is my HTML code.
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1>Demo Close tab</h1>
<p>When you click the button, you must close this tab.</p>
<button>Close</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>
window.onload = function() {
$("button").click(function() {
// window.close();
// window.top.close();
// window.open("","_top","").close();
});
}
</script>
</body>
</html>
And this is my GS code
function doGet() {
var template = HtmlService.createTemplateFromFile("Index");
return template.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.addMetaTag("viewport", "width=device-width, initial-scale=1")
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
.setTitle("Demo Google Analytics");
}
As stated in the docs HTML Service: Restrictions:
The setSandboxMode method now has no effect when called.
Your Google Apps Script runs in an iframe by default, regardless of any attempts to change the sandbox mode. I strongly suspect the sandbox settings will prevent you accessing the parent window, but you might try window.parent.window.
According to Javascript Documention: Window.close()
This method is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, an error similar to this one appears in the console: Scripts may not close windows that were not opened by script.
Web Apps are usually standalone script projects that, as per the documentation on restrictions applied in the IFRAME sandbox mode (which is, as of 2021, the only mode available), has the following sandbox flags (corresponding to the sandbox attribute) set on the HTMLIFrameElement Web Apps are served in:
Flag
allow-same-origin
allow-forms
allow-scripts
allow-popups
allow-downloads
allow-modals
allow-popups-to-escape-sandbox
allow-top-navigation-by-user-activation
Note the last flag - this is the reason for being able to initiate navigation when a user clicks on an element but not when calling methods like window.top.close(), window.location.reload(), or window.location.replace(<url>).
This seemed to not be strictly enforced for bound script projects up until September 2021, but it is now. As of now, there are several open issues on the Issue Tracker reporting that the auto-closing Web App windows stopped working - please follow them if you want to get updates on whether or not Google will reconsider enforcing the flag:
https://issuetracker.google.com/issues/198071205
https://issuetracker.google.com/issues/198323022
https://issuetracker.google.com/issues/198073648 (status "Won't fix" but open for a feature-request)

Google reCAPTCHA V.2 working in firefox but not in chrome

I am using google reCAPTCHA V.2 in my website, which is running on a localhost in a MAMP server.
I am doing all the widget integration correctly (both on frontEnd and server side), the proof is that the widget displays correctly on firefox 38.0.1 and that the validation works smoothly
http://imgur.com/cm83p39
but it displays strangely on chrome
http://imgur.com/KHC7hMN
Needless to say, I am doing everything that needs to be done. Again, the proof is that it is working in firefox, but not in chrome...
Without going into detail, in HTML the page looks something like this:
<!DOCTYPE html>
<html>
<head>
<title>reCAPTCHA demo</title>
<script src='https://www.google.com/recaptcha/api.js?hl=en'></script>
</head
<body>
<form id='reCaptcha' action='myValidationScript.php' method='POST'>
<div class="g-recaptcha" data-sitekey="myKey">
</div>
<input type='submit'>
</form>
</body>
</html>
The problem is not on the server, the code I use in PHP to do the validation looks something like this (again, without going into detail).
<?php
if(isset($formFields['g-recaptcha-response']))
{$captcha=$formFields['g-recaptcha-response'];}
$secretCaptchaKey='mySecretKey';
$response=file_get_contents(
"https://www.google.com/recaptcha/api/siteverify?secret=$secretCaptchaKey&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']
);
$response = json_decode($response, true);
if($response["success"]==true){echo('yay!!')}
else{echo('nay')}
?>
The closest answer I've read in the web is from google's FAQ where they discuss the "no_checkbox" issue saying that my client does not have the necessary resources to load the widget and that it falls back to an alternative challenge. But the example they put there (an image with text) is far from the ugly texts I am getting in chrome...
Again, please understand there is no server problem with this, the proof is that it works on firefox...
For information, I had the exact same issue in the past and I solved it by upgrading the browser. Now I have it again in chrome...
any ideas?
I had a similar issue here: reCAPTCHA working flawless in Firefox (51.0.1) and displaying the message "invalid domain for site key" in Chromium (55.0.2883.87).
A workaround was to disable the "Verify the origin of reCAPTCHA solutions" checkbox in the reCAPTCHA configuration for my domain which made reCAPTCHA work in Chrome.
Of course, this is not a sustainable solution. Upon further investigation I found out the problem was caused by the German "Umlaut" characters in my domain name. To solve it, I just needed to add the Punycode of my domain to the reCAPTCHA config.

Unable to enable Chrome app in iframe

I'm trying to load the native messaging example app in an external webpage as follows:
test.html
<html>
<head>
</head>
<body>
<iframe src="chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/main.html"</iframe>
</body>
</html>
I have added the web_accessible_resources property in the app's manifest:
manifest.json
{
// <some code snipped>
"web_accessible_resources": ["main.html"]
}
However, when I use the app within test.html, I get the following error in the console, coming from a JavaScript file within the app:
Developer Console
Uncaught TypeError: Object # has no method 'connectNative'
main.js:51
The problematic line of code is the following:
main.js
port = chrome.runtime.connectNative(hostName);
Here's a screenshot - the problem happens when I click on the Connect button (which calls the connect function):
Obviously, this works when the app is run standalone. How can I go about loading the app in a webpage?
You can't. With very few exceptions, Chrome avoids proprietary extensions to the open web. You're asking for exactly that: an external web page that has nonstandard abilities simply because it's opened in Chrome rather than another browser. As the web is today, that kind of behavior would lead to a poor developer and user experience. The native-messaging documentation suggests that the functionality you want is available to Chrome extensions and Chrome apps. And as you're finding out, that's indeed the case: it works as an app, but not as a web-standard iframe. This is by design.
You probably want to write a Chrome extension. Your webpage should detect whether the Chrome extension is installed and whether the user's browser is Chrome. If it's not Chrome, it should give an appropriate error message. If it is Chrome but the extension is not installed, it should urge the user to install your extension.

Google Apps Script Html Service and Internet Explorer error "This content cannot be displayed in a frame"

I am finally getting my Google script to work. It works fine in Chrome. I am using htmlservice.createHtmlOutputFromFile and the site is obviously hosted on google sites.
But when I try the page in IE, I get
This content cannot be displayed in a frame
To help protect the security of information you enter into this website, the publisher of this content does not allow it to be displayed in a frame.
I tried adding in head tag
meta http-equiv="X-Frame-Options" content="allow"
but it made no difference.
Is there a javascript trick or a GAS library function I can use to try to get this to work cross browser?
Maybe your problem is related to cross domain cookies.
Check this answer maybe will work to you.