Within my project, I am tasked with extracting the content within all script tags. To accomplish this, I have been using the following code:
var scrpt=document.getElementsByTagName('script');
script_txt=scrpt[i].innerHTML;
However, this method does not capture dynamic scripts that are generated using:
var s=document.createElement('script');
s.src="http://somefile.js";
In addition to this approach, there exist other ways of incorporating dynamic scripts such as:
document.write('<script src="">');
And also:
document.body.innerHTML='<script src="">';
Furthermore, in an attempt to collect this information, I experimented with regular expressions like so:
var pattern=/([a-zA-Z0-9_\.].*?)=(document.createElement\((.*)\));
/g;
Yet, it became evident that this approach may not cover all scenarios successfully.
If anyone has suggestions on a more effective method for achieving this goal, please share your insights.