Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7825281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:54:42+00:00 2026-06-02T08:54:42+00:00

As per this post Log a web page’s dynamically-created tag attributes with a userscript

  • 0

As per this post Log a web page’s dynamically-created tag attributes with a userscript

i retrieved the attributes and also included the array as suggested like

addJS_Node ("var arr=[];");

i successfully pushed the src attributes to arr array because i didn’t get any error.

Now i am confused where to display the array.

My code is as follows

// ==UserScript==
// @name        Tags Monitoring
// @namespace   PC
// @run-at      document-start
// ==/UserScript==
//--- Intercept and log document.createElement().tagattributes
addJS_Node ("var arr=[];"); 
function LogNewTagCreations ()
{   
   var oldDocumentCreateElement = document.createElement;
  document.createElement       = function (tagName) 
  {
      var elem = oldDocumentCreateElement.apply (document, arguments);  
      if(tagName=='script')      
         GetScriptAttributes (elem); 
     return elem;
  }   
}
function GetScriptAttributes (elem, tagNum, timerIntVar) 
{
   /*--- Because the tags won't be set for some while, we need
    to poll for when they are added.
   */       
   GetScriptAttributes.tagNum  = GetScriptAttributes.tagNum || 0;
   if ( ! tagNum) 
   {
       GetScriptAttributes.tagNum++;
       tagNum = GetScriptAttributes.tagNum;
   }   
   /*-- Getting the required attributes */
   if (elem.src) 
   {
      doneWaiting ();
      arr.push(elem.src);
        console.log (
        tagNum," has a src attribute of:", elem.src,"=========",arr.length
        );
   }    
   else 
   {
    if ( ! timerIntVar) 
    {
        var timerIntVar = setInterval 
        (
            function () 
            {
                GetScriptAttributes (elem, tagNum, timerIntVar);

            },
            50
        );            
    }        
}    
function doneWaiting () 
{
    if (timerIntVar) 
    {
        clearInterval (timerIntVar);
    }       
}    
}
 /*--- The userscript or GM script will start running before the DOM is available.
   Therefore, we wait...
  */
  var waitForDomInterval = setInterval (
  function () {
    var domPresentNode;
    if (typeof document.head == "undefined")
        domPresentNode = document.querySelector ("head, body");
    else
        domPresentNode = document.head;       
    if (domPresentNode) {
        clearInterval (waitForDomInterval);            
        addJS_Node (GetScriptAttributes.toString() );                    
        addJS_Node (null, null, LogNewTagCreations);
    }
},
1  
);

 addJS_Node("document.onreadystatechange = function (){if (document.readyState ==       'complete'){console.log(arr.length);}}");

//--- Handy injection function.
function addJS_Node (text, s_URL, funcToRun) {
var D                                   = document;
var scriptNode                          = D.createElement ('script');
scriptNode.type                         = "text/javascript";
if (text)       scriptNode.textContent  = text;
if (s_URL)      scriptNode.src          = s_URL;
if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (scriptNode);    
}

I want to print the number of tags created dynamically that is why i added array. I first tried with script tags only and how can i know the array is completed and so that i can print the array length

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:54:43+00:00Added an answer on June 2, 2026 at 8:54 am

    Looks like your problem is not with your code.
    You simply dont know javascript at all.

    I strongly recommend you start with simple codes and tutorials.
    Try to code your first script.
    If you have any doubt about your code, feel free to come and ask about it.

    The code that Brock Adams gave you is working perfectly.
    I just copy-pasted it into Greasemonkey.
    Here is the output:

    enter image description here

    And please go back to Log a web page's dynamically-created tag attributes with a userscript and mark his answer as the right one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm dynamically adding a custom user control to the page as per this post
Referencing this post: ruby on rails average per day I'm getting the average per
As per this MSDN article: W3C Extended Log File Format (IIS 6.0) It says
I intend to have a busy waiting spinner as per shown in this post:
Per this post here there are 3 ways (1)do the whole thing in C++,
Per this helpful article I have confirmed I have a connection pool leak in
Per this question (see comments near the bottom), I was wondering if anyone knows
As per this JSFiddle , I create an Isotope container which contains each of
I am having the same issues as per this question: WCF not deserializing JSON
I need to have a single instance application (as per this answer ), but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.