I have a google app script attached to a spreadsheet. It's deployed as a web app. When accessed, it returns XML.
function doGet()
{
var xml = createXML_(getSheetData_())
Logger.log("\n" + xml);
xml = ContentService.createTextOutput(xml);
xml.setMimeType(ContentService.MimeType.XML);
return xml;
}
I have javascript in a webpage that retrieves the XML from this, with a GET request, using XMLHttpRequest() like normal. It then traverses the XML and builds a table from the data.
In Chrome and Firefox, this all works perfectly. However, in IE11, it doesn't work.
Upon further examination (in IE's inspect thing), the XML being returned to IE is:
<Permission Denied>
and that's it.
How do I make my google app script return the XML when requested by Internet Explorer?
If you mean that Google app script that is deployed as a web app on another domain and your web page is hosted on another domain from where you are trying to retrieve the XML using JS then it can be possible that IE is preventing you from accessing the resources across different domains.
I suggest you try to go to the Internet options-> Security tab-> Select the desired zone-> Custom level then enabled the Access data sources across domains option under the Miscellaneous category.
Restart the machine and again try to check for the issue.
If the issue still persists then I suggest you try to provide detailed steps with the sample code to reproduce the issue and also try to share the snapshot of the error may help to understand the issue in a better way.
Thanks for your understanding.
Related
What would be fastest and most less consuming (CPU, RAM) way to get JavaScript rendered HTML page and save it on drive based on URL with ordinary browser in headless (Google Chrome or Firefox) mode?
Idea is to also have proxy options in browser changed per request as well.
I'm well aware of Selenium, Puppeteer, PhantomJS and similar solutions. This needs to be done with REAL browser, remotely managed through some API on Linux environment.
I've found only JS API implementations for building addons but haven't found any solutions except Remote browser for which I'm not sure weather is updated any more.
Any pointers, snippets or whatever are more than welcome since I can't find anything.
Is it necessary for the JavaScript rendered HTML
Page to be functional after it is saved?
Just take a screenshot using Python and save it on drive.
I've written some code that retrieves some data from google sheets then updates some content on my google sites. However, while the script works (when run on localhost) I encounter the
"details": "Not a valid origin for the client: https://966655698-atari-embeds.googleusercontent.com has not been whitelisted for client ID MY-ID. Please go to https://console.developers.google.com/ and whitelist this origin for your project's client ID."
However, I enabled this for localhost, cleared my caches. The problem is the 'https://966655698-atari-embeds'. Each time the google site loads it generates a new random number sequence. Does anyone know how to workaround this? The google site uses embedded html which I believe is why the initialization failed.
I have tried to white-list https://googleusercontent.com which didn't work (I didn't think it would because the domain changes) but I'm honestly incredibly stumped.
Google hosts all user content using their somedomain.googleusercontent.com. I do not know for certain, but I'm almost sure that to save space they dynamically host their content, meaning that when the embedded html does not need to be actively hosted, it isn't. I had to find a way to host from a site that would always send the request. For me, I found that github pages was the answer.
I found this on adobe's website which somewhat explains what googleusercontent does. https://helpx.adobe.com/analytics/kb/googleusercontentcom-instances.html
To set up github pages this link will explain how to do so https://guides.github.com/features/pages/
You can add this to the developer Google console relatively easily and any connection will submit from your username.github.io. (I believe it also uses https protocol). It also allows me to implement directly using git version control and implements nicely with WebStorm.
My app creates an excel file, server side, from a database extraction.
A post request sends parameters to the server that the server then uses to query the database.
The server uses these parameters to extract data convert the data to an excel file (xlsx), then saves the file with a certain file-name as per the parameters sent to the server.
The server responds to the post request by sending the file-name to the browser.
The browser then creates a link using the filename and other predefined parameters to download the file by the following instructions:
var link = 'http://host-name/path-to-file/excel-file.xlxs'; // the link that is created by the js in the browser
window.location = link; // the file is downloaded
This works in chrome, firefox, opera and safari, in these browsers, the file downloads no problem.
However; when running in Microsoft-edge, the file is not downloaded and this appears in the page.
Someone was facing similar issue in some versions of IE and had to set Cache-Control header to make the download working properly:
response.Cache.SetCacheability(HttpCacheability.Private);
Source
The issue here is that this method of downloading files is not actually downloading the file. I was using javascript to instruct the browser to open the excel file, window.location = link;. Which tells the browser, go to a that link, and open whatever you find at that address. Which is normally an HTML file or something else transpiled into HTML. This can in some cases be also be a .pdf or the sort of file that modern web-browsers are able to interpret and run.
Now, the reason this was mostly working is; browsers like chrome and firefox are smart enough to know that they cannot interpret and display excel files, so instead, they download them. Pretty smart right. However; microsoft-edge is not so clever as its more proven compatriots. It tries to interpret and run the file, which of course it cannot. What this then leads to; is a grand display of nonsense; as you can see from screen-grab in my question above.
My problem here was actually a deeper rooted issue of technology mismatch. I had since migrated to using a more modern stack, replacing my plain node.js server with express. Moving the front-end out of a cross-origin tomcat java-container application-server model (which was causing most of my headaches on a daily bases since I was coding javascript) to a same-origin environment using webpack along with express.
And as you might know, using webpack brings a whole new dimension to the front-end that was not available before when we were using the 'old approach' to web-dev.
Most of the improvements in using webpack came from its ability to bring 'node.js' to the front end.
It has made my life as a dev 150% easier and the type of problem as described in my question above is now a thing of the past. javascript for the win! The moral for me here is that sometimes that aren't any quick fixes, and you just have to do things properly.
I attempted to get my current location and display in google-maps.
for this:
I activated the Javascript API(in google.developers site).
got the key to access the api.
copied the code in the link below to a html file( inserting my key when "calling" the api, of course).
https://developers.google.com/maps/documentation/javascript/examples/map-geolocation
When I ran the html file in the browser, I received an alert giving the error InvalidKeyOrUnauthorizedURL, but it seems that I did everything right, and actually it seems I really did, because when I ran the exact code in the W3Schools tutorials ("Try it your self") the result showed me my location.
So after this context, I would like to know why I can't run this code directly on the browser, I mean, It's kind of OK using the w3schools but it's not the properly way and it's questioning why it's invalid.
observations:
note that the file is not being hosted, it is my own computer.
I tried to run in Opera and Chrome browser- and they both failed.
I ran codes of google maps api successfully directly on the browser but they didn't need any key.
Thanks
It's because you are not hosting it on the local server.
Your browser won't allow location request to go through even if you allow all sites to track your location.
Set up a server on the localhost interface and then try running it. It should work just fine.
PS. Your browser will tell you when any location requests are blocked. In Chrome there will be a small icon on the right hand side of the URL bar after a request for location has been made.
I've ran into Same Origin Policy issues before while doing standard web development. I usually end up writing a vb.net web service as a proxy. However, now that I'm trying to dabble in Windows 8 development using Javascript (due to familiararity) I'm wondering what my options are to avoid the issue.
All I need to do is fetch a remote XML file and display information from it.
You can make a WinJS.xhr call to the xml file directly without problem as long as you have the Internet (Client) capability enabled (which it is by default). I do it all the time in several applications.
I'm assuming all you want to do is download an xml doc and work with the data.
You should check out http://msdn.microsoft.com/en-us/library/windows/apps/hh441295.aspx if you looking at sending cross document messages. If you want the deep discussion on dynamic web content, security contexts, etc. - this is a good place to start, though a bit dated http://channel9.msdn.com/Events/BUILD/BUILD2011/APP-476T