Skip to content

Tutorial example: JavaScript bindings do not work and OnAfterCreated behavior differs from v66 #707

Open

Description

@cztomczak

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!

Activity

  1. linesight commented on Oct 24, 2026

    @linesight
    Contributor

    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

  2. cztomczak commented on Oct 24, 2026

    @cztomczak
    OwnerAuthor

    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.

    tutorial.patch

  3. cztomczak commented on Oct 24, 2026

    @cztomczak
    OwnerAuthor

    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.

  4. linesight commented on Oct 24, 2026

    @linesight
    Contributor

    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 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.

  5. cztomczak commented on Oct 24, 2026

    @cztomczak
    OwnerAuthor

    Looks good 👍 Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions