From 11660a66b9291e137db93a74b985941f4a63ad90 Mon Sep 17 00:00:00 2001 From: Michael Chow Date: Fri, 30 Aug 2024 13:29:34 -0400 Subject: [PATCH] fix: save with latest google chrome (#425) * orphan commit * fix: up crud factor in .save method * fix: add small sleep after resizing to .save * fix: correctly account for outer ui in .save * fix: up crud factor a pinch for a little breathing room * fix: make debug borders less wide --- great_tables/_export.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/great_tables/_export.py b/great_tables/_export.py index e0db57b9a..54189d26b 100644 --- a/great_tables/_export.py +++ b/great_tables/_export.py @@ -360,19 +360,23 @@ def _save_screenshot( # the window can be bigger than the table, but smaller risks pushing text # onto new lines. this pads width and height for a little slack. # note that this is mostly to account for body, div padding, and table borders. - crud_factor = 100 - + crud_factor = 20 + outer_width, outer_height = driver.execute_script( + "var w = window; return [w.outerWidth - w.innerWidth, w.outerHeight - w.innerHeight]" + ) offset_left, offset_top = driver.execute_script( "var div = document.body.childNodes[0]; return [div.offsetLeft, div.offsetTop];" ) reported_width = driver.execute_script( "var el = document.getElementsByTagName('table')[0]; return el.clientWidth;" ) - required_width = (reported_width + offset_left * 2 + crud_factor) * scale + required_width = (reported_width + offset_left * 2) * scale + crud_factor + outer_width # set to our required_width first, in case it changes the height of the table driver.set_window_size(required_width, original_size["height"]) + time.sleep(0.05) + if debug == "width_resize": return _dump_debug_screenshot(driver, path) @@ -380,7 +384,7 @@ def _save_screenshot( div_height = driver.execute_script( "var div = document.body.childNodes[0]; return div.scrollHeight;" ) - required_height = div_height + crud_factor + offset_top * 2 + required_height = div_height + offset_top * 2 + outer_height # final resize window and capture image ---- driver.set_window_size(required_width, required_height) @@ -410,8 +414,8 @@ def _save_screenshot( def _dump_debug_screenshot(driver, path): driver.execute_script( - "document.body.style.border = '5px solid blue'; " - "document.body.childNodes[0].style.border = '5px solid orange'; " - "document.getElementsByTagName('table')[0].style.border = '5px solid green'; " + "document.body.style.border = '3px solid blue'; " + "document.body.childNodes[0].style.border = '3px solid orange'; " + "document.getElementsByTagName('table')[0].style.border = '3px solid green'; " ) driver.save_screenshot(path)