Repository navigation
Fix drag-and-drop and console warnings in Electron examples - #122
Open
miguelcalderon wants to merge 1 commit into
Open
miguelcalderon wants to merge 1 commit into
miguelcalderon wants to merge 1 commit into
Conversation
Dropping a PDF did nothing because the examples read `File.path`, which Electron removed in v32. Use `webUtils.getPathForFile` and pass the viewer a `file://` URL, which it can open. Set `baseUrl` (and `useCDN: false`) so the viewer stops warning about auto-detected assets, and add a Content Security Policy so Electron stops warning about an insecure renderer. Inline renderer scripts move to files so the policy doesn't need to allow inline scripts. Co-Authored-By: Claude Opus 5.5 <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.
What
Fixes drag-and-drop in both Electron examples and removes two console warnings. Found while smoke-testing #118. This PR targets
mainand works on both Electron 41 and 42.File.path, which Electron removed in v32. It now useswebUtils.getPathForFileand passes the viewer afile://URL. A plain file system path still fails with "File not in PDF format or corrupted", even for the bundledexample.pdf.baseUrlwarning: Both examples now setbaseUrlto the installed npm package anduseCDN: false.blob:/data:workers, images and fonts, and the viewer's usage metrics endpoint. The policy doesn't allow inline scripts, so the inline renderer scripts moved intorenderer.jsfiles. The moved code is unchanged apart from Biome formatting and one lint fix.The viewer still logs "Copying assets from the npm package is deprecated", because the assets still load from
node_modules. Removing it needs an SDK change for Electron, so it isn't part of this PR. The existingpreloadWorker()hint is also unchanged.Type
Checklist
pnpm run formatpasses (Biome)startandstart:e2escripts inpackage.json(not applicable: the Electron examples are excluded from e2e)SERVER_DIR=examples/<name> pnpm run testpasses (not applicable for the same reason)README.mdincluded with prerequisites, setup, and usage@nutrient-sdk/viewerversionEvidence
I tested both examples on macOS with Electron 41.10.7. A script launched each app, read the console through DevTools, and simulated dropping a 6-page PDF onto the viewer.
baseUrland insecure-CSP warnings.Not tested: the Open and Export toolbar buttons (they use native dialogs), Windows and Linux, and packaged builds.
🤖 Generated with Claude Code