Display current URL in a chrome extension

前端 未结 3 1319
一个人的身影
一个人的身影 2020-12-09 05:43

After doing some research, the code that I have come up with is this:

var outUrl;
// first get the windowid
chrome.windows.getCurrent(function(window) {
             


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 06:16

    Maybe this is what your looking for....

    chrome.tabs.query({'active': true, 'windowId': chrome.windows.WINDOW_ID_CURRENT},
       function(tabs){
          alert(tabs[0].url);
       }
    );
    

    And the tabs permission needs to be set in the manifest...

    manifest.json

    "permissions": [ 
      "tabs"
    ]
    

提交回复
热议问题