Boscop / web-view

Rust bindings for webview, a tiny cross-platform library to render web-based GUIs for desktop applications
MIT License
1.93k stars 176 forks source link

Persistent cookies between sessions #213

Open MGlolenstine opened 4 years ago

MGlolenstine commented 4 years ago

How would one keep cookies between sessions?

EDIT: I can save them using the localStorage, but they won't get loaded at the next webpage load.

Blakeinstein commented 4 years ago

I am unsure as to what you mean by "won't get loaded at the next webpage load". Aren't files stored to localstorage consistent between sessions?

MGlolenstine commented 4 years ago

I am unsure as to what you mean by "won't get loaded at the next webpage load". Aren't files stored to localstorage consistent between sessions?

Correct... localStorage does persist, but I need to load cookies for the first website request and I can't access localStorage or cookies without JS, which is a problem, as I have to set cookies before first request, otherwise I just get blocked by "unauthorised".

Blakeinstein commented 4 years ago

You could build the webview first then use eval to execute the necessary javascript and then run the webview..

let mut webview = builder().......
                ...build().unwrap();

webview.eval(r#"
    your js code here
"#);

webview.run().unwrap(); ?
MGlolenstine commented 4 years ago

You could build the webview first then use exec to execute the necessary javascript and then run the webview..

let mut webview = builder().......
              ...build().unwrap();

webview.exec(r#"
  your js code here
"#);

webview.run().unwrap(); ?

I had no idea I was able to run JS without having to load a website first 😮. I'll try this out and will report back!

MGlolenstine commented 4 years ago

webview doesn't include exec function. The code is located after the .build().unwrap().

error[E0599]: no method named `exec` found for struct `web_view::WebView<'_, bool>` in the current scope
  --> src/main.rs:49:13
   |
49 |     webview.exec(r#"
   |             ^^^^ method not found in `web_view::WebView<'_, bool>`

.eval() on the other hand works!

Blakeinstein commented 4 years ago

Ah shoot my apologies, I got confused between exec and eval for a second since I was using qt recently... Anyways, Glad it works.

Blakeinstein commented 4 years ago

If you have no other issues, close the Issue btw!

MGlolenstine commented 4 years ago

If you have no other issues, close the Issue btw!

I haven't solved the cookies yet, I just managed to get the JS working before the WebView loads ;) I will close it once I have it working! :+1: I'm currently at work, so I'll try more stuff once I get home.

khinch commented 3 years ago

Has anyone come across a solution for this? I just did a quick test and localStorage doesn't seem to persist between runs.

It would be awesome if we could pass a path to the builder where the cookies can be found/stored. I realise that could be almost impossible if not implemented in the C library though.

im-n1 commented 3 years ago

This is quite a must-have feature and I will explain why.

With no persistent cookies support (or at least to have the ability to load cookies from file) you are pretty much doomed from all application behind login or from applications where you need some kind of personalization.

Blakeinstein commented 3 years ago

Please give tauri a shot https://github.com/tauri-apps/tauri

im-n1 commented 3 years ago

Tauri is a whole different level and tool. Also using another tool doesn't resolve this issue.