最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get current URL with Chrome Extension - Stack Overflow

programmeradmin1浏览0评论

I'm trying to write a Chrome extension that will take the URL of the page the user is on and send it to a server for a response back.

So far I have been trying to use chrome.tabs.getCurrent(), but I get uncaught TypeError on the getCurrent object.

Is there an easy way for doing this?

I'm trying to write a Chrome extension that will take the URL of the page the user is on and send it to a server for a response back.

So far I have been trying to use chrome.tabs.getCurrent(), but I get uncaught TypeError on the getCurrent object.

Is there an easy way for doing this?

Share Improve this question edited May 1, 2012 at 17:55 Patrick McElhaney 59.4k41 gold badges137 silver badges170 bronze badges asked Aug 7, 2010 at 10:30 HatchiNZHatchiNZ 431 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Any reason why you don't want to use getSelected()?

chrome.tabs.getSelected(windowId, function(tab) {
    alert("current:"+tab.url);
});

getSelected is deprecated. The preferred way to access the current tab is:

    chrome.tabs.query({active: true}, function(tab) {
        // Do stuff here
    }

You are getting the error because getCurrent returns the tab the script is running on, not the tab that is currently selected.

You should probably be using getSelected as noted by serg

发布评论

评论列表(0)

  1. 暂无评论