Search code examples
firefox-addonadd-onbrowser-addons

firefox addon checking sqlite database on event


I'm doing firefox addon that has it's sqlite database mydb.sqlite. It's a database of my selected links and I have a load event for gBrowser. Now I would like to write a code that will check the content.document.location on each load event and will notify me if the currently open link is in the database or if it is not in the database (e.g. with some icon on the status bar).

Do you know how to do it efficiently? So it won't slow down firefox much?

thank you


Solution

    1. Be sure you're listening for the DOMContentLoaded event, which fires on every page load

    2. You can get the loaded page's URL from within your DOMContentLoaded handler using e.target.defaultView.location.href (where e should be whatever you've named the first parameter in your callback).

    3. Now compare this URL to what's in the DB. Consider using asynchronous statement execution (Firefox 3.5 and newer only), so that you don't block the main thread unnecessarily.

    4. This excellent tutorial will show you how to update the status bar.