javascriptdombrowser

JavaScript ran on page, but at the end deleted its own DOM node. How do I test it did something?


A scenario,

I have a script element in the DOM

This script did "things" on the page, then it deleted itself

<script type="text/javascript" id="the-javascript">
(function (d){

    var ...,
        script = d.getElementById('the-javascript'),
        ...;

    // lotsa code !!

    script.parentNode.removeChild(script);

}(document));
</script>

This was an Anonymous IIFE (Immediately invoked function execution)
How do I know that JavaScript was executed on the page. Stuck in a scenario in which I must find that.

Anything other than view-source?

I am running a test case, that needs to find if JavaScript ran on the page
I know the use of Developer Tools. Duh! The code was in a script tag and the code deleted the script tag
The code was anonymous, so no globals that I can check in console, or wherever
I have to find if that JavaScript created any DOM elements, without using view-source


Solution

  • "My question in one line would be - "How do I find that a JavaScript code has been executed on a page, if that code deleted itself"."

    If the script deleted itself from the DOM, it can't be found... because it isn't there... because it was deleted.


    To address the updated question and comments, aside from making an XHR request for the page and analyzing the content received, there's not really any way to safely detect if a script ran and then deleted itself.

    You could search for side-effects of the code, but the number of possibilities is really too great, and it could be that the script had no visible side-effect.