<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mike Conley&#039;s Blog &#187; DOMContentLoaded</title>
	<atom:link href="http://mikeconley.ca/blog/tag/domcontentloaded/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikeconley.ca/blog</link>
	<description>The personal blog of a Toronto based software developer, musician, sound designer, and theatre enthusiast.</description>
	<lastBuildDate>Fri, 11 May 2012 15:23:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Overriding Firefox’s Window.Alert &#8211; Part 3</title>
		<link>http://mikeconley.ca/blog/2009/05/03/overriding-firefox%e2%80%99s-windowalert-part-3/</link>
		<comments>http://mikeconley.ca/blog/2009/05/03/overriding-firefox%e2%80%99s-windowalert-part-3/#comments</comments>
		<pubDate>Sun, 03 May 2009 07:14:17 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[alertCheck]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Firefox Extensions]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[content.alert]]></category>
		<category><![CDATA[contentWindow]]></category>
		<category><![CDATA[DOMContentLoaded]]></category>
		<category><![CDATA[DOMWillOpenModalDialog]]></category>
		<category><![CDATA[DoS]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[override]]></category>
		<category><![CDATA[window.alert]]></category>
		<category><![CDATA[wrappedJSObject]]></category>

		<guid isPermaLink="false">http://mikeconley.ca/blog/?p=387</guid>
		<description><![CDATA[Wow.  I think I got it.  I&#8217;ve got a Firefox plugin that can suppress all alert() dialogs on a page if the user checks a &#8220;suppress&#8221; box on the second alert() dialog. The trick, was not to rely on the DOMContentLoaded event to fire to do the override.  Instead, I used the DOMWillOpenModalDialog to detect [...]]]></description>
			<content:encoded><![CDATA[<p>Wow.  I think I got it.  I&#8217;ve got a Firefox plugin that can suppress all alert() dialogs on a page if the user checks a &#8220;suppress&#8221; box on the second alert() dialog.</p>
<p>The trick, was not to rely on the DOMContentLoaded event to fire to do the override.  Instead, I used the DOMWillOpenModalDialog to detect the first alert().  After detection, I overrode with an alertCheck which asked the user whether or not to &#8220;suppress more dialogs&#8221;.  If the user answers in the affirmative, alert() is simply overwritten with an empty function.</p>
<p>Piece of cake.</p>
<p>A couple of issues though&#8230;</p>
<h2>Security</h2>
<p>In order to override the alert() function, I have to write to document.getElementById(&#8216;content&#8217;).contentWindow.wrappedJSObject.alert.</p>
<p>Remember how I mentioned the <em>distance</em> between the Extension JavaScript, and the inline content JavaScript?  I said it felt like a security layer.</p>
<p>I was totally right.</p>
<p><a href="https://developer.mozilla.org/En/Working_with_windows_in_chrome_code#Accessing_content_documents">Check this out.</a> I&#8217;ll quote:</p>
<blockquote><p>You should be aware of <a rel="internal" href="https://developer.mozilla.org/en/XPCNativeWrapper">XPCNativeWrappers</a> when working with <a rel="internal" href="https://developer.mozilla.org/en/XPCNativeWrapper#What_is_a_trusted_window.3F">untrusted content</a>. With XPCNativeWrappers turned on (which is the default in Firefox 1.5+), your extension can safely access the DOM of the content document, but not the content JavaScript. Bypassing XPCNativeWrapper to work with content JavaScript directly can lead to security problems.</p></blockquote>
<p>Hrmph.  So I seem to be violating some security rules here.  So maybe my approach isn&#8217;t the greatest idea.  &#8220;Mook&#8221; from irc.mozilla.net #extdev suggested looking into commonDialog.xul&#8230;but I can&#8217;t seem to wrap my head around that just yet.</p>
<h2>Imperfections</h2>
<p>Not sure why yet, but while I can suppress dialog floods like this:</p>
<pre>for (i = 0; i &lt; 10; ++i) {
  alert(i);
}</pre>
<p>It seems to fail on this:</p>
<pre>for (i = 0; i &lt; 10; ++i) {
  alert(i);
  confirm(i);
}</pre>
<p>For some reason, regardless of whether or not I choose to suppress the dialogs, they just keep coming.  It works fine when I swap out the confirm() for a second alert().  Not exactly sure why.  Yet.</p>
<p>Ok, so I&#8217;m going to clean the code up, and post it soon.  I&#8217;ll also post a link to a real, brutally annoying website where you can test the alertCheck extension.  Just give me a bit.</p>
]]></content:encoded>
			<wfw:commentRss>http://mikeconley.ca/blog/2009/05/03/overriding-firefox%e2%80%99s-windowalert-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

