The below code works on the server.
The above code does not.
This was the issue.
window.addEventListener('beforeunload', (event) => { PageMethods.LogOutOfRecord(); });
I do not have an explanation as to why the original code will work locally and not on the server and this one will work on both.