Wednesday, 6 February 2013

Chrome extensions don't run on first use

Okay, so I'm having this problem with my chrome extensions. The user downloads and installs an extension, clicks on the icon and boom, nothing happens! The reason being, page loaded before your extension was installed don't contain the content scripts.

As yet, I haven't found a work around but, at least, using the following you can send an alert to the page and tell the user whats happening...
/* in the background.js */

chrome.browserAction.onClicked.addListener(function(tab){ 
    linkAudit.log('alert if not loaded'); 
    chrome.tabs.executeScript(tab.id, {
     code:'if(!window.linkAudit){alert("Please reload the page to run Link Audit")}'
    }) 
});
Investigate the Link Audit extension.

No comments:

Post a Comment

 

Note: the opinions on this page don't represent that of my employer in anyway. And, actually only vaguely represent my opinions on the date of publication. (Unlike Ms T, I am very much for turning)