Fix for async loading of TTVC lib
This PR addresses the issue where ttvc is loaded into an SPA after the window.load has fired.
In the current state that means the observer for the resources never registers.
This is already properly handled in the waitForPageLoad called from visuallyCompleteCalculator, we check the document.readyState and immediately resolve if it is complete. But it was not handled for the networkIdleObservable.
I have added the test that validates this behavior. Without the fix it marks ttvc before the img is ever downloaded.
Obviously there is still a gap if the resource started downloading before ttvc was initialized, but at least this way ttvc will work for future SPA navigations. Without this fix any future resources (e.g. additional bundles) are also not tracked.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.
Also, for the record, and in case anyone else stumbles on this issue: we strongly recommend loading the ttvc library synchronously and as early in the document as possible to ensure accurate stats are reported.
@ajhyndman sorry, let me go through the steps to be able to contribute to it here from my work account I and will re-do the submission.
Closed in favor of #92