Reputation: 361
After recent update of chrome an old app - bookmark manager - I use, stopped working. To be more specific the part that takes the thumbnail screenshots is not working. The error message is
"Error during tabs.captureVisibleTab: Cannot access contents of url "chrome://newtab/#20". Extension manifest must request permission to access this host. "
As far as I get it, tabs.captureVisibleTab is not supposed to work on
chrome://
tabs, etc.
Here is the manifest.json permissions:
"permissions": [ "storage","bookmarks", "tabs", "history", "management", "unlimitedStorage", "chrome://favicon/", "http://*/*", "https://*/*","<all_urls>", "contextMenus", "notifications" ],
And here are the functions that trigger the thumbnail on page load
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;
}
}
}
});
The problem - most of the time the console will trigger this error message. Once in a blue moon the code will actually get the thumbnail. As far as I get it,tabs.captureVisibleTab triggers before it is intended to.
i will consider valid answer both direct fix of the code(better) or general direction how to make it more reliable.
My system - Ubuntu 12.04, Chrome 24.0.1312.70
Upvotes: 0
Views: 1524
Reputation: 18534
chrome.tabs.getSelected
is deprecated use chrome.tabs.query instead.chrome.tabs.captureVisibleTab(null
it defaults to current window
.Upvotes: 1