Last active
October 27, 2023 15:34
-
-
Save phantomtnt/dd395d40fe3275198c013ea62a5658ae to your computer and use it in GitHub Desktop.
Revisions
-
phantomtnt revised this gist
Oct 27, 2023 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,12 @@ /* Source: https://hackernoon.com/how-to-take-screenshots-in-the-browser-using-javascript-l92k3xq7 It needs permission from uses to access display */ const capture = async () => { const canvas = document.createElement("canvas"); const context = canvas.getContext("2d"); -
phantomtnt created this gist
Oct 27, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ /* Source: https://hackernoon.com/how-to-take-screenshots-in-the-browser-using-javascript-l92k3xq7 It need permission from user */ const capture = async () => { const canvas = document.createElement("canvas"); const context = canvas.getContext("2d"); const video = document.createElement("video"); try { const captureStream = await navigator.mediaDevices.getDisplayMedia(); video.srcObject = captureStream; context.drawImage(video, 0, 0, window.width, window.height); const frame = canvas.toDataURL("image/png"); captureStream.getTracks().forEach(track => track.stop()); window.location.href = frame; } catch (err) { console.error("Error: " + err); } }; capture();