Chrome was the last of a large trio (IE, Firefox, Chrome) to refuse to make XMLHttpRequest synchronous calls in the "main thread" (as Firefox calls it). Some browsers also completely removed the ability to set the .widthCredentials option for synchronous requests in the main thread.
After searching around the world, I could not find enough information to determine exactly which code would work in the main thread and which would not.
Obviously, javascript included through the script tag (inline or with src) is in the main thread. And the synchronous XHR that works inside the asynchronous XHR callback will not work in the main thread.
But what about other scenarios? Mouse events, touch events, various document events? How to say without trying everything? It would be nice to avoid creating an asynchronous and reverse hell.
Please try a thorough answer.
Edit: W3C Specification Warning : Developers should not pass false for the async argument when the global JavaScript environment is the document environment because it has a negative effect on the end user interface. User agents are strongly advised to warn of such use in the developerโs tools and can experiment to eliminate the InvalidAccessError exception when it occurs, so that this function can ultimately be removed from the platform.
Edit 2: Clarification:
There are situations when the calling code must either wait until all racing simultaneous asynchronous calls end (using some counters or state tracking variables for each call), or they are chained using callbacks. Each situation sucks. For example, I have a JSONRPC client that needs to dynamically create callable functions by polling the reflection API.
Inside the hand, all the executable code (UI or NOT) needs to be executed inside the callback of another library, especially if it needs to be done on several pages, and if the library should behave like a simple definition (hide that the code works during the definition). This is just an example of complexity , I do not ask permission for it, but a general clear explanation of how the browser decides what is the main thread.