From 8df513fbd3343576040eebedb6a89a231dc4f4e8 Mon Sep 17 00:00:00 2001 From: m-khan-glyptodon Date: Mon, 7 Jan 2019 14:54:00 -0800 Subject: [PATCH] Added scroll height and scroll width cap to fix ios safari crash --- .../src/main/webapp/scripts/client-ui.js | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/guacamole-tunnel/src/main/webapp/scripts/client-ui.js b/guacamole-tunnel/src/main/webapp/scripts/client-ui.js index 7e3fe300..3fe8f6a9 100644 --- a/guacamole-tunnel/src/main/webapp/scripts/client-ui.js +++ b/guacamole-tunnel/src/main/webapp/scripts/client-ui.js @@ -1581,6 +1581,38 @@ GuacUI.Client.attach = function(guac) { GuacUI.Client.attachedClient.disconnect(); }; + /** + * Calculates maximum possible height that can be scrolled. For additional + * info, visit: https://muffinman.io/ios-safari-get-bounding-client-rect-bug/ + * + * @returns {number} A number that represents the max height in pixels. + */ + function getPageMaxHeight() { + return Math.max( + document.body.scrollHeight, + document.body.offsetHeight, + document.documentElement.clientHeight, + document.documentElement.scrollHeight, + document.documentElement.offsetHeight + ) - window.innerHeight; // Subtract viewport height + } + + /** + * Calculates maximum possible width that can be scrolled. For additional + * info, visit: https://muffinman.io/ios-safari-get-bounding-client-rect-bug/ + * + * @returns {number} A number that represents the max width in pixels. + */ + function getPageMaxWidth() { + return Math.max( + document.body.scrollWidth, + document.body.offsetWidth, + document.documentElement.clientWidth, + document.documentElement.scrollWidth, + document.documentElement.offsetWidth + ) - window.innerWidth; // Subtract viewport width + } + /* * Reflow layout and send size events on resize/scroll */ @@ -1608,9 +1640,17 @@ GuacUI.Client.attach = function(guac) { last_scroll_height = document.body.scrollHeight; last_window_width = window.innerWidth; last_window_height = window.innerHeight; + + // Get appropriate scrolling height (not greater than max value) + var maxHeight = getPageMaxHeight(); + var scrollHeight = Math.min(document.body.scrollHeight, maxHeight); + + // Get appropriate scrolling width (not greater than max value) + var maxWidth = getPageMaxWidth(); + var scrollWidth = Math.min(document.body.scrollWidth, maxWidth); // Reset scroll and reposition document such that it's on-screen - window.scrollTo(document.body.scrollWidth, document.body.scrollHeight); + window.scrollTo(scrollWidth, scrollHeight); // Determine height of bottom section (currently only text input) var bottom = GuacUI.Client.text_input.container;