r0x0r / pywebview

Build GUI for your Python program with JavaScript, HTML, and CSS
https://pywebview.flowrl.com
BSD 3-Clause "New" or "Revised" License
4.62k stars 537 forks source link

Ability to provide cookies for a webview #548

Closed danpalmer closed 4 years ago

danpalmer commented 4 years ago

Specification

Description

I'm building a prototype that uses both API calls and webviews. With authentication already handled outside of the webview, I'd like to be able to present an already-authenticated webview, but pre-loading cookies into it.

I've attempted to achieve this by evaluating a document.cookie = "..." script, but doing this before the URL is loaded does not work as the cookie domain does not match the origin (unset) at that point, and doing it after the URL is loaded may overlap with other cookies set in the unauthenticated page load and requires a window reload to have any effect.

Python provides a CookieJar class in http.cookiejar, I think this would be a nice data format to use in the API.

Practicalities

Yes, I can probably dedicate a few hours to this.

Probably not, but not certain yet.

r0x0r commented 4 years ago

I haven't explored cookie capabilities of web renderers, but my guess this could be done. This should be verified on a renderer basis though. Another possibility could be catch OnLoading navigation event and see if cookie can be set at that time. There has been interest in cookies like here https://github.com/r0x0r/pywebview/issues/531 If somebody wants to give introducing cookie support, help would be most welcome. I am ok with using http.cookiejar for cookie support.

github-actions[bot] commented 4 years ago

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[bot] commented 4 years ago

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