Google chrome extension Chrome扩展和blob
我有一个chrome扩展,通过套接字接收发送的信息,它应该显示为通知 到目前为止,在一个简单的场景中,我能够使用我自己的扩展名中的图标作为iconUrl来显示通知 但是,如果我使用通过套接字发送的图像,则不会发生任何事情。没有错误消息,只是什么都没有 这是相关代码 chrome扩展:Google chrome extension Chrome扩展和blob,google-chrome-extension,Google Chrome Extension,我有一个chrome扩展,通过套接字接收发送的信息,它应该显示为通知 到目前为止,在一个简单的场景中,我能够使用我自己的扩展名中的图标作为iconUrl来显示通知 但是,如果我使用通过套接字发送的图像,则不会发生任何事情。没有错误消息,只是什么都没有 这是相关代码 chrome扩展: //DISPLAYS NOTIFICATION function notify(notification){ //DEBUG STATEMENTS console.log("notification
//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.
});
}
编辑:
如果查看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'});
如果您在
通知.create
回调中选中chrome.runtime.lastError
,是否有任何错误?错误,对不起,chrome.runtime.lastError.message
chrome.runtime.lastError:无法下载所有指定的图像。
我猜我制作blob的方式有问题。。。
blob = new Blob( [intArray] , {type: 'image/png'});