feat: support documentTitle for PDF printing via document.title guard#724
Open
danielrose7 wants to merge 2 commits into
Open
feat: support documentTitle for PDF printing via document.title guard#724danielrose7 wants to merge 2 commits into
danielrose7 wants to merge 2 commits into
Conversation
For PDF iframes, Chrome uses document.title (not the iframe's <title>) for "Save as PDF" filenames. Since print() on a PDF iframe is non-blocking, Chrome reads document.title asynchronously after return. This adds a MutationObserver-based guard that temporarily holds document.title to the desired value, preventing framework re-renders (React <Head>, Vue router, etc.) from resetting it during that window. Adds documentTitleHoldMs param (default 3000ms) to let users tune the hold duration. Closes crabbly#487 Closes crabbly#66 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 23, 2026
Open
Two buttons added: - "Print PDF with documentTitle" — basic test, verify Chrome's print dialog shows "My Custom Report" as the filename - "Print PDF with documentTitle (simulated framework reset)" — uses a setInterval to aggressively reset document.title, proving the MutationObserver guard holds the title stable Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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
document.title(not the iframe's<title>) for "Save as PDF" filenames. Sinceprint()is deferred viasetTimeout, there's a window between setting the title and Chrome actually reading it — during which a framework (React<Head>, Vue router, etc.) can reset it.MutationObserver-based guard that holdsdocument.titleto the desired value across that window, catching and reverting any mutations. Falls back gracefully whenMutationObserveris unavailable.documentTitleHoldMsparam (default3000ms) to let users tune the hold duration.Closes #487
Closes #66
Reference
Standalone helper with writeup: https://gist.github.com/danielrose7/adb604b9334118d98de6e856efd043df
Test plan
Manual test cases are included in
test/manual/index.html— runnpm start(or serve the project root) and click:document.titleevery 50ms to prove theMutationObserverguard holdsAdditional checks:
html,image,json) still work as before (no title guard, immediate cleanup)document.titleis restored after the hold perioddocumentTitleHoldMs: 500to verify custom hold durations work🤖 Generated with Claude Code