// Translate the DOM
l10n.translateDOM();
- WebUtil.fetchJSON('./package.json')
+ fetch('./package.json')
+ .then((response) => {
+ if (!response.ok) {
+ throw Error("" + response.status + " " + response.statusText);
+ }
+ return response.json();
+ })
.then((packageInfo) => {
Array.from(document.getElementsByClassName('noVNC_version')).forEach(el => el.innerText = packageInfo.version);
})
if (l10n.language === "en" || l10n.dictionary !== undefined) {
UI.prime();
} else {
- WebUtil.fetchJSON('app/locale/' + l10n.language + '.json')
+ fetch('app/locale/' + l10n.language + '.json')
+ .then((response) => {
+ if (!response.ok) {
+ throw Error("" + response.status + " " + response.statusText);
+ }
+ return response.json();
+ })
.then((translations) => { l10n.dictionary = translations; })
.catch(err => Log.Error("Failed to load translations: " + err))
.then(UI.prime);
localStorage.removeItem(name);
}
}
-
-// sadly, we can't use the Fetch API until we decide to drop
-// IE11 support or polyfill promises and fetch in IE11.
-// resolve will receive an object on success, while reject
-// will receive either an event or an error on failure.
-export function fetchJSON(path) {
- return new Promise((resolve, reject) => {
- // NB: IE11 doesn't support JSON as a responseType
- const req = new XMLHttpRequest();
- req.open('GET', path);
-
- req.onload = () => {
- if (req.status === 200) {
- let resObj;
- try {
- resObj = JSON.parse(req.responseText);
- } catch (err) {
- reject(err);
- }
- resolve(resObj);
- } else {
- reject(new Error("XHR got non-200 status while trying to load '" + path + "': " + req.status));
- }
- };
-
- req.onerror = evt => reject(new Error("XHR encountered an error while trying to load '" + path + "': " + evt.message));
-
- req.ontimeout = evt => reject(new Error("XHR timed out while trying to load '" + path + "'"));
-
- req.send();
- });
-}