Skip to content

Conversation

@leaanthony
Copy link
Member

@leaanthony leaanthony commented Oct 14, 2025

Summary

Fixes Windows HTML drag and drop functionality by properly configuring AllowExternalDrag after WebView2 initialization.

This is a backport of the v3 fix from PR #4259 to v2.

Changes

  • Move AllowExternalDrag(false) call to after chromium.Embed() (was called before)
  • Add chromium.HasCapability(edge.AllowExternalDrop) check before calling
  • Change condition from DisableWebViewDrop to EnableFileDrop (consistent with v3)
  • Update changelog

Technical Details

The issue occurred because:

  1. AllowExternalDrag was called before the WebView2 was embedded, causing it to fail silently
  2. Missing capability check meant it could fail on older WebView2 versions
  3. Wrong condition logic - should disable external drag when Wails handles file drops

When EnableFileDrop is true, Wails needs to handle dropped files, so we disable the webview's native external drag to prevent it from opening files automatically.

Testing

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved Windows HTML drag-and-drop reliability by enabling external file drop only when explicitly configured and supported, preventing unintended blocking and ensuring smoother interactions.
    • Adjusted initialization order to better align with platform capabilities, enhancing compatibility and stability for drag-and-drop on Windows.
  • Documentation

    • Updated changelog with details on the Windows drag-and-drop fix and guidance on enabling external file drop when supported.

* Move AllowExternalDrag call after chromium.Embed()
* Add capability check before calling AllowExternalDrag
* Change condition from DisableWebViewDrop to EnableFileDrop
* Update changelog

Fixes #3782

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@cloudflare-workers-and-pages
Copy link

Deploying wails with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2b3df04
Status:🚫  Build failed.

View logs

@github-actions github-actions bot added Documentation Improvements or additions to documentation Windows v2-only labels Oct 14, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

Walkthrough

Switches Windows drag-and-drop handling to an opt-in flow: removes unconditional/disable path and adds a new EnableFileDrop check after Chromium embed, gated by an AllowExternalDrop capability. Updates changelog to note the Windows HTML drag-and-drop fix and the new call order/capability gating.

Changes

Cohort / File(s) Summary
Windows frontend DnD logic
v2/internal/frontend/desktop/windows/frontend.go
Replaces DisableWebViewDrop-based block with EnableFileDrop-based logic executed post-Embed; checks Chromium capability (AllowExternalDrop) before calling AllowExternalDrag(false); adds warning log on error; positioned before swipe navigation handling.
Documentation (changelog)
website/src/pages/changelog.mdx
Notes Windows HTML drag-and-drop fix; documents moving AllowExternalDrag call after Embed and adding capability check; no API changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App
  participant WinFrontend as Windows Frontend
  participant Chromium as Chromium Edge

  App->>WinFrontend: Start (with DragAndDrop config)
  WinFrontend->>Chromium: Embed()
  Note over WinFrontend,Chromium: Post-embed initialization

  alt DragAndDrop.EnableFileDrop is true
    WinFrontend->>Chromium: Check capability: AllowExternalDrop?
    alt Capability available
      WinFrontend->>Chromium: AllowExternalDrag(false)
      Note right of Chromium: External HTML DnD disabled<br/>OS-level file drop enabled
    else Capability missing
      WinFrontend->>WinFrontend: Log warning (capability unavailable)
    end
  else EnableFileDrop is false
    Note over WinFrontend: No change to external drag behavior
  end

  WinFrontend->>WinFrontend: Initialize swipe navigation handlers
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

Bug, go, size:M, lgtm

Poem

A hop, a drop, a careful stop—
I tweak the wind where files do plop.
After embed, I sniff the breeze,
“Capability?” I ask with ease.
If yes, I nudge the drag just so—
Now DnD’s right, onward we go! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description includes a summary, change list, technical details, testing notes, and related issues but does not follow the required repository template sections such as Type of change with checkboxes, How Has This Been Tested? with platform-specific checkmarks, Test Configuration output, or the final checklist. Please update the description to include the Type of change section with checkboxes, the How Has This Been Tested? section with platform test markers, the Test Configuration section with wails doctor output, and the repository checklist to fully comply with the template.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary change, namely fixing Windows HTML drag-and-drop in the v2 release, and directly references the correct issue number, making it clear and focused without extraneous detail.
Linked Issues Check ✅ Passed The code updates align with the linked issue objectives by moving the AllowExternalDrag call after WebView2 embedding, gating it on the EnableFileDrop flag and the AllowExternalDrop capability, thereby ensuring external drag is disabled only when needed and restoring backend file-drop events without altering behavior for apps that do not opt in.
Out of Scope Changes Check ✅ Passed All code changes are scoped to the Windows frontend Go file and the changelog, directly addressing the drag-and-drop fix without introducing unrelated modifications in other areas of the codebase.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-3782-windows-drag-drop-v2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
v2/internal/frontend/desktop/windows/frontend.go (1)

545-552: Correct placement and gating; include error details in warning.

Logic matches v3: after Embed, gated by EnableFileDrop and capability. Improve diagnosability by logging the underlying error.

-            if err != nil {
-                f.logger.Warning("WebView failed to set AllowExternalDrag to false!")
-            }
+            if err != nil {
+                f.logger.Warning("WebView2 AllowExternalDrag(false) failed: %v", err)
+            }
website/src/pages/changelog.mdx (1)

30-30: Clarify that the change is gated by EnableFileDrop.

Add the EnableFileDrop gating note to match the implementation and v3 behavior.

- - Fixed Windows HTML drag and drop by moving AllowExternalDrag call after Embed and adding capability check [#3782](https://github.com/wailsapp/wails/issues/3782)
+ - Fixed Windows HTML drag and drop by moving AllowExternalDrag call after Embed, gating it behind `EnableFileDrop`, and adding a capability check [#3782](https://github.com/wailsapp/wails/issues/3782)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4df077f and 2b3df04.

📒 Files selected for processing (2)
  • v2/internal/frontend/desktop/windows/frontend.go (1 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
v2/internal/frontend/desktop/windows/frontend.go (1)
v2/pkg/options/options.go (1)
  • DragAndDrop (201-216)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: semgrep-cloud-platform/scan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation v2-only Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webview failed to set AllowExternalDrag to false on Win 10 ( after cross compile on macOS)

2 participants