SteveSandersonMS / WebWindow

.NET Core library to open native OS windows containing web UI on Windows, Mac, and Linux. Experimental.
Apache License 2.0
1.98k stars 215 forks source link

Add draft implementation of the WebView using EdgeHtml control #16

Open kant2002 opened 4 years ago

kant2002 commented 4 years ago

I would like to implement more modern c++/winrt, but that requires version C++ 17. And that seems to be another request.

SteveSandersonMS commented 4 years ago

This looks really interesting. Thanks for getting started on it!

I would like to implement more modern c++/winrt, but that requires version C++ 17

Please feel free to switch the project to C++17 in your PR if that helps with implementing this cleanly and doesn't have any other major drawbacks.

kant2002 commented 4 years ago

@SteveSandersonMS Thank for feedback. I will play with C++ 17. On closer investigation support for Edge seems to be impossible to implement fully. Would like to hear you opinion on what's very essential to support in the list of issues which I have.

Another issue which should be worked-out separately is handling errors. right now MessageBox is popping up if you do not have WebView (Chromium) installed. I would like to have exception to be produced by library and not message boxes. If you have something in your mind how to make that work except changing export declaration (returning int instead of void), let me know. This should be whole new issue, but I just want to capture your attention while you are here.

yuri-vin commented 4 years ago

Hello @kant2002 , thanks for your contribution. Did you make any progress on this lately? Is it correct that this implementation allows for running WebWindow in EdgeHTML engine (old Edge browser)? This seems like an interesting solution as a fallback scenario when the new Edge (Chromium) is not available on the user's system.

I didn't dig too deep into the details, but for me the HelloWorldApp shows an error message with 0x80004004 code right after the window is initialized.

kant2002 commented 4 years ago

@yuri-vin believe it is impossible properly implement WebWindows as it is in old Edge. Given that Steve explicitly express that any functionality added should still support whole scope of existing functionality, I cannot made it. One of the obvious roadblocks is injection of JS into EdgeHTML. I cannot find article how to do that. Without that, I doubt my work can be implemented practically.

If you know how to inject JS into running page in the EdgeHTML, please give me hint, and I can try to revive this branch

reflectronic commented 4 years ago

It should be possible using IWebViewControl.InvokeScriptAsync and IWebViewControl2.AddInitializeScript, no?

kant2002 commented 4 years ago

I can try again. Let me recall where I stuck.

kant2002 commented 4 years ago

@reflectronic do you now how I can implement custom scheme support?

kant2002 commented 4 years ago

@yuri-vin The error which you are seeing is from fact, that you load files from local file system. EdgeHTML cannot display data from local filesystem. At least I still do not found an way to make it load file:// protocol. There possible to embed simple HTTP server as part of WebWindow, but that's defeat whole thing to be minimalistic library.

@reflectronic Other thing which is missing is the add_WebMessageReceived handler which implemented in WebView2. I can implement receiving notification same way as Android Cordova implement that, having queue in the Browser and drain it periodically. But on the whole fallback seems to be unreliable and not worth pursuing as part of that library.

@SteveSandersonMS what's your position on having limited fallback functionality to EdgeHTML where unsupported scenarios will clearly throw and documented?

yuri-vin commented 4 years ago

The error which you are seeing is from fact, that you load files from local file system.

Thanks for the update, I'll check if loading resources from the web rather than the local file system solves the error. In my particular case this should not be a problem since I'm already running a local web server to run the aspnet core app, but in general yes, this seems like a big limitation...

reflectronic commented 4 years ago

I played around a lot with WebView. The functionality seems to be a little messed up, probably since they have "deprecated" it in favor of WebView2. I couldn't get things like AddInitializeScript to work properly; I'll try and investigate the Microsoft Community Toolkit's bindings and see why that might not be working for me.

If nothing else, I did figure out how to get local web pages to render. There are still caveats; custom URIs do not really work, and I don't think it's possible to implement them properly. image

You can test it out on my fork at https://github.com/reflectronic/WebWindow/tree/edgehtml. I used a C++/WinRT implementation, separate from this PR's impl.

jspuij commented 4 years ago

I have a managed old Edge fallback implementation in https://github.com/jspuij/BlazorWebView. Somebody might be interested in backporting it.