poorejc commented on issue #50: URL: https://github.com/apache/incubator-flagon-useralejs/issues/50#issuecomment-821766828
> All of the tests in the [merged branch](https://github.com/apache/incubator-flagon-useralejs/tree/UncleGedd-sendOnClose) are passing on my end, using Node version v14.8.0 and I don't have any global packages. > > When I was testing the viability of web workers I was swapping between tabs and closing the tab that the example page was open in. Both of those actions resulted in a seeing a custom web worker log in the terminal where the example server was running. I'm confident that the log was coming from the web worker itself, not `sendOnRefresh `. I was doing something like this in [worker.js](https://github.com/apache/incubator-flagon-useralejs/blob/UncleGedd-sendOnClose/src/worker.js): > > ```js > export function workerSendLog(e) { > const {url, logs} = e.data > fetch(url, { > method: 'POST', > headers: { > 'Content-Type': 'application/json' > }, > body: JSON.stringify([{webworker: 'from web worker'}]) // custom web worker log > }) > } > ``` > > One thing to make sure of is to set the `data-interval` to some value >1 in `example/index.html` and ensure that there are logs in the queue before closing the page (ie. click a couple of times and then close the tab to ensure there are logs to be flushed by the web worker). > > I saw when running the example app that `index.js` was not being loaded, looks like this was due to Express not using the base directory to serve files from? I pushed a small change to the example app in that [original branch](https://github.com/UncleGedd/incubator-flagon-useralejs/tree/spike-workers). > > Check out this video I made showing the behavior I'm seeing: https://youtu.be/ri0AHBMai20 A few findings: 1. Unit and Journey tests are now passing for me on this branch. May have had some collision when I last tested, also looks like node-fetch was missing from package, which broke jsdom-worker. Adding in that and tests are passing. 2. **Webworkers do appear to send logs during tab changes**. I was able to replicate your test with the web-worker. I consistently saw custom messages from the web worker flipping between tabs (jacked log interval to 5 from 1). *They are reliably shipping data to the right URL and they are reliably firing off of the visibility change event*. 3. **Webworkers aren't working reliably for end of page life cycle visibility events**. In that same test [2], web workers fired reliably for tabbing back and forth. However, they did not work for submit and navigation events. Similar to my earlier testing (reported above), I do see submit and click events for linked buttons sporadically--they are very rare and unpredictable. I tested under a wide range of constraints and I don't see a pattern. The common theme is that **webworkers don't seem to work reliably (or at all) when the page is unloading**. I confirmed this in devtools looking at xml request traffic. 4. **webworkers don't seem to work with pagehide events**. I'll test this some more, but I didn't see any behavior (e.g., [2]) using pagehide events. If true, that limits webworkers' utility in Safari. I'll do a little more testing soon, but I'm leaning toward fixing this issue with navigator.sendBeacon in the next release. Call it a hotfix. We can keep testing webworkers or move to websockets for more elegant solutions. I'll work with and look into your unit test for navigator.sendBeacon @UncleGedd that's very helpful, thanks! -- 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