This code is used to download a pdf via blob. It works fine on every browser except Safari 12 for macOS and iOS. Even Safari 11 works. When I run the code the very first time, it works fine, but every time after that it gives me "WebKitBlobResource error 1"
function downloadFileFromBlob(fileBlob, fileName) {
if (/\bMSIE\b|\bTrident\b/.test($window.navigator.userAgent)) {
$window.navigator.msSaveOrOpenBlob(fileBlob, fileName);
} else {
var fileURL = $window.URL.createObjectURL(fileBlob);
createDownloadElementAndClick(fileURL, fileName);
}
}
function createDownloadElementAndClick(fileURL, fileName) {
var anchorElement = $window.document.createElement('a');
anchorElement.href = fileURL;
anchorElement.target = '_blank';
anchorElement.download = fileName;
var event = $window.document.createEvent("MouseEvents");
event.initEvent("click", true, false);
anchorElement.dispatchEvent(event);
}