Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breaking JavaScript execution always when cookie is set

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

document.cookie = '...';
like image 409
haba713 Avatar asked Dec 20 '16 15:12

haba713


Video Answer


2 Answers

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.

like image 75
haba713 Avatar answered Sep 23 '22 20:09

haba713


This should work (run it in a console):

origDescriptor = Object.getOwnPropertyDescriptor(HTMLDocument.prototype, 'cookie');
Object.defineProperty(document, 'cookie', {
  get() {
    return origDescriptor.get.call(this);
  },
  set(value) {
    debugger;
    return origDescriptor.set.call(this, value);
  },
  enumerable: true,
  configurable: true
});
like image 27
fflorent Avatar answered Sep 22 '22 20:09

fflorent