Breaking JavaScript execution always when cookie i

2019-01-27 00:36发布

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 = '...';

Harri

3条回答
等我变得足够好
2楼-- · 2019-01-27 00:59

Try setting it in a If statement.

if(document.cookie.indexOf('...') >= 0){
  debugger;
}

note: when using firefox your console has to be open. in chrome this is not the case.

查看更多
仙女界的扛把子
3楼-- · 2019-01-27 01:17

https://stackoverflow.com/a/41247745/2158271 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.

查看更多
狗以群分
4楼-- · 2019-01-27 01:20

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
});
查看更多
登录 后发表回答