{"id":2193,"date":"2022-08-30T15:22:49","date_gmt":"2022-08-30T15:22:49","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/04\/chrome-app-wont-recognize-ids-that-work-fine-when-run-by-the-chrome-browser-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:22:49","modified_gmt":"2022-08-30T15:22:49","slug":"chrome-app-wont-recognize-ids-that-work-fine-when-run-by-the-chrome-browser-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/chrome-app-wont-recognize-ids-that-work-fine-when-run-by-the-chrome-browser-collection-of-common-programming-errors\/","title":{"rendered":"chrome-app won&#39;t recognize id&#39;s that work fine when run by the chrome browser-Collection of common programming errors"},"content":{"rendered":"<p>As lostsource mentioned, you&#8217;re probably accessing the wrong DOM&#8217;s document. You should think about the javascript in your app running in different global contexts, one for each page. There is (at a minimum) a page for the background page, and a page for each window.<\/p>\n<p>Each of these pages runs in its own global context. This means global variables like <code>document<\/code> and <code>window<\/code> are different.<\/p>\n<p>In the background page will be scripts which you load via the background manifest tag. When you open a window, it can also load its own script via script tags (make sure you do not use inline or block script tags, but use <code>script src=\"foo.js\"<\/code>. See http:\/\/developer.chrome.com\/apps\/contentSecurityPolicy.html).<\/p>\n<p>The code that runs in the callback to <code>chrome.app.window.create<\/code> runs in the background page&#8217;s context, so its <code>document<\/code> variable is for the background page&#8217;s DOM, which is usually empty. Instead you can make it refer to the window&#8217;s DOM using <code>win.contentWindow<\/code> as lostsource suggested, or add a page.js file with the script in it, and include it from the page via a <code>script src='page.js'<\/code> tag.<\/p>\n<p id=\"rop\"><small>Originally posted 2014-01-04 14:17:15. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>As lostsource mentioned, you&#8217;re probably accessing the wrong DOM&#8217;s document. You should think about the javascript in your app running in different global contexts, one for each page. There is (at a minimum) a page for the background page, and a page for each window. Each of these pages runs in its own global context. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2193","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2193"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2193\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}