Hi,
Is it possible to modify JavaScript code when a web page
is loading? I have been proving the followings techniques:
*
http://groups.google.com/group/mozilla.dev.tech.network/browse_thread/thread/62af84e6d35ab77d/df5a79e36a4caf24#df5a79e36a4caf24
These techniques in nutshell is to use an "observer" and "converter"
objects. Using "observer" object i modify the MIME type of document
and using the "converter" object i modify the document.
However, i have not attained to modify the JavaScript
code, only i have attained to modify HTML to HTML and WML to HTML
(http://wmlbrowser.mozdev.org/index.html).
Anybody can give a help, please.
Here i write an extract of my code (maybe, i am doing bad something):
//This function modify a document.
JavaScriptConverter.prototype.onStopRequest =
function (aRequest, aContext, aStatusCode) {
var converter = Components
.classes["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance
(Components.interfaces.nsIScriptableUnicodeConverter);
converter.charset = this.charset;
try {
this.data = converter.ConvertToUnicode
(this.unencodeddata);
} catch (failure) {
this.logger.logStringMessage ("wmlbrowser: Failure
converting unicode using charset " + this.charset);
this.logger.logStringMessage (failure);
this.data += this.unencodeddata;
}
var wrapData = rewrite(this.data);
var sis =
Components.classes["@mozilla.org/io/string-input-stream;1"]
.createInstance(Components.interfaces.nsIStringInputStream);
sis.setData (wrapData, wrapData.length);
// Pass the data to the main content listener
this.listener.onDataAvailable (this.channel, aContext, sis, 0,
wrapData.length);
this.listener.onStopRequest (this.channel, aContext,
aStatusCode);
};
Observer.prototype = {
observe: function(subject,topic,data){
subject.QueryInterface(Components.interfaces.nsIChannel);
myDump("Observer:prototype:1:"+subject.contentType+"
data:"+data+ " topic:"+topic);
if (subject.contentType == "text/javascript" ||
subject.contentType == "application/x-javascript")
subject.contentType = "text/vnd.wap.wml";
contenido = subject.contentType;
myDump("Observer:prototype:2:"+subject.contentType+"
data:"+data+" topic:"+topic);
}
.....
}
Thank in advance,
Paul Leger.
_______________________________________________
dev-tech-network mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-network