javascript - Get current URL with Chrome Extension - Stack Overflow

I'm trying to write a Chrome extension that will take the URL of the page the user is on and send

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745378373a4625107.html

相关推荐

  • javascript - Get current URL with Chrome Extension - Stack Overflow

    I'm trying to write a Chrome extension that will take the URL of the page the user is on and send

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信