Sto facendo un addon per mio uso personale.
uso
browser.docShell.allowJavascript=false
e la cosa curiosa è che al caricamento iniziale esegue gli script
mentre se ricarico la pagina con F5 non li esegue.
Intercetto l'evento DOMContentLoaded
Mi daresti un suggerimento per risolvere il problema?
Io ho ipotizzato che la prima volta gli script vengono eseguiti man mano che la pagina si carica per cui al DOMContentLoaded "i buoi sono già scappati".
Mentre quando faccio il refresh la pagina è già stata aperta e imposta per non eseguire gli script.
forse dovrei usare http-on-modify-request ?
ty
DOMContentLoaded e allowJavascript
DOMContentLoaded e allowJavascript
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4) Gecko/20091028 Ubuntu/9.10 (karmic) Firefox/3.6.13
- Giorgio Maone
- Site Admin
- Posts: 9524
- Joined: Wed Mar 18, 2009 11:22 pm
- Location: Palermo - Italy
- Contact:
Re: DOMContentLoaded e allowJavascript
Hi.
Please use English for respect to other forum users.
You can think of DocShell as "document containers", which survive page loads.
If you intercept DOMContentLoaded, all the scripts except the event handlers already ran (because all the document has already been parsed), as you could notice.
Also, if you reload the DocShell properties are kept, therefore this time no script can run.
Using nsIDocShell.allowJavascript is quite tricky exactly for this reason: there's no really safe time to change it.
DOMContentLoaded is too late, but http-on-modify-request is too early (because the previous document has not been unloaded yet, and at least onbeforeunload and onunload get lost if you change to false, or run when you don't want them to if you change to true).
Furthermore, if you don't do the switch at the right time, the HTML parser may misunderstand the scripting enablement of the page and <NOSCRIPT> elements may be mishandled.
NoScript switches allowJavascript only to enforce the untrusted blacklist, and it does in _handleDocJS1() which, as you can see, gets called by a nsIWebProgressListener, during onStateChanged() execution, when both the STATE_IS_DOCUMENT and STATE_START state flags are set.
Please use English for respect to other forum users.
You can think of DocShell as "document containers", which survive page loads.
If you intercept DOMContentLoaded, all the scripts except the event handlers already ran (because all the document has already been parsed), as you could notice.
Also, if you reload the DocShell properties are kept, therefore this time no script can run.
Using nsIDocShell.allowJavascript is quite tricky exactly for this reason: there's no really safe time to change it.
DOMContentLoaded is too late, but http-on-modify-request is too early (because the previous document has not been unloaded yet, and at least onbeforeunload and onunload get lost if you change to false, or run when you don't want them to if you change to true).
Furthermore, if you don't do the switch at the right time, the HTML parser may misunderstand the scripting enablement of the page and <NOSCRIPT> elements may be mishandled.
NoScript switches allowJavascript only to enforce the untrusted blacklist, and it does in _handleDocJS1() which, as you can see, gets called by a nsIWebProgressListener, during onStateChanged() execution, when both the STATE_IS_DOCUMENT and STATE_START state flags are set.
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Re: DOMContentLoaded e allowJavascript
Thanks for your reply and sorry for the language but the question was difficult to translate.
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4) Gecko/20091028 Ubuntu/9.10 (karmic) Firefox/3.6.13