admin 管理员组

文章数量: 1086019

I'm analyzing a site where the document.location.hash changes after some seconds since page loaded. It seems something asynchronous. Is possibile to debug who change the hash, via Chrome inspector?

By now I only add a "watch" but is hasn't breakpoint.

Thanks

I'm analyzing a site where the document.location.hash changes after some seconds since page loaded. It seems something asynchronous. Is possibile to debug who change the hash, via Chrome inspector?

By now I only add a "watch" but is hasn't breakpoint.

Thanks

Share Improve this question asked Feb 28, 2018 at 16:24 MerlinoxMerlinox 3773 silver badges9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

You can enable an event listener breakpoint for "hashchange":

As of 2019 Q4, this functionality exists in the "Sources" tab, in a panel titled "Event Listener Breakpoints".

When code now makes a change to location.href Chrome would stop at a handler for this event:

You can now go to the cause using the "Call Stack" panel.

This only works when there's already an event handler for hashchange.

Assuming you don't have such an event handler in your code yet, create an event handler like this:

window.addEventListener("hashchange", function(e) {
    debugger;
});

本文标签: javascriptChrome Debug who changes documentlocationhashStack Overflow