diff --git a/share/jupyter/voila/templates/base/static/main.js b/share/jupyter/voila/templates/base/static/main.js index d08be7435..324e6023f 100644 --- a/share/jupyter/voila/templates/base/static/main.js +++ b/share/jupyter/voila/templates/base/static/main.js @@ -50,8 +50,13 @@ require([window.voila_js_url || 'static/voila'], function(voila) { async function init() { // it seems if we attach this to early, it will not be called + const matches = document.cookie.match('\\b_xsrf=([^;]*)\\b'); + const xsrfToken = (matches && matches[1]) || ''; window.addEventListener('beforeunload', function (e) { - kernel.shutdown(); + const xhttp = new XMLHttpRequest(); + xhttp.open("DELETE", `/api/kernels/${kernel.id}`, false); + xhttp.setRequestHeader('X-XSRFToken', xsrfToken); + xhttp.send(); kernel.dispose(); }); await widgetManager.build_widgets();