Chrome extensions and blobs



我有一个chrome扩展,通过套接字,得到发送的信息,它应该显示为通知。

到目前为止,在一个简单的场景中,我能够使用我自己的扩展中的图标作为iconUrl来显示通知。

然而,如果我使用通过套接字发送的图像,什么也不会发生。没有错误信息,什么都没有。

以下是相关代码…

chrome扩展:

//DISPLAYS NOTIFICATION
function notify(notification){
    //DEBUG STATEMENTS
    console.log("notification title: " + notification["title"]);
    var arrayBuff = notification["icon"];
    intArray = new Uint8Array(arrayBuff);
    blob = new Blob(intArray, {type: 'image/png'});
    var opt = {
      type: "basic",
      title: "Some Title",
      message: "Some Message",
//          iconUrl: window.URL.createObjectURL(blob) <-- NOTHING HAPPENS IF I USE THIS...
      iconUrl: "../img/icon48.png"
    }
    chrome.notifications.create("someid", opt, function(id){
            console.log("created notification: " + id); <-- Prints regarless of which iconUrl line I use in opt.
    });
}

仅供参考,这是我如何通过socket从我的node.js服务器发送通知对象:

function send_notification_to_socket(user, notification, target){
    fs.readFile(notification.iconpath, function(err, buf){
            if(socketstore.get_socket_by_id(user)){
                    socket = socketstore.get_socket_by_id(user);
                    notification["icon"] = buf;
                    socket.emit('notification', notification);
            }else{
                    console.log("No socket for user " + user);
            }
    });
}
编辑:

如果我查看console.error(chrome.runtime.lastError)的输出,我得到以下输出:

chrome.runtime.lastError: [object Object] background.js:286
(anonymous function) background.js:286
(anonymous function) extensions::notifications:114
run extensions::lastError:97
(anonymous function) extensions::notifications:105
imageUtil.loadAllImages.oncomplete extensions::notifications:79
(anonymous function) extensions::imageUtil:64 

点击imageUtil:14的代码,我看到:

callbacks.onerror({ problem: 'could_not_load', path: path }); 

发现错误。如下:

 blob = new Blob(intArray, {type: 'image/png'});

应该改成:

 blob = new Blob( [intArray] , {type: 'image/png'});

最新更新