Skip to content

Commit 1271689

Browse files
committed
Save screenshot of whole page, and accept select kernel dialog if present
1 parent 7d4b985 commit 1271689

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

jupyter_output_monitor/_monitor.py

+24
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,30 @@ def _monitor_output(url, output, wait_after_execute, headless):
114114

115115
print(f"{len(input_cells)} input cells found")
116116

117+
# Take screenshot of the whole page, for the record
118+
screenshot_bytes = page.screenshot()
119+
120+
timestamp = isotime()
121+
122+
screenshot_filename = os.path.join(
123+
output,
124+
f"page-{iso_to_path(timestamp)}.png",
125+
)
126+
image = Image.open(BytesIO(screenshot_bytes))
127+
image.save(screenshot_filename)
128+
129+
# Check if server is asking us to select a kernel
130+
dialogs = list(page.query_selector_all(".jp-Dialog-header"))
131+
for dialog in dialogs:
132+
if 'Select Kernel' in dialog.inner_text():
133+
print("Server is asking to select a kernel, accepting default")
134+
accept = list(page.query_selector_all(".jp-mod-accept"))
135+
if len(accept) == 1:
136+
accept[0].click()
137+
else:
138+
print("Error: multiple accept buttons found, not sure which to click")
139+
sys.exit(1)
140+
117141
last_screenshot = {}
118142

119143
# Now loop over each input cell and execute

0 commit comments

Comments
 (0)