在 Chrome 中打开 blob objectURL

2022-01-21 00:00:00 blob google-chrome base64 javascript

我想在 javascript 中使用 window.open(fileObjectURL) 在 chrome 浏览器(Chrome 56.0.2924.87、Ubuntu 14.04)的新选项卡中打开 PDF.我正在从 base64 编码数据创建 blob,并创建一个像这样的 objectURL:

I want to open a PDF in a new tab in chrome browser (Chrome 56.0.2924.87, Ubuntu 14.04) using window.open(fileObjectURL) in javascript. I am creating the blob from base64 encoded data and do create an objectURL like this:

const fileObjectURL = URL.createObjectURL(fileBlob); 

它在最新的 Firefox 浏览器中运行良好.但在 Chrome 中,我可以看到新标签页被打开但立即关闭.所以我在控制台等中没有任何错误.它现在在 Chrome 中工作的唯一方法是将 base64 数据直接提供给 window.open(fileBase64Data) 函数.但我不喜欢在 url 中设置完整的数据.

It works fine in latest Firefox browser. But in Chrome I can see that the new tab gets opened but then closed immediately. So I don't get any error in the console etc. The only way it works in Chrome now is to give the base64 data directly to the window.open(fileBase64Data) function. But I don't like the complete data being set in the url.

也许这是 Chrome 阻止打开 blob 的安全问题?

Maybe this is a safety issue with Chrome blocking opening of blobs?

推荐答案

原因可能是adblock扩展(我遇到了完全相同的问题).

The cause is probably adblock extension (I had exactly the same problem).

相关文章