Skip to content

fix(desktop): keep clipboard permissions for every app window - #57513

Open
SomaRe wants to merge 2 commits into
anomalyco:devfrom
SomaRe:desktop-clipboard-permissions
Open

SomaRe wants to merge 2 commits into
anomalyco:devfrom
SomaRe:desktop-clipboard-permissions

Conversation

@SomaRe

@SomaRe SomaRe commented Oct 20, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #51748

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

allowRendererPermissions registered the session permission handlers per window while keying them on that window's webContents.id. The handlers live on the session, so opening another window replaced them and every older window then failed the id check. That breaks navigator.clipboard.writeText in all but the newest window, which is why the markdown code block copy button silently does nothing there.

The handlers are now registered once per session and check the live webContents ids kept in a set, adding ids on window creation and removing them on close. Every app window keeps clipboard and notification access.

Also narrowed the unused openExternalURL callback return from unknown to void, because lint:changed lints the whole touched file and the repo disallows unknown returns.

How did you verify your code works?

  • Two-window Electron 44.4.5 harness using the same handler shape: before the fix the older window rejects navigator.clipboard.writeText with NotAllowedError: Write permission denied; after the fix the permission check returns true for both windows and false for an unknown webContents.
  • bun test in packages/desktop (130 pass, 1 skip).
  • bun run typecheck in packages/desktop.

Screenshots / recordings

N/A, no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks correct from reading the code. All app windows share one Electron session, so setting the permission handlers once per session and checking a set of open window ids fixes the case where only the newest window keeps clipboard and notification access. Embedded views and other web content are never added to the set, so they stay denied as before. Windows are removed from the set on closed, and a renderer crash or reload keeps the same webContents, so its id stays valid.

I couldn't run the desktop app here to reproduce it with two windows. Typecheck and bun test in packages/desktop pass (130 pass, 1 skip).

Public API: unchanged (desktop main-process internals only).

No blocking concerns.

Permission handlers live on the shared session, so registering one per window replaced the previous handler and only the newest window passed the webContents id check. Clipboard writes from older windows rejected with NotAllowedError.

Keep the live webContents ids in one set and register the handlers once per session.
@SomaRe
SomaRe force-pushed the desktop-clipboard-permissions branch from 3fa6082 to 6d5b6f7 Compare October 20, 2026 19:48

This branch has not been deployed

No deployments
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.

desktop: per-window permission handler on a shared Electron session gets overwritten

1 participant