简体   繁体   中英

modify google chrome extension to remove tab

I am trying to modify an existing extension (readability) for Chrome. Right now when you save a page with readability it does not close the tab afterwards.

The code in the extension calls a script hosted on their server:

(function(){
    rdb.chrome.inject_page_script('/bookmarklet/save.js');
 }());

I changed the code to look like this:

(function(){
    rdb.chrome.inject_page_script('/bookmarklet/save.js');
    chrome.tabs.getSelected( null, function(tab) 
        { chrome.tabs.remove(tab.id);   return true; }); 
 }());

But it doesn't close the tab or use their function properly. I tried my close tab code alone in the function without their call and it didn't close the tab.

Is there a way to modify their call to close the tab after it does their script to bookmark the page?

I wouldn't use chrom chrome.tabs.getSelected anymore as it has recently been deprecated. It's recommend that you use chrome.tabs.query instead. However, it's also worth mentioning that both of these methods require the tabs permission .

Without looking at the readability extension myself it's hard to determine why your code wasn't being called but I suggest you add debug (eg console.log('foo') ) statements to the code in order to determine why that code isn't being reached.

Finally, ensure you are following thecorrect debugging/development procedures so that you can test your changes easier.

Try:

chrome.tabs.getCurrent(function(tab) {
    chrome.tabs.remove(tab.id, function(){});
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM