Tracking fails if a page is leaved
Looks like amplitude.logEvent crashes if it's followed by window.location.raplace, consider example:
...
amplitude.getInstance().init(amplitudeApiKey);
Vue.prototype.$amplitude = amplitude;
...
navigateAfterLogin() {
this.$amplitude.getInstance().logEvent('Login passed');
setTimeout(() => {
this.$amplitude.getInstance().logEvent('test tracking crash');
window.location.replace(this.nextPage);
}, 1000);
},
I have tried to call this.$amplitude.getInstance().sendEvents() on page startup but nothing happens, so I guess LocalStorage contains no events.
Expected Behavior
Both events are successfully uploaded
Current Behavior
Second logEvent crashed.

Environment
"amplitude-js": "^7.4.4" Chrome Version 89.0.4389.82 (Official Build) (x86_64)
Seems to be related to https://github.com/amplitude/Amplitude-JavaScript/issues/136
Thanks @ViktorDanyliuk for reporting this, we'll take a look!
@ViktorDanyliuk I think your issue looks pretty related to page changes. We'll discuss more internally about how to build the sendBeacon API into our SDK.
For the second issue (sendEvents not working after page load) - potential culprits might be the JS SDK not loading fully w/events before trying to send, or an issue with our logic using sendEvents publicly - we can investigate this separately.
I followed https://github.com/amplitude/GTM-Web-Demo, with GTM in the middle it sends events when the next page is loaded.
I would like to avoid canceled requests but it's not critical anymore.