“无法读取未定义的属性";在内容脚本中使用chrome.tabs或其他chrome API时 [英] "Cannot read property of undefined" when using chrome.tabs or other chrome API in content script

查看:58
本文介绍了“无法读取未定义的属性";在内容脚本中使用chrome.tabs或其他chrome API时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

chrome.tabs 返回未定义.

"permissions": [
    "tabs",
    "http://*/*",
    "https://*/*"
],
"content_scripts": [
    {
        "matches": [
            "http://*/*",
            "https://*/*"
        ],
        "js": [
            "js/myScript.js"
        ],
        "all_frames": true
    }
],

但是在myScript.js中,以下返回未定义.

But in myScript.js the following returns undefined.

chrome.tabs   

推荐答案

由于内容脚本有其自身的局限性,

As content script has its own limitations,

chrome.tabs 仅在后台脚本和弹出脚本中可用.

chrome.tabs is only available in background scripts and popup scripts.

如果您想使用 chrome.tabs ,然后将消息从content_script传递到后台脚本,然后使用 chrome.tabs 播放.

If you wanna to use chrome.tabs then pass message from content_script to background script and play with chrome.tabs.

这篇关于“无法读取未定义的属性";在内容脚本中使用chrome.tabs或其他chrome API时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆