Search code examples
javascriptxsltxmlhttprequest

Latest Chrome update fails to load XSLT document


Since last Chrome update, when app tries to load an XSLT document it returns empty. I've found out that trying to do an XMLHttpRequest to load a XLST file if you try to return this.responseXML is empty while this.responseText works. Then you have to use a parser to convert it to 'application/xml'. It was working fine until latest update.

    return new Promise(function (resolve) {
        var req = new XMLHttpRequest();
        req.open("GET", url);
        if (typeof XSLTProcessor === 'undefined') {
            try {
                req.responseType = 'msxml-document';
            }
            catch (e) { console.log('error');}
        }
        req.onload = function () {
            resolve(this.responseText);
            //resolve(this.responseXML); --this used to work
        }
        req.send();
    });
}```

Solution

  • adding

    req.overrideMimeType("text/xml"); 
    

    seems to do the trick. By the way the error seems to happen only in Chrome, Edge is fine. Haven't tested in others