Boscop / web-view

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

After running webview.set_html, external.invoke('arg') no longer works. #251

Open vthg2themax opened 3 years ago

vthg2themax commented 3 years ago

I am not sure if this is something that is supported, or if I am missing something, but after setting up an .invoke_handler(), and then running .set_html() from inside of it, I lose the ability for subsequent external.invoke calls to activate again.

neinteen commented 3 years ago

I just tested it and it works perfectly for me. Button 1 sends a command to the invoke handler that executes this code:

// build_html_dyn() just returns a string containing the html content.
// all of the javascript is inlined in the html
view.set_html(&crate::html::build_html_dyn()).unwrap();

Button 2 sends a different command that executes:

view.eval("test();").unwrap();

The test function just sets the innerText of button 1 to AAAA

window.test = () => {
  window.libraryButton.innerText = 'AAAA';
};

The function is binded to the window object, this is the only way I get evaluated functions to work at all. Maybe that works for you too.

3ae8fe9c2ea5592715a04473de36ad1c