Fix missing images in exported article PDFs - #1
Open
aaln wants to merge 3 commits into
Open
Conversation
Scroll lazy-loaded tweetPhoto nodes into view before extraction, resolve image URLs from background-image fallbacks, upgrade twimg URLs to large, and render PNG/WebP/GIF data URLs with the correct jsPDF format instead of hardcoding JPEG. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@aaln is attempting to deploy a commit to the koredeycode's projects Team on Vercel. A member of the Team first needs to authorize it. |
Use crossOrigin Image+canvas to load twimg URLs (bypasses page CSP on fetch), scroll the correct overflow container for lazy-loaded photos, sanitize HTML-encoded URLs, and apply dynamic image formats on cover pages too. Co-authored-by: Cursor <cursoragent@cursor.com>
Reduce margins, font sizes, line spacing, code block padding, image height, and block gaps so articles fit on fewer printed pages. Co-authored-by: Cursor <cursoragent@cursor.com>
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
[data-testid="tweetPhoto"]nodes.<img src>and the innerbackground-imagediv X uses for rendering.'JPEG'.pbs.twimg.comURLs toname=largefor better export quality.Problem
When exporting long X articles, most images were missing from the generated PDF. On a real-world article with 16 body images, the exported PDF contained only 1 embedded image.
Three separate bugs contributed:
Lazy loading — X only mounts
tweetPhotonodes for content that has been scrolled into view. The exporter read the DOM immediately, so images below the fold were never found (Processing Images (1/1)instead of(16/16)).Hardcoded JPEG format —
renderImageBlockalways calledaddImage(..., 'JPEG', ...). PNG article images (common for diagrams/screenshots) failed silently in thecatchblock and were omitted from the PDF.No background-image fallback — X renders each image with both a
background-imageCSS div and an<img>tag. Video posters already had a background-image fallback, but article images only usedimg.src. When the<img>was not yet loaded, the exporter skipped the image even though the URL was available on the parent div.Failed fetches made this worse: the PNG placeholder generated on fetch failure was also passed to jsPDF as
'JPEG', so even error placeholders never appeared.Solution
preloadArticleImages()— Scroll the full article view, wait for eachtweetPhototo mount and load, then restore scroll position before extraction.resolveTweetPhotoUrl()— Resolve the best available URL from<img>orbackground-image(inline + computed styles), ignoring placeholder src values.normalizeTwitterImageUrl()— Requestname=largefrom twimg for higher-quality exports.getImageFormatFromDataUrl()— Pass the correct format to jsPDF for JPEG, PNG, WebP, and GIF data URLs.[data-testid="tweetPhoto"]containers instead of nestedimgtags so URL resolution is centralized.Test plan
Loading article images...thenProcessing Images (16/16)...twitterArticleRichTextViewis still captured on the title page[X Articles Exporter] Failed to render image blockwarnings for valid imagesMade with Cursor