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 7793537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:31:11+00:00 2026-06-01T22:31:11+00:00

I am able to track all the dynamically created tags, using Brock Adams’ answer

  • 0

I am able to track all the dynamically created tags, using Brock Adams’ answer to “Log a web page’s dynamically-created, DOM elements with a userscript”.

Now I want to get the attributes of the tags. I tried it by adding an if condition in LogNewTagCreations () but it didn’t work.
In this example I am checking attributes for script tags:

if(tagName=="script")
    {
        console.log("------------",elem.attributes.src.Value);
    }

Please help me.

  • 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-01T22:31:13+00:00Added an answer on June 1, 2026 at 10:31 pm

    Because a <script>s src is set outside the createElement() call, adapting the previous script requires a little more work than that. You must check for the src attribute essentially asynchronously.

    One way to do that is with another polling interval. Rolling that into the previous script (along with some housekeeping), the script code becomes:

    //--- Intercept and log document.createElement().
    function LogNewTagCreations () {
        var oldDocumentCreateElement    = document.createElement;
    
        document.createElement          = function (tagName) {
            var elem = oldDocumentCreateElement.apply (document, arguments);
            console.log ("Dynamically created a(n)", tagName, " tag.  Link: ", elem);
    
            if (tagName == "script") {
                GetScriptAttributes (elem);
            }
    
            return elem;
        }
    }
    
    function GetScriptAttributes (elem, tagNum, timerIntVar) {
        /*--- Because a <script>s src or text 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;
        }
    
        if (elem.src) {
            doneWaiting ();
            console.log (
                "Script tag", tagNum,
                " has a src attribute of:", elem.src
            );
        }
        else if (elem.textContent) {
            doneWaiting ();
            console.log (
                "Script tag", tagNum,
                " has a JS code of:", elem.textContent
            );
        }
        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
    );
    
    //--- 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);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to track ALL elements that are clicked on a HTML-page. I need
What I mean is to be able to track the users' gestures across all
An application keeps track of hundreds of variables. Users are able to create conditions
Hi I have been able to extract a VARCHAR to a date using string_to_date
I am able to read emails in from Microsoft Exchange using an IMAP Client
I'd like to be able to track which application is currently focused on my
I've created a drawing of a truck using paths in an HTML5 canvas. The
I want to be able to track the data changes in the DB of
Hello all! I'm working on a prototype that would require me being able to
I'm trying to build a new web app using Eclipse, I want to use

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.