开发者

Can an extension detect Google Chrome's home page?

Is there a way to detect Google Chrome's home page via the chro开发者_高级运维me.* extension API, or any other way? Thanks!


There is no API call for this. The closest I could get was to run chrome.tabs.getAllInWindow in the beginning of a background page and then analyze returned tabs.

chrome.tabs.getAllInWindow(null, function(tabs) {
    if(tabs.length == 1 && tabs[0].status == "loading") {
        console.log("possible home page:", tabs[0].url);
    }
});

This would work most of the times, but if your extension will be enabled when current window happens to have 1 tab which is currently loading - it would return wrong url. So you need to implement check to at least not run this code during first extension installation (by using some localStorage flag).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜