Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: save with latest google chrome #425

Merged
merged 6 commits into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading