poorejc commented on issue #50: URL: https://github.com/apache/incubator-flagon-useralejs/issues/50#issuecomment-806171078
I’d like to explore that RE alternatives to navigator.sendbeacon. Unfortunately, I can’t get sendLogs working against page unload event handlers (or visibility change events). The only thing that (I’ve tried) that works for this is sending data via navigator.sendbeacon triggered off of a visibility change event. So the ask wasn’t necessarily just to build unit or journey test, but really help shake this solution (integration test). The problems with this solutionare: 1. navigator.sendbeacon isn’t as reliable as docs suggest (see Robs links in ticket) 2. That method is difficult to programmatically test (unit and journey) 3. Safari doesn’t support visibility change events as uniformly as Moz and Chrome. Need some more hands on testing before we commit to the current course of action. Joshua Poore > On Mar 24, 2021, at 12:56 PM, UncleGedd ***@***.***> wrote: > > > Ok, I've got one of the tests working: > > it('sends logs on page exit with navigator', () => { > const html = `<html><head></head><body></body></html>`; > new JSDOM(html) > const originalNavigator = global.navigator; > let called = false; > global.navigator = { > sendBeacon: () => { > called = true; > }, > }; > > sendOnClose([{foo: 'bar'}], {on: true, url: 'test'}); > Object.defineProperty(global.document, 'visibilityState', { > get: () => 'hidden' > }) > global.document.dispatchEvent(new Event('visibilitychange')) > > global.navigator = originalNavigator > expect(called).to.equal(true); > }); > Basically I'm just faking the visibilitychange event and manually setting the visibilityState to "hidden" so the sendBeacon function will fire. > > Regarding the other failing test: > > it('sends logs on page exit without navigator', () => { > // ... > } > In what case would we not have the navigator? Do we want to move away from using navigator.sendBeacon as the link Rob posted is suggesting? > > — > You are receiving this because you were assigned. > Reply to this email directly, view it on GitHub, or unsubscribe. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org