""" Communicate between Python and Javascript asynchronously using inter-process messaging with the use of Javascript Bindings. """ from cefpython3 import cefpython as cef g_htmlcode = """

Javascript Bindings

""" def main(): cef.Initialize() browser = cef.CreateBrowserSync(url=cef.GetDataUrl(g_htmlcode), window_title="Javascript Bindings") browser.SetClientHandler(LoadHandler()) bindings = cef.JavascriptBindings() bindings.SetFunction("py_function", py_function) bindings.SetFunction("py_callback", py_callback) browser.SetJavascriptBindings(bindings) cef.MessageLoop() del browser cef.Shutdown() def py_function(value, js_callback): print("Value sent from Javascript: "+value) js_callback.Call("I am a Python string #2", py_callback) def py_callback(value): print("Value sent from Javascript: "+value) class LoadHandler(object): def OnLoadEnd(self, browser, **_): browser.ExecuteFunction("js_function", "I am a Python string #1") if __name__ == '__main__': main()