How to use CEF (Chromium Embedded Framework) in Python 3.12.0?

50 Views Asked by At

How to use CEF in Python 3.12.0? Because when I try to use CEF in Python, it tells me that the version is not supported. Is there any version of CEF for Python 3.12.0 or any equivalent?

Versions:

Python: v3.12.0, VueJS: v3.4.15

My Code:

import sys
from cefpython3 import cefpython as cef


VUE_APP_PATH = "app"
INDEX_HTML_FILE = VUE_APP_PATH + "/index.html"

settings = {
    "context_menu": {"enabled": False},
    "browser_subprocess_path": "%s/%s" % (cef.GetModuleDirectory(), "subprocess"),
    "auto_zooming": "system",
    "remote_debugging_port": 0,
}

def initialize_cef():
    sys.excepthook = cef.ExceptHook
    cef.Initialize(settings=settings)
    cef.MessageLoop()

def run_vue_app():
    browser = cef.CreateBrowserSync(url=INDEX_HTML_FILE, window_title="Vue App in CEF")
    browser.SetClientHandler(LoadHandler())
    browser.SetClientHandler(RequestHandler())
    cef.MessageLoop()
    cef.Shutdown()

class LoadHandler(object):
    def OnLoadError(self, browser, frame, errorCode, errorText, failedUrl):
        print("Error: {0}, {1}, {2}, {3}".format(errorCode, errorText, failedUrl, frame.GetUrl()))

class RequestHandler(object):
    def OnBeforeBrowse(self, browser, frame, request, is_redirect):
        url = request.GetUrl()
        if url.startswith("http://") or url.startswith("https://"):
            cef.QuitMessageLoop()
            cef.Shutdown()
            return False
        return True

if __name__ == "__main__":
    initialize_cef()
    run_vue_app()
0

There are 0 best solutions below