GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Bug]: webagg backend uses non-existent unload event · Issue #32393 · matplotlib/matplotlib

[Bug]: webagg backend uses non-existent unload event #32393

New issue
Copy link
New issue
Copy link
Open
Open
[Bug]: webagg backend uses non-existent unload event#32393
Copy link
Labels
GUI: webaggMaintenance

Description

@QuLogic
QuLogic
opened on Sep 25, 2026
Issue body actions

Bug summary

The webagg backend uses the onunload attribute of the image to close the websocket:

matplotlib/lib/matplotlib/backends/web_backend/js/mpl.js

Lines 83 to 85 in c1afaec

this.imageObj.onunload = function () {
fig.ws.close();
};

I cannot find any such event for Images, for its parent HTMLElement interface, or for its parent Element class, or even the Node ABC.

The docs for the unload event say that it is only on the global Window interface, with onunload on the body, frameset, and svg elements. It is also not recommended for use.

Code for reproduction

In the browser console:

var img = new Image();
img.on<TAB>

Actual outcome

There is no onunload in the autocomplete in the browser console.

Expected outcome

We should remove the onunload entirely, but I am uncertain as to whether we should be closing the websocket explicitly somewhere else.

Matplotlib Version

main

Matplotlib Backend

WebAgg

Installation

git checkout

Activity

  1. QuLogic
    added
    GUI: webagg
    Maintenance
    on Sep 25, 2026
  2. kokhlo commented on Sep 26, 2026

    @kokhlo
    kokhlo
    on Sep 26, 2026
    More actions

    Confirmed — onunload doesn't exist anywhere on the Image prototype chain (HTMLImageElement → HTMLElement → Element → Node), so the assignment at mpl.js:83-85 is a plain expando property that no browser has ever invoked. It's been dead code since it was introduced.

    Re: your uncertainty about closing the websocket explicitly — I don't think it's needed:

    • On page teardown the browser is required to close all open WebSocket connections, and the tornado side already handles that path: WebSocketHandler.on_close → FigureManagerWebAgg.remove_web_socket cleans up the server-side set.
    • For nbagg, the comm is closed by Jupyter's own comm lifecycle (comm.on_close in backend_nbagg.py), independent of this handler.

    So removing the handler outright is behavior-neutral (it never fired) and leaves the real cleanup paths untouched. I'll push a PR removing it shortly.

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

    GUI: webaggMaintenance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.