Html2 chromium edge

Hello,

is the new Chromium based Edge html2 backend already available?
I tried using it, but the isBackendAvailable function just returned false, which implies that it is not available.

The new chromium basd edge browser is definitely installed on my system.
Do I have to manually activate the backend?

Works for me. But I’m having some issues:

@cutright Thanks for the answer, did you get it to work?
I have wxpython 4.1.1 installed, which should be new enough?
Also edge is version 87 on my computer.

Unfortunately, I also can not run the demo from the wxpython repository :confused:
I just get a module error for the “version” package.

Unfortunately, I don’t know much more than what is in the above two threads. Although, I just tested the code I posted in those threads, and Edge works for me in 4.1.1. Although, I still have the Notebook issue.

Are you running his demo application? Or trying to run a specific example by itself? I had no luck with the latter.

For clarity, this works for me in wxPython 4.1.1

import wx
import wx.html2 as webview
# from wx.lib.inspection import InspectionTool
# from wx.lib.agw.flatnotebook import FlatNotebook

NotebookClass = wx.Notebook
# NotebookClass = FlatNotebook
BACKEND = webview.WebViewBackendEdge


class DVHAMainFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)

        self.notebook_main_view = NotebookClass(self, wx.ID_ANY)
        self.tab_keys = ['Browser 1', 'Browser 2', 'Browser 3']

        print(webview.WebView.IsBackendAvailable(BACKEND))

        for key in self.tab_keys:
            func = self.make_web_page if key == self.tab_keys[0] else self.make_text_page
            func(key)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.notebook_main_view, 1, wx.EXPAND, 0)

        self.SetSizer(sizer)
        self.Layout()
        self.Center()

    def make_web_page(self, title):
        page = wx.Panel(self.notebook_main_view)
        plot = webview.WebView.New(page, backend=BACKEND)
        plot.LoadURL("http://www.google.com")
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(plot, 1, wx.EXPAND)
        page.SetSizer(sizer)
        self.notebook_main_view.AddPage(page, title)

    def make_text_page(self, title):
        page = wx.Panel(self.notebook_main_view)
        text = wx.StaticText(page, wx.ID_ANY, "This is just text for %s" % title)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(text, 1, wx.EXPAND)
        page.SetSizer(sizer)
        self.notebook_main_view.AddPage(page, title)


class MainApp(wx.App):
    def OnInit(self):
        self.SetAppName('DVH Analytics')
        self.frame = DVHAMainFrame(None, wx.ID_ANY, "", size=(800,600))
        self.SetTopWindow(self.frame)
        # InspectionTool().Show()
        self.frame.Show()
        return True


def start():
    app = MainApp()
    app.MainLoop()


if __name__ == "__main__":
    start()

Thats weird, @cutright.
The code you posted raises this error on my pc.

False
Traceback (most recent call last):
  File "c:/Users/xxxxx/Desktop/wx/browser.py", line 53, in OnInit
    self.frame = DVHAMainFrame(None, wx.ID_ANY, "", size=(800,600))
  File "c:/Users/xxxxx/Desktop/wx/browser.py", line 23, in __init__
    func(key)
  File "c:/Users/andil/Desktop/wx/browser.py", line 34, in make_web_page
    plot = webview.WebView.New(page, backend=BACKEND)    
wx._core.wxAssertionError: C++ assertion "m_handle == 0" 
failed at ..\..\src\common\dynlib.cpp(67) in wxDynamicLibrary::Load(): Library already loaded.
OnInit returned false, exiting...

The important thing shown in your output is that

     print(webview.WebView.IsBackendAvailable(BACKEND))

is printing False, so either .../site-packages/wx/WebView2Loader.dll is failing to be loaded dynamically by wxWidgets, or that DLL is failing to load the Chromium Edge components. So that is the thing to focus on for the moment. Unfortunately I currently don’t know a whole lot about the implementation details there, so I can just poke it with a stick and make educated guesses…

You may be able to get some clues by running the sample in the depends.exe tool and see if it’s able to find and load WebView2Loader.dll. If it can then check what DLLs it is trying to load and failing to. You can also check if there is another WebView2Loader.dll on your system installed as part of MS Office or something, and copy it into the wx package folder and see if it works or not.

Finally, what version of Windows are you running? 32-bit or 64-bit? Is it fully updated? Is Python 32-bit or 64-bit? What’s the exact version of Edge you have installed? Is it from the main channel or the beta channel?

What is the actual error?

Thanks for the reply.
The version error does not occur any more after I downloaded the demo and samples from the url you gave me.

I can run the demo file with the html2 example, but the Edge backend is also not available there.

.../site-packages/wx/WebView2Loader.dll is present.

I’m using windows 10 home version 20H2, 64 bit.
Edge 87.0.664.52 (Offizielles Build) (64-Bit)
Python 3.8.6 64bit

@Robin I was able to resolve the issue with the edge backend.
The documentation from microsoft says that the WebView2 Runtime has to be manually installed.
I installed from this source https://developer.microsoft.com/en-us/microsoft-edge/webview2/ (evergreen bootstrapper) and afterwards the html2 example in the demo.py works just fine with the edge backend.

Maybe this information should be added to the documentation?
Or didn’t you have to install the runtime manually @cutright?

Interesting. I was told that the only requirement is that Edge is installed (and building with the API, and distributing the WebView2Loader.dll)

Maybe the runtime is not installed with Edge on Windows Home? Anyway, you’re right, the docs should include at least something about trying the runtime installer if things don’t work.

Thanks for finding the cause!

I honestly can’t remember, but I’m fairly certain I only installed the Edge Beta (which maybe includes it?).

I’m using Windows 10 Professional 64 bit.
The default Edge, which is Chromium, did not work with WebViewBackendEdge.
So I installed the Beta yesterday and it worked.

Standard: Version 87.0.664.57 (Offizielles Build) (64-Bit)
Beta: Version 88.0.705.18 (Offizielles Build) beta (64-Bit)

1 Like

Does this mean that end-users need to install edge too?

I believe so, yes. My application uses wxpython 4.1.1 and my users need to separately install MS Edge Beta (or default to IE backend). I’ve not come across a way to embed MS Edge with a wxPython app.

Thanks for answering, @cutright .

I’ve not come across a way to embed MS Edge with a wxPython app.

That’s quite unfortunate. :frowning:

You’ll want to double-check to be sure, but I believe it is allowed to include installing the WebView2 runtime as part of your installation process, and I think that is enough to allow the edge backend for wx.html2 to function. I’ve only tested it on a system that had Edge installed and then uninstalled, so there may have been something left-over on the system that didn’t get uninstalled.