When you next experience the issue, you can try to debug it:
0. You should be viewing the page using MediaWiki's debug mode to make the results easier to interpret (add &debug=1 to the page address). Note that this will make pages load slower. 1. Open the Firefox developer tools (Ctrl+Shift+I, or Tools → Web Developer → Toggle Tools). 2. Switch to the "Debugger" tab. 3. Click the "Pause" button.
Screenshot: https://phabricator.wikimedia.org/F10524704 (this is Firefox 57 on Windows 10, but the layout should be similar everywhere)
This will pause the execution of JavaScript on the page and reveal the script that was executing (if nothing is currently executing, it will pause at the beginning of the next function to execute). You can right-click the file name to copy/reveal the full path of the script.
For example, in this screenshot the execution paused inside the code to toggle the blinking cursor in the CodeMirror editor: https://phabricator.wikimedia.org/F10524713
(Please also take a screenshot of the entire debugger when filing a task about this, the "Call stack" on the right is very useful if the script itself is large.)
Afterwards click the "Resume" button (in the same location as "Pause") to let the page continue executing. Try doing this a few times, in case multiple scripts are running, to increase the chance of seeing each one.