当window.location更改时中断? [英] Break when window.location changes?

查看:180
本文介绍了当window.location更改时中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不应该重定向的页面,我试图找出是谁在做这件事。首先,我试图劫持window.location:

  window.location =(function(location){
// location is现在隐藏在一个闭包里面,我们可以覆盖它
var Location = Object.create(location);
// Location现在是我们的代理,我们可以用它来捕捉变化
window .__ defineGetter__ ('location',function(){return Location});
window .__ defineSetter __('location',function(x){debugger; location = x; return x;});
// etc考虑分配给location.href,location.search,location.host等,以及调用location.replace和location.assign
(window.location));

在Chrome中完全没有用。出于安全原因,您不能在window.location上执行setter和getter。好。接下来的事情是观察onunload和onbeforeunload:

  ['unload','beforeunload']。forEach(function(evName ){
window.addEventListener(evName,function(){
debugger; //在重定向发生之前检查所有内容的机会
});
});

我知道window.location的值将保持不变,直到onunload事件之后,再次安全的原因,但我希望有其他线索;没有这样的运气。我接下来尝试在我可以在window.location可能分配的脚本中找到的每个点都放置断点。根据Chrome调试器,它们都没有被击中。哎呀。顺便说一句,这个重定向不会发生在FF中,我已经尝试重新启动Chrome。我觉得我已经真正尝试了一切,无处可去,希望这意味着我即将升级为开发人员?请问?



在我的任何浏览器中,操作调试器的人有没有办法突破重定向页面位置的路线?我知道允许自动访问这些信息会产生安全隐患,但是没有什么能够让开发人员获得特权,并且有办法执行此操作?如果不是,处理这种情况的正常方法是什么?这看起来很普遍,我不认为任何人都喜欢在一个概念上简单的问题上被封锁几个小时或几天。 TIA

解决方案

网络标签可以帮助您,切换保留日志复选框,发起人列将包含导致重定向的javascript位置。 / p>

I've got a page that's redirecting when it shouldn't be, and I'm trying to figure out who's doing it. First I tried hijacking window.location:

window.location = (function (location) {
    // location is now hidden inside a closure. We can override it
    var Location = Object.create(location);
    // Location is now our proxy. We can use it to catch changes
    window.__defineGetter__('location', function () { return Location });
    window.__defineSetter__('location', function (x) { debugger; location = x; return x; });
    // etc etc, considered assignments to location.href, location.search, location.host etc., as well as calls to location.replace and location.assign
}(window.location));

That didn't work at all in Chrome. You can't do setters and getters on window.location for security reasons. OK. The next thing I tried was observing onunload and onbeforeunload:

['unload', 'beforeunload'].forEach(function (evName) {
    window.addEventListener(evName, function () {
        debugger; // Chance to check everything right before the redirect occurs
    });
});

I knew that the value of window.location would stay the same until after the onunload event, again for security reasons, but I was hoping for some other clue; no such luck. I next tried putting breakpoints at every point I can find in my own scripts where window.location could possibly be assigned. None of them are hit according to the Chrome debugger. Argh. This redirect is not happening in FF, by the way, and I already tried restarting Chrome. I feel like I've truly tried everything and gotten nowhere, which hopefully means I'm about to level up as a developer? Please?

Is there any way in any browser for me, the human operating the debugger, to break on the line that's redirecting the page location? I understand there are security implications for allowing automatic access to that information, but is there nothing that privileges the developer and allows a way to do it? If not, what's the normal way of dealing with a situation like this? It seems common enough and I don't think anyone likes getting blocked for hours or days on a conceptually simple problem. TIA

解决方案

Network tab helps you, switch on preserve log checkbox, initiator column will contain the javascript location that caused the redirect.

这篇关于当window.location更改时中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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