Skip to content

Commit d55f02e

Browse files
committed
fix memory leaks caused by the "Restart the Game" button shown on crash
1 parent 4931f6d commit d55f02e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

runtime/src/error-screen.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
export {};
44

5+
// eslint-disable-next-line no-var, @typescript-eslint/no-explicit-any
6+
declare var chrome: any;
7+
58
let originalErrorCallback = window.GAME_ERROR_CALLBACK;
69
if (originalErrorCallback != null) {
710
const MODLOADER_NAME = modloader.name;
@@ -12,6 +15,20 @@ if (originalErrorCallback != null) {
1215
window.GAME_ERROR_CALLBACK = function (error, info, gameInfo, ...args) {
1316
info[`${MODLOADER_NAME} version`] = MODLOADER_VERSION;
1417
info[`${RUNTIME_MOD_ID} version`] = RUNTIME_MOD_VERSION;
15-
return originalErrorCallback.call(this, error, info, gameInfo, ...args);
18+
let result = originalErrorCallback.call(this, error, info, gameInfo, ...args);
19+
20+
if (typeof nw !== 'undefined' && typeof chrome !== 'undefined') {
21+
for (let container of document.getElementsByClassName('errorMessage')) {
22+
for (let button of container.getElementsByTagName('a')) {
23+
// eslint-disable-next-line no-script-url
24+
if (button.href === 'javascript:window.location.reload()') {
25+
// eslint-disable-next-line no-script-url
26+
button.href = 'javascript:chrome.runtime.reload()';
27+
}
28+
}
29+
}
30+
}
31+
32+
return result;
1633
};
1734
}

0 commit comments

Comments
 (0)