【问题标题】:Chrome extension - content script - to get innerText of current tab - not workingChrome 扩展 - 内容脚本 - 获取当前选项卡的内部文本 - 不起作用
【发布时间】:2013-03-28 05:19:32
【问题描述】:

我正在尝试在 chrome 扩展中获取当前打开的标签的 innerText

这是我的 ma​​nifest.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


【解决方案1】:

在我的浏览器上运行良好

重新加载扩展。

如果还是不行, 退出 Google Chrome 并重新登录。

【讨论】:

  • 感谢重新加载扩展并重新启动 chrome 工作。奇怪。
【解决方案2】:

它适用于我的 chrome 浏览器。

打开网址chrome://extensions/,加载插件目录。 并确保它正确加载,并将其标记为启用。

【讨论】:

  • 感谢您的回复,我朋友的浏览器也可以,但我的浏览器不行!!!你知道为什么吗?
猜你喜欢
  • 1970-01-01
  • 2016-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多