chrome.tabs returns undefined in content script

后端 未结 4 1520

chrome.tabs returns undefined despite the fact I set tabs in the permissions block.

\"permissions\": [
    \"tabs\",
    \"http://*/*\",
    \"h         


        
4条回答
  •  时光说笑
    2020-11-22 15:14

    https://developer.chrome.com/extensions/tabs#method-getSelected shows

    getSelected

    chrome.tabs.getSelected(integer windowId, function callback)
    Deprecated since Chrome 33. Please use tabs.query {active: true}.
    Gets the tab that is selected in the specified window.

    Maybe, you should use chrome.tabs.query in popup.js like this

    chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
        console.log(tabs[0].url);
    });
    

    , reload your extension and check the result in the inspect element of your extension.

    result image

    code image

    https://developer.chrome.com/extensions/tabs#type-Tab shows that The URL the tab is displaying. This property is only present if the extension's manifest includes the "tabs" permission.(Just for remind someone forgot. I was forgot it when I just test it.)

提交回复
热议问题