设置 cookie 时总是中断 JavaScript 执行 [英] Breaking JavaScript execution always when cookie is set

查看:17
本文介绍了设置 cookie 时总是中断 JavaScript 执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在设置 cookie 时始终在 FireBug 或其他 Web 开发人员工具中中断 javascript 执行(无需明确设置 JS 断点)?

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

推荐答案

下面的答案似乎不起作用铬合金.将此代码段添加到 html → head 块的开头可以正常工作:

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>

参见 这个 Angular 大学页面 了解更多信息.

See this Angular University page for more information.

这篇关于设置 cookie 时总是中断 JavaScript 执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆