Chrome扩展程序:错误处理响应:TypeError:无法读取未定义的属性“ url”

时间:2020-04-18 17:15:34

标签: javascript google-chrome-extension

我正在尝试获取当前标签页的网址。但是,我不断收到以下错误消息

Error handling response: TypeError: Cannot read property 'url' of undefined
at chrome-extension://haencpbflmfmghcblmadiohldhpidihf/background.js:3:25

manifest.json

{
"name": "x",
"version": "1.0",
"description": "y!",
    "permissions": [
        "tabs"
    ],
    "background": {
        "scripts": ["background.js"]
    },
"manifest_version": 2}

background.js

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

我尝试用activeTab替换选项卡权限,但是我仍然遇到相同的错误。

0 个答案:

没有答案