0
在Chrome最近更新之后,旧应用程序 - 书签管理器 - 我使用,停止工作。更具体地说,采用缩略图截图的部分不起作用。 错误消息是在tabs.captureVisibleTab期间出错?最近Chrome更新后
“tabs.captureVisibleTab过程中的错误:无法访问URL 的内容 ”铬:// NEWTAB /#20“。扩展清单必须请求允许 访问这台主机。”
据我得到它,tabs.captureVisibleTab不应该对
个铬工作://
标签等
这里是manifest.json的权限:
"permissions": [ "storage","bookmarks", "tabs", "history", "management", "unlimitedStorage", "chrome://favicon/", "http://*/*", "https://*/*","<all_urls>", "contextMenus", "notifications" ],
这里是触发缩略图在页面加载
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;
}
}
}
});
问题的功能 - 最控制台将触发此错误消息的时间。一旦进入蓝色月亮,代码将实际得到缩略图。据我所知,tabs.captureVisibleTab在触发之前触发。
我会考虑有效的答案,直接修正代码(更好)或一般方向如何使它更可靠。
我的系统 - 的Ubuntu 12.04,Chrome浏览器24.0.1312.70
我会尝试,并给予好评,如果这是导致问题的唯一的事情。我仍然必须传递正确的id与chrome.tabs.query或不是?在我看来,所有的功能停止时,我离开了应用程序页面... – deckoff 2013-02-21 10:45:59
@deckoff:是的... – Sudarshan 2013-02-21 10:47:02
谢谢你的帮助 - 这不工作的原因是非常不同的,但你不能有已知 - 代码在backgorund。 html,而不是background.js,并没有根据版本2清单要求进行声明 – deckoff 2013-02-21 19:44:52