PDF Blob URL cannot be opened in iframe

pdf
bug
#1

When I request a PDF file through ajax into an “arraybuffer” response and create a blob of this response and a blob url and set the blob url as src for an iframe, then the pdf will be downloaded, instead of loaded into the iframe.

All other major browsers support this, but not brave. The code is very simple:

HTML:

<iframe id="my-frame"></iframe>

JavaScript: (In my code I check the contentType and use jQuery, but I am sure, you understand, what I mean)

let xhr = new XMLHttpRequest();
let iframe = document.getElementById('my-frame');

xhr.addEventListener("load", function(e) {
    if (this.status === 200) {
        let contentType = xhr.getResponseHeader('Content-Type');
        let blob = new Blob([this.response], { type: contentType });
        let blobUrl = window.URL.createObjectURL(blob);
        iframe.setAttribute('src', blobUrl);
    }
});

xhr.open('GET', src, true);
xhr.responseType = 'arraybuffer';
xhr.send();
0 Likes

#2

Hi @hazington,

Sorry that you’re experiencing this - I believe this is something we know about and have captured in a GitHub issue:

Thanks
Brian

1 Like

#3

Hi @clifton

Actually it’s not the same issue. I do not have problems with generated pdf files. My described problem is, that Brave cannot show content fetched over a blob url. It does not matter, if I open them in an iframe or in another tab. Instead of showing the pdf, Brave starts a file download.

In another words: for Brave blob is always a download!

Try it out. Fetch any file, create a blob url and then open this url in a frame or another window and you will see, that the pdf viewer won’t show up. Then try the same code in Chrome, Firefox, Opera, Edge, Safari and you will see, that those browsers will show the pdf file

Erik

0 Likes

closed #4

This topic was automatically closed after 30 days. New replies are no longer allowed.

0 Likes