{"id":250,"date":"2008-04-06T22:37:42","date_gmt":"2008-04-06T22:37:42","guid":{"rendered":"http:\/\/dalelane.co.uk\/blog\/?p=250"},"modified":"2008-04-06T22:37:42","modified_gmt":"2008-04-06T22:37:42","slug":"capturing-page-loaded-events-from-a-firefox-extension","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=250","title":{"rendered":"Capturing page loaded events from a Firefox extension"},"content":{"rendered":"<p>One of my hacks at <a href=\"http:\/\/overtheair.org\/blog\/\" target=\"_blank\">Over The Air<\/a> was an attempt to <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=246\">sync browser histories between desktop and mobile<\/a>. A part of this was a Firefox extension which listens for when I go to a new webpage, gets the URL from the Firefox address bar and sends it to a connected mobile.<\/p>\n<p>As my first attempt at a Firefox extension, I was surprised by how easy this was. I&#8217;ve made it, so if anyone wants to learn or build on it, <a href=\"http:\/\/dalelane.co.uk\/files\/bladesync.zip\">downloading the source<\/a> may be useful. (<em>Remembering it was thrown together in a bit of a hurry!<\/em>) But I wanted to highlight a couple of quick points.<\/p>\n<p>Firstly &#8211; getting started. <a href=\"http:\/\/blog.owengriffin.com\/\" target=\"_blank\">Owen<\/a> pointed me at a brilliant <a target=\"_blank\" href=\"http:\/\/ted.mielczarek.org\/code\/mozilla\/extensionwiz\/\">Firefox extension wizard<\/a>. Fill in the simple form &#8211; telling it stuff like whether you want to add an options dialog and preferences, or a context menu item, or a toolbar button, and so on. And it generates you a skeleton Firefox extension ready for you to fill in with code. This probably saved me an hour or two of reading about how to create Firefox extensions!<\/p>\n<p>Secondly &#8211; capturing new pages. This was done by adding a listener for DOMContentLoaded events:<\/p>\n<pre><code>var appcontent = window.document.getElementById(\"appcontent\");\r\nappcontent.addEventListener(\"DOMContentLoaded\", \r\n                            myContentLoadedFunction, \r\n                            false);<\/code><\/pre>\n<p>And in my content loaded function, I got the URL like this:<\/p>\n<p><code>var urlbar = document.getElementById('urlbar');<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of my hacks at Over The Air was an attempt to sync browser histories between desktop and mobile. A part of this was a Firefox extension which listens for when I go to a new webpage, gets the URL from the Firefox address bar and sends it to a connected mobile. As my first [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[152,160],"class_list":["post-250","post","type-post","status-publish","format-standard","hentry","category-code","tag-firefox","tag-javascript"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=250"}],"version-history":[{"count":0,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}