1

I have a webapp that makes use of websocket (io) to communicate with the backend. (It uses Underscore and JQuery, but nothing fancier like React.) In Safari, every few minutes the page refreshes.

How can I tell what made that happen? In the Developer Tools Network tab I see an xhr and other requests, but how do I see what line of Javascript initiated that?

enter image description here

Stopping on the beforeunload event in the debugger does not show anything in the call stack.enter image description here

Joshua Fox
  • 18,704
  • 23
  • 87
  • 147
  • 1
    Did you find the `initiator` column in the tab? – ikhvjs Aug 20 '21 at 14:57
  • `window.addEventListener("beforeunload", function() { debugger; }, false)` – Andreas Aug 20 '21 at 14:58
  • Not a real dupe, but the answers (other than the accepted one) might help nevertheless: [How to use Chrome's network debugger with redirects](https://stackoverflow.com/questions/10987453/how-to-use-chromes-network-debugger-with-redirects) – Andreas Aug 20 '21 at 15:00
  • Better dupe candidate: [Debug webpage redirects in browser](https://stackoverflow.com/questions/18477825/debug-webpage-redirects-in-browser) – Andreas Aug 20 '21 at 15:10
  • @ikvjs Where would I see this tab? Note the screenshot -- I don't see it there – Joshua Fox Aug 22 '21 at 06:28
  • @andreas -- thank you for the snippet. But when the debugger stops, it is of course in the unload listener, which does not have the original cause of the reload in the call stack. How do I find the cause of the reload? – Joshua Fox Aug 22 '21 at 06:31
  • @JoshuaFox, you quote my name wrongly...nvm, I post my answer. – ikhvjs Aug 23 '21 at 07:47
  • _"it is of course in the unload listener, which does not have the original cause of the reload in the call stack."_ - In Chrome I see the source of the redirect in the callstack: https://imgur.com/rOd0WvX – Andreas Aug 23 '21 at 07:58
  • @andreas Stopping on the `beforeunload` event in the debugger does not show anything (beyond that debugger callback itself) in the call stack in Safari. (See body of question.) The reload behavior does not happen for me in Chrome. – Joshua Fox Aug 23 '21 at 09:18

1 Answers1

2

There is a column initiator in the Network tab. You can see what initiates the network.

note: Chrome Version 92.0.4515.159 (Official Build) (64-bit)

enter image description here

ikhvjs
  • 5,316
  • 2
  • 13
  • 36
  • Thank you. In Safari, I had to enable that column -- now I haveit. – Joshua Fox Aug 23 '21 at 08:57
  • The Initiator column showed me that socket.io was doing the reloading. The specific filename + line number was apparently incorrect (looking both at the minimized file and the original) but for now I will assume -- without much evidence -- that this issue is specific to Safari and that Safari has some limitation the prevents websockets from working in their normal way, so that there is a fallback to a full page load after some timeout. – Joshua Fox Aug 24 '21 at 08:42