You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tutorial example: JavaScript bindings do not work and OnAfterCreated behavior differs from v66 #707
In cefpython v147, tutorial.py displays an intercepted JavaScript error for python_property, even though the example sets it with bindings.SetProperty("python_property", "This property was set in Python").
The OnAfterCreated() message says “This will probably never display as DOM is not yet loaded”. In cefpython v66, this was expected to cause a JavaScript error, but in v147 the message appears without an error.
External.test_multiple_callbacks() also appears not to run: its Python print() does not appear in the terminal, and its js_print() message does not appear in the window.
Here are the logs from running tutorial.py:
[tutorial.py] CEF Python 147.0.dev1240+gfd40c964
[tutorial.py] Chromium 147.0.7727.118
[tutorial.py] CEF 147.0.10+gd58e84d+chromium-147.0.7727.118
[tutorial.py] Python 3.12.3 64bit
DevTools listening on ws://127.0.0.1:50384/devtools/browser/da6b5356-c7e8-493a-9a72-9527567e36cf
[55356:55356:1023/161527.756921:ERROR:ui/gl/gl_surface_presentation_helper.cc:260] GetVSyncParametersIfAvailable() failed for 1 times!
[55356:55356:1023/161534.280565:ERROR:ui/gl/gl_surface_presentation_helper.cc:260] GetVSyncParametersIfAvailable() failed for 2 times!
[55356:55356:1023/161613.070432:ERROR:ui/gl/gl_surface_presentation_helper.cc:260] GetVSyncParametersIfAvailable() failed for 3 times!
I’ve attached tutorial.patch with updates to tutorial.py:
Keep SetJavascriptBindings() after CreateBrowserSync(), consistent with the flow used in the other examples like ondomready.py snippet or unit test main_test.py.
Move the page-side test calls into run_html_tests() and invoke it from OnLoadingStateChange() instead of using window.onload.
Print messages to the terminal as well as display them in the GUI.
Add a few messages to show when the HTML script runs and when Python sets the bindings,
Fix thread issue. Replace threading.Timer with cef.PostDelayedTask(cef.TID_UI, ...) so browser.ExecuteFunction() runs on the CEF UI thread.
Rename the Javascript variable console to terminal to avoid shadowing window.console.
Informational note: CEF's CreateBrowserSync() supports passing extra_info to the renderer's OnBrowserCreated(). This could be used to provide initial JavaScript binding data before page <script> runs, provided OnBrowserCreated() occurs before OnContextCreated(). CEF documentation does not specify the order of these callbacks, so this would need to be verified. Just informational in case this is needed in the future.
terminal = document.getElementById("terminal") was still an implicit global, the same kind of problem as the old console one, so it's now var terminal = ...;.
Removed the leftover ; after run_html_tests() { ... }. It came from the old window.onload = function(){...}; assignment.
DisplayHandler.OnConsoleMessage still said "see comments in OnAfterCreated", but those comments were removed. It now points to the intentional error thrown by run_html_tests().
If this looks good, I'll cherry-pick it into PR #691.
Activity
linesight commentedon Oct 24, 2026
i have a tentative fix (both code and doc) at linesight@a7daa2d
can you help take a look? If you are ok with the fix, I would merge into #691 later
cztomczak commentedon Oct 24, 2026
I’ve attached
tutorial.patchwith updates totutorial.py:SetJavascriptBindings()afterCreateBrowserSync(), consistent with the flow used in the other examples likeondomready.pysnippet or unit testmain_test.py.run_html_tests()and invoke it fromOnLoadingStateChange()instead of usingwindow.onload.threading.Timerwithcef.PostDelayedTask(cef.TID_UI, ...)sobrowser.ExecuteFunction()runs on the CEF UI thread.consoletoterminalto avoid shadowingwindow.console.tutorial.patch
cztomczak commentedon Oct 24, 2026
Informational note: CEF's
CreateBrowserSync()supports passingextra_infoto the renderer'sOnBrowserCreated(). This could be used to provide initial JavaScript binding data before page<script>runs, providedOnBrowserCreated()occurs beforeOnContextCreated(). CEF documentation does not specify the order of these callbacks, so this would need to be verified. Just informational in case this is needed in the future.linesight commentedon Oct 24, 2026
I've applied your patch, with a few small fixes on top, as one commit on top of the PR head:
linesight@d38fc22
(compare view: linesight/cefpython@cefpython147-qt...issue707-fix)
Small fixes on top of your patch:
terminal = document.getElementById("terminal")was still an implicit global, the same kind of problem as the oldconsoleone, so it's nowvar terminal = ...;.;afterrun_html_tests() { ... }. It came from the oldwindow.onload = function(){...};assignment.DisplayHandler.OnConsoleMessagestill said "see comments in OnAfterCreated", but those comments were removed. It now points to the intentional error thrown byrun_html_tests().If this looks good, I'll cherry-pick it into PR #691.
cztomczak commentedon Oct 24, 2026
Looks good 👍 Thanks.
Fix JavaScript bindings in tutorial.py (Issue cztomczak#707): apply c…