Safari: different bettween normal execution and debug mode

23 Views Asked by At

About the saving generated files on the client-side on Safari. I using the download attribute of for download the generated file

 var downloadLink = document.createElement('a');
 var dataType = 'data:application/csv;charset=utf-8';
 var filename = "test.csv";
 var csv = "content data ....";
 if (window.navigator.msSaveBlob) {
    window.navigator.msSaveOrOpenBlob(
        new Blob([csv], {type: "text/plain;charset=utf-8;"}), filename)
  } else {
    downloadLink.style.display = 'none';
    document.body.appendChild(downloadLink);
    downloadLink.href = dataType + ',' + encodeURIComponent(csv);
    downloadLink.download = filename;
    downloadLink.click();
    document.body.removeChild(downloadLink);
  }

This code cannot work in the normal execution of Safari (Version 13.0.5). But whenever "Inspect Element", open debug mode and push the breakpoint to the code -> This code can download the file.

0

There are 0 best solutions below