Open kmike opened 10 years ago
Another option is to deep-clone the page after loading and replace it with a cloned one - event listeners are not cloned when cloneNode is called.
Even if we can track all listeners, it is probably too costly. Parsing all * elements to get rid of the href and on* attribute is already quite long and the user has time to click on some elements before it's done. Deep cloning the whole page is more elegant if it works. (but "reactivate links" won't work)
I think that deleting event listeners can be much faster than changing elements attributes because attributes are a part of DOM, CSS rules can depend on them and so browser could need to re-render the page - this is not the case for event listeners.
Removing event listeners (either by using nsIEventListenerService or by cloning a page) is more than just deactivating the links - it will stop some drop-down menus from working, and other stuff like that. Are you OK with that? Do we need a separate button/option for it?
Well my opinion is that the more static the page under annotation, the better. We will be unable to annotation inside a dynamic menu, but I'm not even sure it was possible so far.
Ok, got it. I'll try implementing this soon.
nsIEventListenerService
drives me nuts - you can get event listeners, but you can't remove them with removeEventListener. Something with object wrapping seems to be wrong; callback object you get seems to be different from the callback object registered. But maybe I'm doing something wrong. Related ticket: https://bugzilla.mozilla.org/show_bug.cgi?id=890505
Deep-cloning the whole page works fine for removing all events (I did a quick prototype). We should be careful to create popups after the page is cloned, but this approach would work if not being able to reactivate links if fine. I personally don't see much value in reactivating them - why is this feature needed?
test file can be found in my branch: https://github.com/kmike/WebAnnotator/tree/link-disabling2; I haven't commited nsIEventListenerService attempts.
I think I provided the reactivate feature because it was easy to. We can keep reactivating hrefs and on* attributes and forget about event listeners.
Check e.g. https://www.facebook.com/MadHatterCafeWeymouth - for me links are half-enabled on first load (check a link with an address):
Then, after clicking "Activate links", some attributes changes:
Then, after clicking "Disable links" again, I get the following results:
On other pages links disabling also was inconsistent. I recall for some pages links were not disabled, but after restarting browser and activating session again they became disabled.
It seems that there is some flaw or a bug in a way links are disabled.