{"id":381,"date":"2009-05-02T18:19:04","date_gmt":"2009-05-02T23:19:04","guid":{"rendered":"http:\/\/mikeconley.ca\/blog\/?p=381"},"modified":"2023-12-20T16:25:21","modified_gmt":"2023-12-20T21:25:21","slug":"overriding-firefoxs-windowalert-part-2","status":"publish","type":"post","link":"https:\/\/mikeconley.ca\/blog\/2009\/05\/02\/overriding-firefoxs-windowalert-part-2\/","title":{"rendered":"Overriding Firefox\u2019s Window.Alert &#8211; Part 2"},"content":{"rendered":"<p>Ok, so there have been some developments.<\/p>\n<p>Before I go into this though, I just want to make it clear that I have <em>very little <\/em>knowledge or experience working with XUL, or writing Firefox extensions in general.\u00a0 I&#8217;ve dabbled, but I&#8217;m mostly ignorant.\u00a0 So all you Firefox aficionados out there&#8230;go easy on me.<\/p>\n<p>So, developments:<\/p>\n<p>Using <a href=\"http:\/\/ted.mielczarek.org\/code\/mozilla\/extensionwiz\/\">this site<\/a>, I created a skeleton for my extension, calling it &#8220;alertCheck&#8221;.<\/p>\n<p>And then I hit a brick wall right away, trying to find the right &#8220;alert&#8221; to override.<\/p>\n<p>Let me explain.\u00a0 Mozilla extension development is strange for me because of all of the various layers to Firefox, and the <em>distance<\/em> between the JavaScript in the extension, and any page that is loaded in the browser.\u00a0 It feels like a security layer &#8211; and it makes sense:\u00a0 you <em>really<\/em> don&#8217;t want the Javascript on a website to monkey around with the internals of your browser.<\/p>\n<p>Thankfully, <a href=\"http:\/\/forums.mozillazine.org\/viewtopic.php?f=19&amp;t=326355&amp;p=1791443\">this forum<\/a> and <a href=\"http:\/\/markmail.org\/message\/gsxdzrhddztbgtbc\">this forum<\/a> provided some help.<\/p>\n<p>Now, after the appcontent is loaded, I wait for the DOMContentLoaded event to fire, and then write my new alert function to here:<\/p>\n<pre>document.getElementById('content').contentWindow.wrappedJSObject.alert<\/pre>\n<p>The problem is, if I wait for the DOMContentLoaded event to fire, the alert override happens (obviously) <em>after <\/em>all of the DOM Content is loaded into the browser.\u00a0 This is only useful if the alert&#8217;s that we want to capture are fired using &lt;body onLoad&gt; or some other function that detects when the DOM has been loaded.\u00a0 It&#8217;s no good for inline Javascript alerts, since these commands are parsed and executed line by line as the HTML is processed.<\/p>\n<p>Phew.\u00a0 Big mouthful.<\/p>\n<p>So, where does that leave me?\u00a0 Well, I was just hanging out in irc.mozilla.net in the #extdev channel.\u00a0 Here&#8217;s a chunk of what was said:<\/p>\n<pre>&lt;mike_conley&gt; Hey all - I'm trying to write an extension to override window.alert, with an alertCheck that allows users to disable future alerts.\r\n&lt;mike_conley&gt; So far, I'm able to override alert by writing to document.getElementById('content').contentWindow.wrappedJSObject.alert\r\n&lt;mike_conley&gt; however, now it's a matter of timing - I'm doing the override after the DOMContentLoaded event is fired\r\n&lt;mike_conley&gt; But this means that it doesn't catch alerts that are fired using inline javascript.\r\n&lt;mike_conley&gt; So my question is, when should I do the override?\r\n&lt;Mook&gt; I suspect just overriding commonDialog.xul is easier\r\n&lt;Mook&gt; trying to poke the content JS's definition is going to be full of pain\r\n&lt;mike_conley&gt; Cool, I'll look into that - thanks!\r\n&lt;Mook&gt; (the content JS starts around http:\/\/mxr.mozilla.org\/mozilla\/source\/dom\/src\/base\/nsGlobalWindow.cpp#4022 and goes the the prompt service which pokes that xul)\r\n&lt;mike_conley&gt; Excellent - I appreciate it.<\/pre>\n<p>So maybe there&#8217;s another approach that I should be taking &#8211; I&#8217;m going to look into overriding commonDialog.xul&#8230; I&#8217;ll write more when I have it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ok, so there have been some developments. Before I go into this though, I just want to make it clear that I have very little knowledge or experience working with XUL, or writing Firefox extensions in general.\u00a0 I&#8217;ve dabbled, but I&#8217;m mostly ignorant.\u00a0 So all you Firefox aficionados out there&#8230;go easy on me. So, developments: [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[380,5,220,44,68,51,79],"tags":[207,210,215,214,208,213,125,35,212],"class_list":["post-381","post","type-post","status-publish","format-standard","hentry","category-alertcheck-firefox-extensions-technology","category-computer-science","category-firefox-extensions","category-internet","category-javascript","category-security","category-technology","tag-alert","tag-alertcheck","tag-commondialogxul","tag-contentalert","tag-dos","tag-extension","tag-firefox","tag-mozilla","tag-windowalert"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/prmTy-69","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/comments?post=381"}],"version-history":[{"count":8,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":670,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/posts\/381\/revisions\/670"}],"wp:attachment":[{"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/media?parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/categories?post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikeconley.ca\/blog\/wp-json\/wp\/v2\/tags?post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}