Break javascript before an inline javascript redirect in Chrome

前端 未结 3 1476
[愿得一人]
[愿得一人] 2020-11-29 21:37

I\'m viewing a page that has an inline javascript redirect (window.location = \"/anotherpage\"). I want to load the page in Chrome but have the redirect line d

相关标签:
3条回答
  • 2020-11-29 21:49

    Do the following

    1. Open Developer Tools
    2. Go to Sources tab
    3. Look for Event Listener Breakpoints
    4. Expand Load option
    5. Here check unload option

    0 讨论(0)
  • 2020-11-29 21:52

    I have a 3rd party JS library, which has had a wrong condition to reload the page. And the page has been reloaded continuously because of this. I tried to find where is the wrong code.

    I tried to use the "Event Listener Breakpoints" method, but as a comment said you don't have stack trace in unload events, so it is pretty useless.

    The solution which has worked for me: I created a page with an iframe tag with sandbox attribute, e.g. <iframe sandbox="allow-same-origin allow-scripts allow-popups allow-forms"></iframe> and put my site in it. This way security errors will occur inside chrome and the console shows where the JS tries to access the location object. You can click on it and see the code. The best is Chrome has a JS decompressor (the {} button in the bottom left of the source window), which is clever, can show the line even after pretty printing, so you can see it even in compressed JS.

    More info about sandbox property: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox

    0 讨论(0)
  • 2020-11-29 22:05

    Developer Tools -> Sources -> Event Listener Breakpoints (on the right sidebar) -> Load -> check unload

    This will make debugger break on unload event which is dispatched before navigation.

    0 讨论(0)
提交回复
热议问题