In testing document.location.href, I have observed that when the user initiates an action that results in javascript that assigns to document.location.href, the new URL is a
Read the original question more carefully. The question is not about content loaded by an XHR, but about content loaded by a script loaded by an XHR. I had the same problem and the setTimeout method seems to work well.