2023-10-20 22:35:26 +08:00
|
|
|
// SPDX-FileCopyrightText: 2023 XWiki CryptPad Team <contact@cryptpad.org> and contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2022-04-04 16:25:00 +08:00
|
|
|
(function () {
|
2022-04-04 19:01:20 +08:00
|
|
|
var h = (tag, children) => {
|
|
|
|
var el = document.createElement(tag);
|
|
|
|
children.forEach(child => {
|
|
|
|
if (typeof(child) === 'string') {
|
|
|
|
return void el.appendChild(document.createTextNode(child));
|
|
|
|
}
|
|
|
|
el.appendChild(child);
|
|
|
|
});
|
|
|
|
return el;
|
|
|
|
};
|
|
|
|
|
2022-04-04 16:25:00 +08:00
|
|
|
var first = true;
|
|
|
|
window.addEventListener('error', function (ev) {
|
2022-05-03 20:50:18 +08:00
|
|
|
if (window.CHECKUP_MAIN_LOADED) { return; }
|
2022-04-04 16:25:00 +08:00
|
|
|
if (!ev) { return; }
|
|
|
|
var srcElement = ev.srcElement;
|
|
|
|
if (!srcElement) { return; }
|
|
|
|
var nodeName = srcElement.nodeName;
|
|
|
|
if (nodeName !== 'SCRIPT') { return; }
|
|
|
|
var src = srcElement.src;
|
2022-04-04 19:01:20 +08:00
|
|
|
|
|
|
|
if (/\/api\/.*/.test(src)) {
|
|
|
|
console.error("A serverside API endpoint could not be reached.", src);
|
2023-01-07 20:27:20 +08:00
|
|
|
// don't warn about missing components if the error is the optional instance endpoint
|
2022-05-30 18:04:02 +08:00
|
|
|
if (/\/api\/instance/.test(src)) { return; }
|
2022-04-04 19:01:20 +08:00
|
|
|
}
|
|
|
|
|
2023-01-07 20:27:20 +08:00
|
|
|
//if (!/\/components\/.*/.test(src)) { return; }
|
2022-04-04 16:25:00 +08:00
|
|
|
if (first) {
|
2022-04-04 19:01:20 +08:00
|
|
|
document.body.appendChild(h('h1', ['Oops!']));
|
|
|
|
document.body.appendChild(h('p', [
|
2023-01-07 20:27:20 +08:00
|
|
|
`It's possible that required resource couldn't be loaded.`,
|
2022-04-04 19:01:20 +08:00
|
|
|
` See your browser's console for more details.`,
|
|
|
|
]));
|
2022-04-04 16:25:00 +08:00
|
|
|
first = false;
|
|
|
|
}
|
2022-04-04 19:01:20 +08:00
|
|
|
document.body.appendChild(h('p', [
|
|
|
|
'Failed to load ',
|
|
|
|
h('code', [src]),
|
|
|
|
'.',
|
|
|
|
]));
|
2022-04-04 16:25:00 +08:00
|
|
|
}, true);
|
|
|
|
}());
|