Breaking JavaScript execution always when cookie is set

haba713 picture haba713 · Dec 20, 2016 · Viewed 7.8k times · Source

Is it possible to break javascript execution in FireBug or in some other web developer tool always when cookie is set (without setting JS breakpoints explicitly)?

document.cookie = '...';

Answer

haba713 picture haba713 · Jan 10, 2018

The answer below does not seem to work in Chrome. 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.