Skip to content

Native windows: right-click menu downloads save, "in New Window" items tell the truth - #1374

Merged
vasu2001 merged 2 commits into
mainfrom
native-window-context-menu
Oct 3, 2026
Merged

vasu2001 merged 2 commits into
mainfrom
native-window-context-menu

Conversation

@vasu2001

@vasu2001 vasu2001 commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

What

In a native window (macOS) the right-click menu is WebKit's default — a browser's. Two of its items silently did nothing:

  • Download Image / Download Linked File / Download Media — context-menu downloads bypass the public didBecomeDownload hooks and arrive through the private _webView:contextMenuDidCreateDownload:. Nobody adopted the WKDownload, so it had no delegate to pick a destination. Now adopted like a link download: ~/Downloads, Finder-style unique name, Dock bounce.
  • Open Image / Link / Media in New Window — goes through the popup delegate. An external http(s) URL went to the default browser (worked, label lied); a blob: / data: URL (a generated image) had nowhere to go. The proposed menu is now curated through _webView:getContextMenuFromProposedMenu:forElement:userInfo:completionHandler::
    • external URL → retitled "… in Browser"
    • URL on our own server → kept as is (opens a native window)
    • anything else (blob:, data:) → dropped; Copy Image and Download Image remain

Decisions are pure Python in window_policy.context_menu_item; mac_window.py enacts them. The menu is left exactly as proposed when WebKit offers no hit-test URLs (never curate blind).

Notes

  • Both hooks are private WebKit selectors, same precedent as pointer lock / geolocation already in mac_window.py; DMG build, not App Store.
  • Menu item identifiers (WKMenuItemIdentifierOpenImageInNewWindow etc.) come from WKMenuItemIdentifiersPrivate.h, which the SDK doesn't ship — verify live that the retitle/drop lands on the image item.
  • Same fix goes to fused-bot (mainwindow.py) in a sibling PR.

Verify

  1. Native window → an app with a generated (blob/data) image → right-click: no "Open Image in New Window"; Download Image saves into ~/Downloads.
  2. Right-click an https:// image or link: item reads "Open Image in Browser" / "Open Link in Browser" and opens the default browser.
  3. Right-click an app-served image (http://127.0.0.1:<port>/…): item still reads "Open Image in New Window" and opens a native window.

🤖 Generated with Claude Code


Note

Medium Risk
Relies on undocumented WebKit selectors and menu item identifiers that may shift across OS versions; failures degrade to the default menu rather than crashing.

Overview
Native macOS windows now fix broken WebKit right-click behavior by hooking private delegate selectors (same pattern as pointer lock / geolocation).

Context-menu downloads (Download Image, linked file, media) are adopted via _webView:contextMenuDidCreateDownload: and routed through the existing ~/Downloads + unique-name path, instead of silently doing nothing.

“Open … in New Window” items are curated via _webView:getContextMenuFromProposedMenu:… using hit-test URLs and pure policy in window_policy.context_menu_item: loopback app URLs stay as-is; external http(s) labels become “… in Browser”; blob:/data: items are removed. If hit-test data is missing or curation throws, WebKit’s proposed menu is shown unchanged.

Reviewed by Cursor Bugbot for commit a665f39. Bugbot is set up for automated code reviews on this repo. Configure here.

vasu2001 and others added 2 commits October 3, 2026 11:16
…s tell the truth

WebKit's default context menu in a native window is a browser's. Two of its
items silently did nothing:

- "Download Image" / "Download Linked File" / "Download Media": context-menu
  downloads bypass the public didBecomeDownload hooks and arrive through the
  private `_webView:contextMenuDidCreateDownload:`. Nobody adopted the
  WKDownload, so it had no delegate to pick a destination. Now adopted like
  a link download: ~/Downloads, Finder-style unique name, Dock bounce.
- "Open Image/Link/Media in New Window": goes through the popup delegate. An
  external http(s) URL went to the default browser (works, label lied); a
  blob:/data: URL — a generated image — had nowhere to go. The proposed menu
  is now curated through `_webView:getContextMenuFromProposedMenu:…`: external
  → retitled "… in Browser", app URL → kept, anything else → dropped (Copy
  Image and Download Image remain). Decisions live in
  `window_policy.context_menu_item`; the menu is left untouched when WebKit
  offers no hit-test URLs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
A raise inside the curation would leave the right-click with no menu at all.
The debug log of (identifier, title) pairs makes a missed identifier a
one-line fix read off Show Logs — the names come from WebKit source, the SDK
ships no WKMenuItemIdentifiersPrivate.h.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@vasu2001
vasu2001 merged commit d1e6a7d into main Oct 3, 2026
11 of 13 checks passed
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