Skip to content

Commit

Permalink
fix: save with latest google chrome (#425)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
machow committed Aug 30, 2024
1 parent 0422164 commit 11660a6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions great_tables/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,27 +360,31 @@ 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)

# height accounts for top-padding supplied by the browser (doubled to pad top and bottom)
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)
Expand Down Expand Up @@ -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)

0 comments on commit 11660a6

Please sign in to comment.