So, To download images/pdf that have blob: url in wkwebview, i injected javascript to my code.Here's the javaScript:
function(url) {
function blobToBase64String(blob, callback) {
var reader = new FileReader();
reader.onloadend = function() {
callback(this.result.split(",")[1]);
};
reader.readAsDataURL(blob);
}
if (url.startsWith("blob:")) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "blob";
xhr.onload = function() {
if (this.status !== 200) {
return;
}
var blob = this.response;
blobToBase64String(blob, function(base64String) {
webkit.messageHandlers.downloadManager.postMessage({
url: url,
mimeType: blob.type,
size: blob.size,
base64String: base64String
});
});
};
xhr.send();
return;
}
var link = document.createElement("a");
link.href = url;
link.dispatchEvent(new MouseEvent("click"));}
This is the error i m getting: XMLHttpRequest cannot load blob:https://url due to access control checks. Is there any way to allow request in wkwebview. I m not sure, where to head forward! Is there any preferences in wkwebview, that needs to be enabled?