Note that there are some explanatory texts on larger screens.

plurals
  1. POFirefox not recognizing a defined object (Firefox Extension development)
    text
    copied!<p>I'm developing a Firefox extension (I'm a newbie to this, so please go easy), and I seem to be stuck with a very annoying problem that is hindering me from making any progress.</p> <p>I have three .js files: <code>main.js</code>, <code>hello.js</code>, <code>awesome.js</code> and one .xul file, <code>awesomeOverlay.xul</code>. The <code>main.js</code> goes something like this:</p> <pre class="lang-js prettyprint-override"><code>//main.js if(typeof(MyExtension) === "undefined") { var MyExtension = {}; } MyExtension.Main = { browser : null, init : function() { if("gBrowser" in window) { MyExtension.Main.browser = window.gBrowser; MyExtension.Main.browser.addEventListener("DOMContentLoaded", MyExtension.Main.onPageLoad, true); window.content.console.log("Yay, recognized the browser!"); }, onPageLoad : function(e) { var doc = e.originalTarget; var regex = /stackoverflow\.com/; if(regex.test(doc.location.href)) { window.content.console.log("Visiting stackoverflow!"); alert("Loaded stackoverflow!"); } e.originalTarget.defaultView.addEventListener("unload", function(e){MyExtension.Main.onPageUnload(e), true); }, onPageUnload : function(e) { var regex = /stackoverflow\.com/; var doc = e.originalTarget; if(regex.test(doc.location.href)) { alert("Found a solution to your problem, huh? Great!"); } } }; </code></pre> <p>In my other two .js files, I have objects like <code>MyExtension.Hello = {...}</code> and <code>MyExtension.Awesome = {...}</code>. The issue is, when I load stackoverflow.com, I do not get any alerts or logs in the console. I loaded up Scratchpad, changed the Environment context to "Browser", and verified if the objects I defined existed by <code>alert(typeof(MyExtension))</code>, and it returns "object" as expected. When I tried <code>alert(typeof(MyExtension.Main))</code>, I got "undefined". In fact, I get "undefined" for <code>alert(typeof(MyExtension.Main.*))</code>.</p> <p>When I tried checking the typeof of objects in the other two files (hello.js and awesome.js), they are correctly recognized (i.e., "function", "object" etc.). It seems like the main.js file is being ignored for some reason. This is how my .xul file is defined:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0"?&gt; &lt;?xml-stylesheet href="chrome://myextension/skin/myextension.css" type="text/css"?&gt; &lt;overlay id="AwesomeOverlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt; &lt;script type="application/x-javascript" src="chrome://myextension/content/jquery.min.js" /&gt; &lt;script type="application/x-javascript" src="chrome://myextension/content/main.js" /&gt; &lt;script type="application/x-javascript" src="chrome://myextension/content/hello.js" /&gt; &lt;script type="application/x-javascript" src="chrome://myextension/content/awesome.js" /&gt; &lt;statusbar id="status-bar"&gt; &lt;statusbarpanel id="myextensionAwesomeStatusBar" context="myextensionSB" class="shown" persist="class"&gt; &lt;hbox id="myextensionHbox" class="shown" persist="class"&gt; &lt;image id="awesomeIcon" tooltiptext="Awesome Extension \m/" class="shown" persist="class" /&gt; &lt;/hbox&gt; &lt;/statusbarpanel&gt; &lt;/statusbar&gt; &lt;/overlay&gt; </code></pre> <p>I've verified that the paths in the chrome.manifest are correct. This is driving me nuts, please help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload