diff options
author | Adam Outler <[email protected]> | 2023-05-27 11:08:57 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2023-05-27 18:08:57 +0300 |
commit | bfbf3172e30cd519190fe48d29d80cc39b04e0e0 (patch) | |
tree | 700d3785c9ce068a73f430a449aeaa27d0505ba3 | |
parent | f0a860600d375858c9befca7b7194b201fe3df55 (diff) |
Fix crash on unload (#136)
* Fix crash on unload
Within main, exists a `window.beforeunload` handler which brings up the "Are you sure you want to close PiKVM session?" message. When the page is refreshed, the event is `undefined` and, the code which sets the `event.returnValue` to the aforementioned text provides an exception.
To reproduce:
1. Open KVMD web
2. Open developer tools to view Console.
3. Interact with the page by clicking the main window.
4. Refresh the page
5. Observe type error in console.
This patch checks if the event is defined before attempting to set the `event.returnValue`. Other functions are maintained.
* Add space
-rw-r--r-- | web/share/js/kvm/main.js | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/web/share/js/kvm/main.js b/web/share/js/kvm/main.js index 7c1b9f46..15609e1a 100644 --- a/web/share/js/kvm/main.js +++ b/web/share/js/kvm/main.js @@ -36,7 +36,9 @@ export function main() { if (value) { window.onbeforeunload = function(event) { let text = "Are you sure you want to close PiKVM session?"; - event.returnValue = text; + if (event) { + event.returnValue = text; + } return text; }; } else { |