Exemple de capture d'écran avec JavaScript et html2canvas

<!DOCTYPE html>
<html lang="fr">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js" integrity="sha512-BNaRQnYJYiPSqHHDb58B0yaPfCu+Wgds8Gp/gU33kqBtgNS4tSPHuGibyoeqMV/TJlSKda6FXzoEyYGjTe+vXA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

</head>

<body>
    <textarea id="textarea" style="width:400px; height:200px;"></textarea>
    <br>
    <button onclick="screenshot()">Prendre une capture d'écran</button>
    <br>
    <p>Résultat :</p>
    <img id="screenshot" src="" alt="résultat capture d'écran">
    <script>
        const screenshotTarget = document.getElementById("textarea");
        const screenshotImg = document.getElementById("screenshot");

        function screenshot() {
            html2canvas(screenshotTarget).then((canvas) => {
                base64image = canvas.toDataURL("image/png");
                screenshotImg.src = base64image;
            });
        }
    </script>
</body>

</html>

Commentaires