Skip to content

1.5.1: intermittent ReferenceError: kaleido_scopes is not defined, because navigate() can return before the page has loaded #487

Open

Description

@sdhiscocks

Since upgrading to 1.5.1, plotly.io.write_image sometimes fails with:

kaleido._kaleido_tab._errors.JavascriptError: {'result': {'type': 'object', 'subtype': 'error',
'className': 'ReferenceError', 'description': 'ReferenceError: kaleido_scopes is not defined\n
at <anonymous>:1:26', ...}}

It's intermittent and depends on load. It shows up reliably when several exports run in parallel, as in a Sphinx-Gallery docs build with -j. 1.5.0 is not affected.

Issue seen localy, as well as on CircleCI builds:

  • Docker image cimg/python:3.14-browsers, medium resource class
  • Chrome installed with kaleido_get_chrome
  • Exports run during a Sphinx-Gallery build with sphinx -j 2
  • kaleido 1.5.1 fails, 1.5.0 passes

Activity

  1. ayjayt commented on Nov 13, 2026

    @ayjayt
    Collaborator

    Not the first time I've seen the error, so I know which system its probably in, I still can't do anything without logs.

    If you set the logging level to 1, you're going to get pages and pages and pages of logs.

    Please upload them as a file.

  2. sdhiscocks commented on Nov 13, 2026

    @sdhiscocks
    Author

    Thanks. Log at level 1 attached: kaleido-1.5.1-issue487-level1.log

    It covers a single export that failed: the first export in a fresh process, so it starts from browser launch.

    Produced with kaleido 1.5.1, choreographer 1.4.0, plotly 6.8.0, Python 3.14.0, and Chrome for Testing 142.0.7444.175 (from kaleido_get_chrome) on Linux. Four of these processes ran in parallel to create load:

    # repro_logs.py
    import logistro
    logistro.betterConfig()  # applies --logistro-level from the command line
    import os
    import plotly.graph_objects as go
    import plotly.io as pio
    
    run = os.environ["RUN"]
    for i in range(15):
        fig = go.Figure(go.Scatter(x=[1, 2], y=[3, i]))
        try:
            pio.write_image(fig, f"out_{run}_{i}.png")
        except Exception as e:
            print(f"FAIL on export {i}: {type(e).__name__}: {str(e)[:100]}", flush=True)
            break
    for p in 1 2 3 4; do RUN=$p python repro_logs.py --logistro-level 1 > run$p.log 2>&1 & done; wait

    All four failed in that run; this is the shortest log. Some line numbers to help navigate:

    1015: Page.enable
    1243: Page.navigate
    1284: Page.loadEventFired
    1352: Runtime.enable
    1429: Runtime.executionContextCreated
    1535: ReferenceError
    With 1.5.0, the same script doesn't fail.

    Drafted with help from Claude

  3. dennisjlee commented on Nov 13, 2026

    @dennisjlee
    Contributor

    This may have been caused by my PR #482. If so, apologies for the disruption! I was trying to fix a different race condition and may have caused another 🤦

  4. dennisjlee commented on Nov 13, 2026

    @dennisjlee
    Contributor

    I'm looking into how I can refine my previous fix to also defend against this case.

    This sequence of events is currently possible:

    1. Chrome’s initial new-tab page finishes loading.
    2. Its Page.loadEventFired satisfies Kaleido’s page_ready future.
    3. The rendering page gets a JavaScript context, but its scripts are still loading.
    4. navigate() returns early, and rendering fails with kaleido_scopes is not defined.
  5. Dev-iL commented on Nov 15, 2026

    @Dev-iL

    @dennisjlee would it make sense to yank 1.5.1 from pypi?

  6. dennisjlee commented on Nov 15, 2026

    @dennisjlee
    Contributor
  7. added a commit that references this issue on Nov 17, 2026
  8. dennisjlee commented on Nov 17, 2026

    @dennisjlee
    Contributor

    @camdecoster sorry for the trouble. Do you have time to review #488? I'm comfortable yanking 1.5.1 from Pypi in the meantime as well.

  9. camdecoster commented on Nov 17, 2026

    @camdecoster
    Contributor

    I'm looking at #488 right now. I don't think we need to yank since this issue doesn't manifest for everyone.

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

    P1needs immediate attentionbugsomething brokenneeds informationneeds more information to reproduce/solvesize: 1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions