(function (open) { XMLHttpRequest.prototype.open = function (method, url, async, user, password) { this.addEventListener("load", function () { if (method === "PUT") { window.top.postMessage('jupytermessage', '*'); } }); open.call(this, method, url, async, user, password); }; })(XMLHttpRequest.prototype.open); (function (fetch) { window.fetch = function (url, options) { options = options || {} return fetch.apply(this, arguments).then(function (response) { try { if (options.method === "PUT" || (typeof url === "object" && url.method === "PUT")) { window.top.postMessage('jupytermessage', '*'); } } catch (error) { } return response; }); }; })(window.fetch); function saveCode() { var saveEvent = new KeyboardEvent('keydown', { key: 's', ctrlKey: true }); document.dispatchEvent(saveEvent); } function onReceiveMessage(e) { try { if (mes.type === 'saveCode') { saveCode() } } catch (error) { console.log('error:', error, e); } } (function () { setInterval(() => { saveCode() }, 5000) })(); window.addEventListener('message', onReceiveMessage);