Fix %jigsaw cross-origin errors and restore button functionality#375
Merged
blink1073 merged 3 commits intoCalysto:mainfrom Mar 14, 2026
Merged
Fix %jigsaw cross-origin errors and restore button functionality#375blink1073 merged 3 commits intoCalysto:mainfrom
blink1073 merged 3 commits intoCalysto:mainfrom
Conversation
Calysto#176, Calysto#199, Calysto#170, Calysto#166, Calysto#165) Replace the old same-origin window.parent.* architecture with postMessage so the jigsaw iframe works in modern browsers with cross-origin/sandboxed frames. Restore Run, Generate, and Clear button behaviour for both Notebook 6 and Notebook 7. Key changes: - Remove all window.parent.* direct-access calls from the downloaded iframe HTML (_fix_cross_origin), replacing button handlers with local postMessage helpers and workspace registration with inline XML initialisation (no XHR required). - Embed previously saved workspace XML in the HTML at magic run time so the Blockly state is restored when the cell is re-executed. - Add a parent-side message listener (postMessage) that handles execute, insert, and clear actions; registered once, updated on every %jigsaw run. - Support Notebook 6 (IPython.notebook classic API) and Notebook 7 (DOM + Jupyter REST/WebSocket fallback) in a single code path. - All output (run results and generated code) is shown in the jigsaw cell's own output area rather than a separate cell. - Fix Blockly indentation: set INDENT = ' ' (4 spaces) for all generators. - Create subdirectories for workspace paths that include a subdirectory component.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #375 +/- ##
==========================================
- Coverage 90.96% 90.82% -0.14%
==========================================
Files 51 51
Lines 2921 2943 +22
Branches 409 410 +1
==========================================
+ Hits 2657 2673 +16
- Misses 185 190 +5
- Partials 79 80 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This was referenced Mar 14, 2026
blink1073
added a commit
to blink1073/calysto.github.io
that referenced
this pull request
Mar 15, 2026
These pages are intended to replace the shims added to metakernel in Calysto/metakernel#375
This was referenced Mar 15, 2026
blink1073
added a commit
to blink1073/metakernel
that referenced
this pull request
Mar 15, 2026
Calysto#196 with Calysto#375) Adds docs/jupyterhub.md covering kernel installation, Apache/nginx reverse-proxy config, and an explanation of the Jigsaw CORS fix. Adds two unit tests that demonstrate the window.parent cross-origin issue and verify _fix_cross_origin eliminates every direct property access in favour of postMessage and embedded XML.
2 tasks
blink1073
added a commit
that referenced
this pull request
Mar 15, 2026
#196) (#386) * Add JupyterHub deployment docs and cross-origin regression tests (closes #196 with #375) Adds docs/jupyterhub.md covering kernel installation, Apache/nginx reverse-proxy config, and an explanation of the Jigsaw CORS fix. Adds two unit tests that demonstrate the window.parent cross-origin issue and verify _fix_cross_origin eliminates every direct property access in favour of postMessage and embedded XML. * Update troubleshooting version reference to >= 1.0
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #176, #199, #170, #166, #165
Summary
window.parent.*direct-access calls in the downloaded iframe HTML withpostMessage, fixing cross-origin/sandboxed frame errors in modern browsersTechnical approach
The old implementation relied on
window.parent.Blockly,window.parent.IPython, andwindow.parent.document.*— all blocked by modern browser security for cross-origin or null-origin sandboxed frames.The new implementation:
_fix_cross_origin()rewrites the downloaded Blockly HTML to remove allwindow.parent.*accesses, inject saved workspace XML as a JS variable, and replace buttononclickhandlers with localpostMessagehelpersJavascript()) receivesexecute/insert/clearmessages from the iframe and handles them using the appropriate notebook API — the classicIPython.notebookOutputArea API for Notebook 6, or DOM manipulation + Jupyter REST/WebSocket for Notebook 7elementis in scope) so the message handler can find it later withoutframeElement, which is null for cross-origin framesTest plan
just test tests/magics/test_jigsaw_magic.py— both tests pass%jigsawcell