[FIXED] Breaking JavaScript execution when cookie is set

Issue

Is it possible to break javascript execution in browser developer tools always when a cookie is set (without setting JS breakpoints explicitly)?

document.cookie = '...';

Solution

Adding this snippet in the beginning of an html → head block works fine:

<script type="text/javascript">
    function debugAccess(obj, prop, debugGet){
        var origValue = obj[prop];
        Object.defineProperty(obj, prop, {
            get: function () {
                if ( debugGet )
                    debugger;
                return origValue;
            },
            set: function(val) {
                debugger;
                return origValue = val;
            }
        });
    };
    debugAccess(document, 'cookie');
</script>

See this Angular University page for more information.



Answered By - haba713
Answer Checked By - Dawn Plyler (Python.Easybugfix Volunteer)

Related Posts

Post a Comment