0

I have a simple set up in which I populate data on my HTML page by accessing data in a Google Sheet.

This works perfectly well in Chrome, but in Edge I get a CORB error in the console. I'm using Google Apps Script and Vanilla JS. My Google Apps Script is

function doGet(request) {
  var res = getData();
  return ContentService.createTextOutput(
    request.parameters.prefix + '(' + JSON.stringify(res) + ')')
    .setMimeType(ContentService.MimeType.JAVASCRIPT);
}
 
//GET DATA FROM GOOGLE SHEET AND RETURN AS AN ARRAY
function getData(){
  var spreadSheetId = "mySpreadsheetID";
  var dataRange     = "Projects!A2:J50";
 
  var range   = GoogleSheetsAPI.Spreadsheets.Values.get(spreadSheetId,dataRange);
  return range.values;
}

and my JavaScript is:

var gScriptURL = "https://script.google.com/a/macros/blah/s/blahblahblah/exec?prefix=console.log&dataType=json&callback=?";

var loadJSONP = (function(){
  var unique = 0;
  return function(url, callback, context) {

    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = url;

    window[name] = function(data){
      callback.call((context || window), data);
      document.getElementsByTagName("head")[0].removeChild(script);
      script = null;
      delete window[name];
    };

    document.getElementsByTagName("head")[0].appendChild(script);
  };
})();

function getData(){
    loadJSONP(
    gScriptURL,
    function(data) {
      console.log(data);
    }
  );
}

In Google Chrome, I get an array dumped to the console, in Edge I get:

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://url.com/login/login.htm?fromURI=blahblah with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

Which seems to have issues with MIME type text/html, but I'm explicitly requesting json. Or am I!?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
  • `https://script.google.com/macros/s/blahblahblah/exec?prefix=console.log&dataType=json&callback=sdfd` — is an HTML document with a 404 error. It isn't JSONP (which is not the same as JSON). You only get JSONP is the server actually supports it (which is a shrinking number since it is 2022, JSONP is awful, and we have CORS now). – Quentin Jun 23 '22 at 09:50
  • Thanks guys. I've found the problem, but I don't really have a solution! I was logged in to my Google account in Chrome, but not in Edge. I wanted to publish the Google Apps Script so that anyone can access it, but my only option is myself or people within my organisation. So when not logged in, the request returns an error. – GeorgePorge Jun 23 '22 at 10:04

0 Answers0