Skip to content

fix(viz): load map panels in sandboxed frames without allow-same-origin - #5033

Merged
jqnatividad merged 2 commits into
masterfrom
fix/viz-sandbox-maps-4946
Nov 10, 2026
Merged

jqnatividad merged 2 commits into
masterfrom
fix/viz-sandbox-maps-4946

Conversation

@jqnatividad

Copy link
Copy Markdown
Collaborator

Fixes #4946.

Problem

Every MapLibre map (viz map, viz choropleth --map, and the point and region maps in a Data Schematic) stayed blank, with no error, in a sandboxed frame without allow-same-origin. That includes the CKAN Webpage view sandbox the wiki recommends (sandbox="allow-scripts allow-popups allow-downloads").

In such a frame the page's window.origin is "null" but location.origin is still the URL's, and MapLibre's blob: worker reports "null". MapLibre 4.7.1 (bundled in plotly.js 3.7.0) drops every page↔worker message whose origin field differs from its own, so tiles never load.

Fix

MapLibre's filter exempts the literal origin "file://". A ~15-line Worker wrapper (SANDBOX_WORKER_SHIM) stamps that origin on every message in both directions. Its message listener is registered in the constructor, so it runs before MapLibre's. It is emitted first in plotly_js_block(), before plotly.js creates its workers, so it covers every page path (Data Schematics and single charts) and every bundle mode (inline gzip, QSV_VIZ_NO_COMPRESS, QSV_VIZ_CDN). It does nothing except in an opaque-origin page that isn't a file: page.

This needs no plotly.js 4.x upgrade, which is on hold pending plotly/plotly.rs#437. The wrapper can go once the vendored plotly.js bundles MapLibre ≥ 6.17 (maplibre/maplibre-gl-js#8912).

Also removes the #4947 note shown above each map in such a frame (the JS, its placeholder substitution, 7 locale strings and its unit test), and regenerates all 23 gallery Data Schematics. Their diffs are only the shim, the removed note, the compile time and a new schematic UUID.

Verification

Browser matrix: Chrome, Firefox and Safari, each page in an iframe in three frame modes. Pass = MapLibre loaded() + isStyleLoaded() + areTilesLoaded().

strict sandbox Chrome Firefox Safari
without shim (control) blank blank blank
with shim loads loads loads
  • Pages tested: the Dogs region-map Data Schematic and the nyc311 clustered point maps (CDN gallery pages), plus freshly generated default inline-gzip pages (a Dogs Data Schematic and a viz map).
  • No regressions: every no-sandbox, allow-same-origin and file:// case that reported loaded both with and without the shim. Four control results from the last run never posted back and weren't re-run.
  • Checked by eye in Chrome: the basemap and choropleth are painted.

Tests:

  • New unit test plotly_js_block_installs_sandbox_worker_shim_first, and integration test viz_sandbox_worker_shim_precedes_plotly_bundle, which checks the shim comes before the plotly bundle for viz map in all three bundle modes and for viz smart. Its marker string qsvStampOrigin cannot occur in the plotly bundle.
  • Mutation-checked: removing the shim from plotly_js_block() fails both tests.
  • test_viz 619 passed; viz unit tests 449 passed; clippy clean on changed lines.

Wiki: the Visualization › CKAN advice that map panels don't work in that sandbox is updated separately.

🤖 Generated with Claude Code

jqnatividad and others added 2 commits November 10, 2026 13:11
In a sandboxed frame without allow-same-origin (CKAN's recommended Webpage
view sandbox), the page's window.origin is "null" while location.origin is
still the URL's, and MapLibre's blob: worker reports "null". The MapLibre
bundled in plotly.js 3.x drops every page<->worker message whose origin
differs from its own, so every map panel stayed blank with no error.

Its filter exempts the literal origin "file://". A small Worker wrapper,
emitted first in plotly_js_block() so it runs before plotly.js creates its
workers, stamps that origin on every message in both directions. It is inert
outside opaque-origin, non-file: pages.

Verified in Chrome, Firefox and Safari for region and clustered point maps
in Data Schematics and viz map: strict sandbox blank -> loaded, with no change
under no sandbox, allow-same-origin or file://.

Removes the #4947 note shown above each map in such a frame, and regenerates
the gallery. The wrapper can go once plotly.js bundles MapLibre >= 6.17
(maplibre-gl-js#8912).

Fixes #4946

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request is too large for an AI review. Its diff is over the size the reviewer can fetch from the Git provider. Splitting it into smaller pull requests lets the reviewer cover it.

TIP How was this review? Give us feedback

@jqnatividad
jqnatividad merged commit 26e9512 into master Nov 10, 2026
24 of 25 checks passed
@jqnatividad
jqnatividad deleted the fix/viz-sandbox-maps-4946 branch November 10, 2026 18:24
jqnatividad added a commit that referenced this pull request Nov 11, 2026
The sandbox Worker shim from #5033 only covers MapLibre 4.x (plotly.js
3.x). plotly.js 4.1.2 and 4.2.0 bundle MapLibre 6.11.2, whose module
blob: worker Chrome and Safari refuse in opaque origins, and the shim
tests only check the shim is emitted. Record the trap and the
three-browser check on the shim's doc comment.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
jqnatividad added a commit that referenced this pull request Nov 15, 2026
Regenerated from the 29.0.0 run in b45bb98 with
scripts/gen_benchmark_viz.py, including hero.png for the wiki.
The data-driven prose now reads qsv 29.0.0 and 67 releases. Every
page also picks up #5033's viz template change: the sandboxed-frame
notice is gone and the opaque-origin fix is in <head>.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

viz: map panels stay blank in sandboxed iframes (opaque origin)

1 participant