Reputation: 13
I want to monitor user activity in Firefox browser, I need to know it's location.href in current tab. For this I use content.location.href , but I need the code when this location.href changes. I need to know what events should I listen and on what objects in the browser.
Some of my code:
window.addEventListener("load", function load(event){
window.removeEventListener("load", load, false);
myExtension.init();
},false);
var myExtension = {
init: function() {
var appcontent = document.getElementById("appcontent");
appcontent.addEventListener("blur", myExtension.onPageBlur, true);
appcontent.addEventListener("load", myExtension.onPageLoad, true);
appcontent.addEventListener("focus", myExtension.onPageFocus, true);
},
onPageBlur: function () {
// Doing something when there is no focus
},
onPageFocus: function(aEvent) {
// Doing something when we get focus
},
onPageLoad: function(aEvent) {
// Doing something on page load
}
};
This code works, but with a little bit unwanted behavior, when you click on location bar of the browser, the blur event is fired, and difficult to work with location.href if the location.href is changed (focus and load event fired), need some rework to optimize when saving data of the user activity
I need that the code has this behavior:
Thank you in advance.
Upvotes: 1
Views: 386
Reputation: 57691
You should be using a progress listener for that. Your onLocationChange
will be called every time the location of the current tab changes, you would only need to look at aURI.spec
. The same approach is used to update the location bar in Firefox.
Upvotes: 1