Skip to content

Fix drag-and-drop and console warnings in Electron examples - #122

Open
miguelcalderon wants to merge 1 commit into
mainfrom
miguel/electron-drag-drop-console-warnings
Open

miguelcalderon wants to merge 1 commit into
mainfrom
miguel/electron-drag-drop-console-warnings

Conversation

@miguelcalderon

Copy link
Copy Markdown
Contributor

What

Fixes drag-and-drop in both Electron examples and removes two console warnings. Found while smoke-testing #118. This PR targets main and works on both Electron 41 and 42.

  • Drag-and-drop: Dropping a PDF did nothing and logged "Backend could not be inferred". The code read File.path, which Electron removed in v32. It now uses webUtils.getPathForFile and passes the viewer a file:// URL. A plain file system path still fails with "File not in PDF format or corrupted", even for the bundled example.pdf.
  • Missing baseUrl warning: Both examples now set baseUrl to the installed npm package and useCDN: false.
  • Electron insecure-CSP warning: Both pages now set a Content Security Policy. It allows the WebAssembly engine, the viewer's 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 into renderer.js files. 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 existing preloadWorker() hint is also unchanged.

Type

  • New framework example
  • Update existing example
  • SDK version bump
  • Bug fix
  • Repo infrastructure (CI, scripts, docs)

Checklist

  • pnpm run format passes (Biome)
  • Example has start and start:e2e scripts in package.json (not applicable: the Electron examples are excluded from e2e)
  • SERVER_DIR=examples/<name> pnpm run test passes (not applicable for the same reason)
  • README.md included with prerequisites, setup, and usage
  • Uses current pinned @nutrient-sdk/viewer version

Evidence

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.

  • Before: the drop failed with "Backend could not be inferred". The console showed the missing-baseUrl and insecure-CSP warnings.
  • After: the dropped PDF opens (the page indicator changes from "1 / 3" to "1 / 6"). Neither warning appears, and the console shows no CSP violations.

Not tested: the Open and Export toolbar buttons (they use native dialogs), Windows and Linux, and packaged builds.

🤖 Generated with Claude Code

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>
@miguelcalderon
miguelcalderon requested a review from a team as a code owner November 16, 2026 10:36
@miguelcalderon miguelcalderon self-assigned this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant