Google chrome extension tabs.captureVisibleTab期间出错?在最近的Chrome更新之后
最近更新了chrome浏览器后,我使用的一个旧应用程序——书签管理器——停止了工作。更具体地说,获取缩略图截图的部分不起作用。 错误消息是 “制表期间出错。captureVisibleTab:无法访问url的内容。” "chrome://newtab/#20“。扩展清单必须请求对 访问此主机。“ 据我所知,tabs.captureVisibleTab不应该在上面工作 铬:// 标签等 以下是manifest.json权限:Google chrome extension tabs.captureVisibleTab期间出错?在最近的Chrome更新之后,google-chrome-extension,Google Chrome Extension,最近更新了chrome浏览器后,我使用的一个旧应用程序——书签管理器——停止了工作。更具体地说,获取缩略图截图的部分不起作用。 错误消息是 “制表期间出错。captureVisibleTab:无法访问url的内容。” "chrome://newtab/#20“。扩展清单必须请求对 访问此主机。“ 据我所知,tabs.captureVisibleTab不应该在上面工作 铬:// 标签等 以下是manifest.json权限: "permissions": [ "storage","bookmark
"permissions": [ "storage","bookmarks", "tabs", "history", "management", "unlimitedStorage", "chrome://favicon/", "http://*/*", "https://*/*","<all_urls>", "contextMenus", "notifications" ],
问题-大多数时候控制台都会触发此错误消息。每过一段时间,代码就会得到缩略图。据我所知,tabs.captureVisibleTab会在预定的时间之前触发
<> P>我会考虑有效的答案,无论是代码的直接修复(更好)还是一般的方向如何使它更可靠。
我的系统-Ubuntu 12.04,Chrome 24.0.1312.70
chrome.tabs.getSelected
不推荐使用chrome.tabs.query function getThumbnail(url, showInfoWarning) {
chrome.tabs.getSelected( null,function(tab) {
speeddial.storage.removeThumbnail(url);
localStorage['requestThumbnail'] = tab.id+'|||'+url;
openInCurrent(url);
});
}
function makeThumbnail(url,captureDelay) {
setTimeout(function()
{
chrome.tabs.captureVisibleTab(null,{format:'png'},function(dataurl)
{
var canvas = document.createElementNS( "http://www.w3.org/1999/xhtml", "html:canvas" );
var ctx = canvas.getContext('2d');
var img = document.createElement('img');
img.onload = function()
{
try
{
resized_width = 480;
quality = 0.72;
if (localStorage['options.thumbnailQuality']=='low') { resized_width = 360; quality = 0.75; }
if (localStorage['options.thumbnailQuality']=='high') { resized_width = 720; quality = 0.65; }
resized_height = Math.ceil((resized_width/img.width)*img.height);
canvas.width=resized_width
canvas.height=resized_height
ctx.drawImage(img,0,0,resized_width,resized_height);
localStorage.setItem(url, dataurl);
// SPEED DIAL DB
// var speeddialdb = {};
// speeddialdb.storage = {};
// speeddialdb.storage.db = null;
// var dbSize = 1 * 1024 * 1024; // 2MB
// speeddialdb.storage.db = null;
// speeddialdb.storage.db = openDatabase('bookmarks', '1.0', 'Speeddial2', dbSize);
// speeddialdb.storage.db.transaction(function(tx) {
// tx.executeSql('DELETE FROM thumbnails WHERE url = ?', [url],function(){
// tx.executeSql('INSERT INTO thumbnails (url, thumbnail) values (?, ?)', [url, canvas.toDataURL("image/jpeg",quality)], null ,function(tx, e){alert('Something unexpected happened: ' + e.message ) });
// });
// });
}
catch(e){console.log(e)}
}
img.src=dataurl;
});
}, captureDelay);
}
chrome.tabs.onUpdated.addListener(function(id,object,tab) {
if (tab.selected && tab.url) {
if (localStorage['requestThumbnail']!='' && localStorage['requestThumbnail']!="undefined" && typeof localStorage["requestThumbnail"]!='undefined') {
var requestThumbnail = localStorage['requestThumbnail'].split('|||');
if (requestThumbnail[0] == tab.id) {
if ( tab.status=="complete" ) {
if (tab.url.indexOf('mail.google.com')>-1 || tab.url.indexOf('twitter.com')>-1)
{
makeThumbnail(requestThumbnail[1],1000);
} else {
makeThumbnail(requestThumbnail[1],500);
}
localStorage['requestThumbnail']='';
}
requestThumbnail = null;
}
}
}
});