我正在尝试innerText
在 chrome 扩展中获取当前打开的选项卡。
这是我的manifest.json:
{
"manifest_version": 2,
"name": "meow",
"description": "meow-meow-meow",
"version": "1.0",
"browser_action": {
"default_icon": "icon2.png",
"default_popup": "popup.html"
},
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["contentscript.js"]
}
],
"permissions": [
"http://*/*",
"https://*/*",
"contextMenus",
"tabs"
]
}
这是我的contentscript.js:
function getText(){
return document.body.innerText
}
console.log(getText());
但它没有在控制台上记录任何内容!我错过了什么?
编辑:有没有更好的方法从当前选项卡获取 HTML 内容?
更新编辑:
这在我朋友的 chrome 上运行良好,但在我的 chrome 上运行良好,两个 Chrome 版本都是 26。
谢谢!