javascriptcookiesbrowsergoogle-chrome-devtoolsbreakpoints

Breaking JavaScript execution when cookie is set


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

  • This should work (run it in a console):

    origDescriptor = Object.getOwnPropertyDescriptor(Document.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
    });