Title: [Bug]: webagg backend uses non-existent unload event · Issue #32393 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: webagg backend uses non-existent unload event · Issue #32393 · matplotlib/matplotlib
X Title: [Bug]: webagg backend uses non-existent unload event · Issue #32393 · matplotlib/matplotlib
Description: 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(); }; ...
Open Graph Description: 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.onun...
X Description: 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.onun...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/32393
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: webagg backend uses non-existent unload event","articleBody":"### Bug summary\n\nThe webagg backend uses the `onunload` attribute of the image to close the websocket:\nhttps://github.com/matplotlib/matplotlib/blob/c1afaeca985ba7cfce0bfcef40a315f641855456/lib/matplotlib/backends/web_backend/js/mpl.js#L83-L85\n\nI cannot find any such event [for `Image`s](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement), for its [parent `HTMLElement` interface](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement), or for its [parent `Element` class](https://developer.mozilla.org/en-US/docs/Web/API/Element), or even the [`Node` ABC](https://developer.mozilla.org/en-US/docs/Web/API/Node).\n\nThe [docs for the `unload` event](https://developer.mozilla.org/en-US/docs/Web/API/Window/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.\n\n### Code for reproduction\n\nIn the browser console:\n```js\nvar img = new Image();\nimg.on\u003cTAB>\n```\n\n### Actual outcome\n\nThere is no `onunload` in the autocomplete in the browser console.\n\n### Expected outcome\n\nWe should remove the `onunload` entirely, but I am uncertain as to whether we should be closing the websocket explicitly somewhere else.\n\n### Matplotlib Version\n\nmain\n\n### Matplotlib Backend\n\nWebAgg\n\n### Installation\n\ngit checkout","author":{"url":"https://github.com/QuLogic","@type":"Person","name":"QuLogic"},"datePublished":"2026-09-25T04:46:39Z","url":"https://github.com/matplotlib/matplotlib/issues/32393"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:76a4619c-bbe7-287b-2869-fd57b655d0b1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CD5C:1FD7D4:D747AF:124564E:6B064EA5 |
| html-safe-nonce | 644128134fffb93eb738ce353574b7a579de8ed0cdc2429f2f4f4a52410ad99a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDVDOjFGRDdENDpENzQ3QUY6MTI0NTY0RTo2QjA2NEVBNSIsInZpc2l0b3JfaWQiOiIyNzc1Mzk0NTAyNTMyNTUwMzA5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f91dd0c8c34f385ecc8d56d9498c9dc871411e6e4768aaee5e2f71597851ba7b |
| hovercard-subject-tag | issue:5578268690 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/32393/issue_layout |
| twitter:image | https://opengraph.githubassets.com/102f13f468fefd95ded2c742b60173311494e04543b80389abdc30c66998a4a4/matplotlib/matplotlib/issues/32393 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/102f13f468fefd95ded2c742b60173311494e04543b80389abdc30c66998a4a4/matplotlib/matplotlib/issues/32393 |
| og:image:alt | 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.onun... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | QuLogic |
| hostname | github.com |
| expected-hostname | github.com |
| None | 772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f1f9a08f7c769a37f1dfc18ad43d463c222a7eea |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width