CORB from Vanilla JS getJSONP to Google Apps Script

17 Views Asked by At

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!?

0

There are 0 best solutions below