Skip to content

Commit

Permalink
Merge pull request #96 from man-group/fix/stdout-copy
Browse files Browse the repository at this point in the history
Workaround for stdout copy in non-secure contexts
  • Loading branch information
jonbannister authored Jun 22, 2022
2 parents 221684e + 8e03eab commit 492e66e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion notebooker/web/static/notebooker/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,29 @@ function viewStdout(stdoutUrl) {
return true;
},
onApprove() {
navigator.clipboard.writeText(stdoutContent.textContent);
copy(stdoutContent.textContent)
return false;
},
}).modal('show');
}

function copy(text) {
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text);
} else {
// workaround for Chrome without https - create a hidden text area and copy from that
textArea = document.createElement("textarea");
textArea.value = text;

textArea.style.position = "absolute";
textArea.style.opacity = 0
document.body.appendChild(textArea);
textArea.focus();
textArea.select();

new Promise((res, rej) => {
document.execCommand('copy') ? res() : rej();
textArea.remove();
});
}
}

0 comments on commit 492e66e

Please sign in to comment.