0

I am trying to build a chrome extension which can record the current tab using chrome.desktopCapture.chooseDesktopMedia and stream the recording to the default_popup file.

Currently I am getting the stream's object url in a content script, passing it to the background script to do some checks and then pass it again to popup.js which is the javascript file for my pop up. the stream works and displays as a video when played on the page's DOM and the object passing is no problem either.

but it seems that the objectURL cannot access the video from the popup! is there any way around this?

This is the error I got when inspecting the pop up's console:

blob:https%3A//developer.chrome.com/5363c96d-69ff-4e91-8d06-48f1648ad0e4 Failed to load resource: the server responded with a status of 404 (Not Found)

4

2 回答 2

1

我刚刚发现如何做到这一点。

为了在 chrome 扩展中跨脚本和选项卡传输 blob url,您必须首先发送一个 xmlhttp 请求以从在不同脚本上创建的原始 blob url 中获取 blob。然后从当前页面上的该 blob 重新创建 blob url。

例如

//originalURL is the bloburl from your content script
//in your popup script, call this
var request=new XMLHttpRequest();
request.open('GET', originalURL);
request.responseType='blob';
request.send();
request.onload=function(){
var newURL=URL.createObjectURL(request.response);
}
//newURL is the bloburl which can not be used on your popup script, you can set it as the soure of a video etc...

我希望这对某人有帮助!

于 2015-03-20T10:59:44.173 回答
0

感谢@jasonY 提供有效的解决方案。在我的情况下,我需要将 ObjectURL 从后台脚本发送到内容脚本。

async function reissueObjectURL (url) {
    return new Promise((resolve, reject) => {
        var request = new XMLHttpRequest();
        request.open('GET', url);
        request.responseType = 'blob';
        request.onload = () => {
            resolve(URL.createObjectURL(request.response));
            URL.revokeObjectURL(url);
        };
        request.send();
    });
}
于 2017-06-30T13:02:07.017 回答