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

Open
ecxs-daedalus opened this issue Jan 3, 2025 · 2 comments

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

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

No branches or pull requests

1 participant