Repository navigation
fix(dashboard): export PDF when an external map is on the dashboard - #46676
Open
schizophrenicmaniac wants to merge 1 commit into
Open
schizophrenicmaniac wants to merge 1 commit into
schizophrenicmaniac wants to merge 1 commit into
Conversation
| * taint the map canvas, and exporting a dashboard as PDF fails because the | ||
| * canvas can no longer be read. | ||
| */ | ||
| const TILE_CROSS_ORIGIN = 'anonymous'; |
Contributor
There was a problem hiding this comment.
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
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
Contributor
This branch has not been deployed
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.
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 callstoDataURL()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:
createXyzLayerandcreateWmsLayersetcrossOrigin: '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.downloadAsPdfchecks 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 toexcludeClassNames, 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
https://tile.openstreetmap.org/{z}/{x}/{y}.png, and add it to a dashboard.Unit tests:
npm run test -- src/utils/downloadAsPdf.test.ts plugins/plugin-chart-cartodiagramADDITIONAL INFORMATION