【发布时间】:2013-03-28 05:19:32
【问题描述】:
我正在尝试在 chrome 扩展中获取当前打开的标签的 innerText。
这是我的 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。
谢谢!
【问题讨论】:
标签: javascript jquery json google-chrome google-chrome-extension