From 120668fe5f4e6df892b697572aed16dabded9aa7 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 15 Oct 2024 17:15:27 +0200 Subject: [PATCH] Fix event listeners in dev mode --- webgpu.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webgpu.py b/webgpu.py index 2184f5e..9054278 100644 --- a/webgpu.py +++ b/webgpu.py @@ -100,6 +100,12 @@ async def main(canvas=None, shader_url="./shader.wgsl"): if canvas is None: canvas = document.getElementById("canvas") + # cloning and replacing the canvas removes all old event listeners + new_canvas = canvas.cloneNode(True) + canvas.parentNode.replaceChild(new_canvas, canvas) + canvas = new_canvas + del new_canvas + context = canvas.getContext("webgpu") context.configure( to_js(