Save pdf in Safari browser

I’m using a Mapbox map on my website, and I’m trying to take a screenshot of this map using HTML2Canvas and JSPDF, then insert it into a PDF. It works in Chrome but not in Safari. I am getting below errors. Any ideas on how to fix this? Thanks in advance.

...
    doc.save("" + REPORT + "_" + formattedDateTime + ".pdf");

    function convertToBase64(width, height) {
        html2canvas(document.getElementById("map"), {
          width: width,
          height: height,
          useCORS: true,
          allowTaint: true,
        })
          .then((canvas) => { var maxWidth = 525;
            var maxHeight = 320;
              var imgWidth = width;
              var imgHeight = height;
    
              if (imgWidth > maxWidth) {
                imgHeight *= maxWidth / imgWidth;
                imgWidth = maxWidth;
              }
              if (imgHeight > maxHeight) {
                imgWidth *= maxHeight / imgHeight;
                imgHeight = maxHeight;
              }
            imageBase64 = canvas.toDataURL("image/jpeg");console.log(width, height, "width height");
            getBase64FromUrl(imageBase64).then(
              
              doc.addImage(imageBase64, "JPEG", 40, 150, imgWidth, imgHeight)
            );
          })
          .catch((error) => {
            console.error("Hata:", error);
            return error;
          });
      }
    
      
      html2canvas(document.querySelector("#map"),{allowTaint:true,useCORS:true}).then(function (canvas) {
        convertToBase64(window.screen.width, window.screen.height);
      });

TypeError: null is not an object (evaluating'(document.body||document.getElementsByTagName(“head”)[0]).lastChild.src’)
SecurityError: The operation is insecure.