1

I'm developing a chrome extension that will do something if it detects a specific object on the window object. For example in content.js I have

var el = document.getElementsByTagName("html");
console.log(el[0].ownerDocument.defaultView.someObj);

This logs undefined. If I run the same code within the browser console. I will see that someObj exist. I get the correct element with

var el = document.getElementsByTagName("html");

but it doesn't seem like I can get the correct window object. Any ideas?

my manifest looks like

{
  "manifest_version": 2,
  "name": "My Ext",
  "version": "0.1",
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "js": ["content.js"]
    }
  ],
  "browser_action": {
    "default_icon": "images/logo.svg"
  }
}
rross
  • 2,236
  • 11
  • 36
  • 41
  • JS of an extension does not run in the same "context" as the main web view. It's does not act like an iFrame. To access the current loaded web page dom you need to use a content script: https://developer.chrome.com/extensions/content_scripts – Sergiu Paraschiv Feb 13 '16 at 16:47
  • 1
    Note that `el[0].ownerDocument.defaultView.someObj` is an _extremely_ contrived way of saying `window.someObj`. – Xan Feb 13 '16 at 18:51
  • @SergiuParaschiv Nope, that's already from a content script. You need to inject code into the page itself to access it. – Xan Feb 13 '16 at 18:52

0 Answers0