Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Option to allow access to clipboard without user interaction #1561

Closed
ecxs-daedalus opened this issue Jan 3, 2025 · 5 comments
Closed
Labels

Comments

@ecxs-daedalus
Copy link

ecxs-daedalus commented Jan 3, 2025

Specification

  • pywebview version: 5.3.2
  • operating system: MacOS & Windows
  • web renderer: Edge, Cocoa

Description

I try to enable access to the clipboard for an App and always run into the browser saveguards to not give the browser unfetted access to the clipboard. For Webapplications this makes sense. In my use case I just wanto to use the renderer to have a plattform independent GUI and don't load further content.

Would it be possible to have an additional Option in the webview.settings like ALLOW_CLIPBOARD_READ ? Then the app could access the clipboard through the navigator.Clipboard API even without user interaction.

I testet some Options on the plattforms I have access to:

Windows / edgechromium.py

I added an Event callback

    def on_permission_requested(self, _, args):
        if (args.PermissionKind == args.PermissionKind.ClipboardRead):
            args.State = args.State.Allow

    def on_webview_ready(self, sender, args):
        ...

        sender.CoreWebView2.PermissionRequested += self.on_permission_requested

        ...

MacOS / cocoa.py

The trick seems to be to set javaScriptCanAccessClipboard and domPasteAllowed to True:

config.preferences().setValue_forKey_(True, 'javaScriptCanAccessClipboard')
config.preferences().setValue_forKey_(True, 'DOMPasteAllowed')

In both cases it also eliminates the strange browser dopdown on paste (especialy irritating on MacOS)

Unfortunately I don't have a Linux/GTK test environment at the moment.

Practicalities

  • YES I am willing to work on this issue myself.
@ecxs-daedalus
Copy link
Author

pywebview.zip

@ecxs-daedalus
Copy link
Author

Copy link

github-actions bot commented Feb 6, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Feb 6, 2025
@r0x0r
Copy link
Owner

r0x0r commented Feb 6, 2025

Sorry for the late response.
Yeah this sounds like a good idea and could be enabled by default, ie ALLOW_CLIPBOARD_READ would be True by default.

Copy link

The message to post on the issue when closing it. If none provided, will not comment when closing an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants