Search code examples
javascriptnode.jsgoogle-chromenwjs

How to Debug a JavaScript code when it is loaded by document.write?


I can see the code in Element view in Chrome, but not in source because it is load by document.write function.

How do I set a breakpoint in this case?


Solution

  • I suppose you have access to the source code that generates the document.write, you can add a call to the 'debugger' like this:

    <script>
    document.write('<sc' + 'ript> debugger; alert(0);</s' + 'cript>');
    </script>
    

    I you have the debugger opened on chrome, it will stop the execution and show the generated code on the Sources tab.