From b4ab807ef003a42d7677a78cd658b3f7b0f35d71 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 23 Sep 2022 21:06:41 +0200 Subject: [PATCH] Open Render in new Tab with timeout (to resolve issue with Safari) --- app/assets/javascripts/editor/submissions.js | 26 +++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/editor/submissions.js b/app/assets/javascripts/editor/submissions.js index 928c091b..7c580131 100644 --- a/app/assets/javascripts/editor/submissions.js +++ b/app/assets/javascripts/editor/submissions.js @@ -139,17 +139,21 @@ CodeOceanEditorSubmissions = { const active_file = CodeOceanEditor.active_file.filename.replace(/#$/,''); // remove # if it is the last character, this is not part of the filename and just an anchor const desired_file = response.render_url.filter(hash => hash.filepath === active_file); const url = desired_file[0].url; - var pop_up_window = window.open(url, '_blank'); - if (pop_up_window) { - pop_up_window.onerror = function (message) { - this.clearOutput(); - this.printOutput({ - stderr: message - }, true, 0); - this.sendError(message, response.id); - this.showOutputBar(); - }; - } + // Allow to open the new tab even in Safari. + // See: https://stackoverflow.com/a/70463940 + setTimeout(() => { + var pop_up_window = window.open(url, '_blank'); + if (pop_up_window) { + pop_up_window.onerror = function (message) { + this.clearOutput(); + this.printOutput({ + stderr: message + }, true, 0); + this.sendError(message, response.id); + this.showOutputBar(); + }; + } + }) }); } },