[英]modify google chrome extension to remove tab
I am trying to modify an existing extension (readability) for Chrome.我正在尝试修改 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.我不会再使用 chrom
chrome.tabs.getSelected
因为它最近已被弃用。 It's recommend that you use chrome.tabs.query instead.建议您改用chrome.tabs.query 。 However, it's also worth mentioning that both of these methods require the tabs permission .
但是,还值得一提的是,这两种方法都需要 tabs 权限。
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.如果不亲自查看可读性扩展,就很难确定为什么没有调用您的代码,但我建议您在代码中添加调试(例如
console.log('foo')
)语句以确定为什么该代码没有被调用达到。
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(){});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.