Skip to content

fix(dashboard): export PDF when an external map is on the dashboard - #46676

Open
schizophrenicmaniac wants to merge 1 commit into
apache:masterfrom
schizophrenicmaniac:fix/46638-dashboard-export-pdf-failed-if-external
Open

schizophrenicmaniac wants to merge 1 commit into
apache:masterfrom
schizophrenicmaniac:fix/46638-dashboard-export-pdf-failed-if-external

Conversation

@schizophrenicmaniac

Copy link
Copy Markdown
Contributor

SUMMARY

Exporting a dashboard to PDF fails when it has a cartodiagram chart with an external base map. The XYZ and WMS tile layers load their tiles without crossOrigin, so the browser taints the OpenLayers canvas as soon as a tile from another origin is drawn. dom-to-pdf later calls toDataURL() on every canvas, which throws a SecurityError on the tainted one, and the whole export is abandoned. dom-to-pdf catches that error itself, so the user doesn't even get the warning toast, just no file.

Two changes:

  • createXyzLayer and createWmsLayer set crossOrigin: 'anonymous' on their sources, so tiles from servers that send CORS headers (OSM and most public tile and WMS servers) no longer taint the canvas and the map shows up in the PDF. This matches what OpenLayers' own OSM source does by default. The trade-off is that a tile server without CORS headers won't display tiles in the chart anymore.
  • downloadAsPdf checks the canvases inside the element being exported before handing it to dom-to-pdf. Any canvas that can't be read back gets a temporary class that is passed to excludeClassNames, so it's left out of the PDF instead of breaking the export. The class is removed again once the export settles. That covers a canvas that is still tainted for some other reason, at the cost of that one canvas being missing from the PDF.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before/after screenshots still to be added.

TESTING INSTRUCTIONS

  1. Create a Cartodiagram chart with an XYZ base layer, e.g. https://tile.openstreetmap.org/{z}/{x}/{y}.png, and add it to a dashboard.
  2. Open the dashboard and pick Download > Export to PDF.
  3. Before this change no PDF is downloaded and the console shows a SecurityError about tainted canvases. After it, the PDF downloads and includes the map.
  4. Optionally, point the layer at a tile server that sends no CORS headers. The export still produces a PDF with the rest of the dashboard.

Unit tests: npm run test -- src/utils/downloadAsPdf.test.ts plugins/plugin-chart-cartodiagram

ADDITIONAL INFORMATION

  • Has associated issue: Fixes Dashboard ; Export PDF failed if external map is used #46638
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

* taint the map canvas, and exporting a dashboard as PDF fails because the
* canvas can no longer be read.
*/
const TILE_CROSS_ORIGIN = 'anonymous';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: For external services that require cookie authentication, anonymous omits cross-origin credentials; configured WMS and XYZ layers then fail to load even when CORS is enabled.

Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Api mismatch

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset-frontend/plugins/plugin-chart-cartodiagram/src/util/layerUtil.tsx
**Line:** 64:64
**Comment:**
	*Api Mismatch: For external services that require cookie authentication, `anonymous` omits cross-origin credentials; configured WMS and XYZ layers then fail to load even when CORS is enabled.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟡  Medium Risk

  • The PR needs attention before merging: anonymous CORS requests omit credentials for external tile services, breaking layers that rely on cookie authentication.

Assessed commit: 5504abfddf11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard ; Export PDF failed if external map is used

1 participant