MS Edge backend for WebView

Edge Vippi2

Last night’s snapshot build added support for using Microsoft’s Edge browser (the new Chromium version) for the backend of wx.html2.WebView (on Windows only). It requires that a recent version of Edge is installed on the PC. I’ve had troubles getting it to work with the latest official release version, but it works very well with the Edge from the Beta Channel. (Currently version 86.0.622.43)

Take a look at the HTML2_Webview sample in the demo for how to check what backends are available. You can use similar code in your application to tell if the Edge backend can be loaded and used, or to fall back to the IE backend.

3 Likes

Great news that there is progress towards using the new(ish) browser.
I have an app that uses HTML2 for rendering SVG, but have have had to send files to Chrome for animation as using the current engine won’t do it in-app.

Hi @Robin

Will WebView2 become the default HTML viewer for wxPython on Windows? :crossed_fingers:
Is there any possibility of making Python functions callable from JavaScript? :sunglasses:

Thanks.

Since it depends on a newest Edge being installed then it probably won’t be the default, at least in the near term. You will be able to test if it’s available and either fall back to the Trident (IE) backend or inform the user that they need to install or upgrade Edge.

I don’t think there is currently any way to get callbacks from Javascript, but it would certainly be a cool feature if it was possible. You’ll need to talk with the wxWidgets devs to get more info about that. (wx-dev googlegroup or wxTrac)

Hi Robin, thanks for working on this. I’m looking forward to using Edge.

I’m having a little trouble though. I’ve installed Edge, and running your demo code below shows Edge is available for me. However, specifying the backend when I call webview.WebView.New(parent, backend=backend) results in blank views. Setting using backend=webview.WebViewBackendIE works just fine.

  • Windows7
  • Edge Version 87.0.664.30 (Official build) beta (64-bit)
  • wxPython4.1.1a1.dev5044+6959fd7f-cp37-cp37m-win32.whl
  • same issue on wxPython build from Oct 16 as well

Just curious if you have any suggestions? I couldn’t use your wx.html2 demo because of run installation issues.

# WebView Backends
backends = [
    (webview.WebViewBackendEdge, 'WebViewBackendEdge'),
    (webview.WebViewBackendIE, 'WebViewBackendIE'),
    (webview.WebViewBackendWebKit, 'WebViewBackendWebKit'),
    (webview.WebViewBackendDefault, 'WebViewBackendDefault'),
]
webview.WebView.MSWSetEmulationLevel(webview.WEBVIEWIE_EMU_IE11)
# Find an available backend
backend = None
for id, name in backends:
    available = webview.WebView.IsBackendAvailable(id)
    # print("Backend 'wx.html2.{}' availability: {}\n".format(name, available))
    if available and backend is None:
        backend = id
print("Using backend: '{}'\n".format(str(backend, 'ascii')))

I’ve noticed that the first time the demo sample is started that it can take several seconds (up to 15 seconds on my machine) for the web page to show up. Subsequent launches are much faster.

The run module used in the sample is part of the demo framework that facilitates running the samples individually. If you download the rest of the demo then you should be able to run that sample. You can get the demo from the same place you got the wxPython snapshot build.

The good news is that your demo works with Edge on my MSW7 setup. It also resolves my JS interactive issues with IE for the content I use.

The bad news is I have to figure out what else I need to change in my code other than backend. My code essentially is something like this:

# set_ie_emulation_level
web_layout = wx.html2.WebView.New(parent, backend=wx.html2.WebViewBackendEdge)
# put layout in a sizer, create layout, etc.
# create web content and save to web_file
web_layout.LoadURL(web_file)

Any thoughts why Edge and IE are behaving differently here? Setting backend=wx.html2.WebViewBackendIE works just fine with the same wxPython build.

Demo

(I’ll have to post my other two images separately)

Thanks Robin!

I’d post my IE image too, but I’m limited to 3 replies in this topic and only one image per post. Basically with IE, it just has the plot that was shown in the demo.

Edge

Can you create a small sample that demonstrates the problem? Also, you mentioned Win7. Can you also try it on Win10?

Just to close this loop in this thread. I created a second thread because I was a new user: MS Edge backend fails in Notebook (other than first page)

@DietmarSchwertberger suggested on demand web view creation, which resolves the issue.

I can only speculate about the minimum requirements to get Edge to work in the Notebook. But I could get the page of my choice to work at app launch if the page was selected before web view creation and remained selected though the rest of the app launch. The issue appears not to be related to time, but rather what resources are available to each Notebook page (must be different for a selected page, also before or after app launch completion).

Has anyone had any luck using Pyinstaller with an Edge web view?

If I run my app normally, everything works fine. But running from a Pyinstaller freeze, IsBackendAvailable is returning False for WebViewBackendEdge.

Edit: A friend of mine suggested this:

Edit 2: Looks like wxPython docs says I need to copy WebView2Loader.dll. Still working on where to place it: venv\Lib\site-packages\wx\WebView2Loader.dll

You may just need to tell PyInstaller to include the WebView2Loader.dll in the bundle. You should also check that the PATH manipulation in wx/html2.py is happening correctly in the bundled version of the application.

1 Like

I added this to my .spec:
binaries=[(r'.\venv\Lib\site-packages\wx\WebView2Loader.dll', r'.')]

IsBackendAvailable is now returning True for WebViewBackendEdge and the plots are working!

That’s good news, thanks for the update. :smiley:

Just curious, has anyone else noticed a webview with MS Edge backend can’t exist in an app’s top-level wxpanel? In addition to the delayed webview creation, I had to place it within a child panel or notebook.

If this is unexpected behavior, I’ll try to work up a simple example later this week.

When I did place the webview in the top-level frame or even panel in said frame, the whole app would lock up as soon as there was user interaction with the webview, interestingly, the webpage still loaded. No issues with IE Backend, or Webkit (when running on macOS) with the same code.

I still cannot track down the source of my bug, but I did verify MS Edge can live inside the top level wxpanel with a simple example.

I was able to reproduce similar (but not the same) behavior with a simple app when passing the wrong parent to my webview, but that caused issues regardless of webview backend.