Search code examples
javascriptdomuserscripts

how to Retrieve the parameters of document.write using userscript


In my Project i am supposed to identify the dynamically created tags which can be done in scripts through document.write. i created a hook for document.write but it is not retrieving all the document.write functions.My code is as follows

UPDATE:

var oldDocumentWrite = document.write; 
document.write      = function (text) 
{        
  console.log(text);
}

where text is the parameters of document.write.

I included this in my userscript. How can i get the parameters of document.write.Is there any mistake in my code.


Solution

  • I tried this again by using the below code now i am getting all the document.write methods.

     var oldDocumentWrite = document.write; 
     document.write      = function (str) 
     {        
        var elem = oldDocumentWrite.apply (document,arguments); 
        console.log("Document.write Parameters:",str);
        return elem;
     }