poorejc commented on issue #50:
URL: 
https://github.com/apache/incubator-flagon-useralejs/issues/50#issuecomment-812796025


   @UncleGedd, @confusingstraw I beat up the webworkers pretty good in Chrome 
and Safari. 
   
   BLUF: The web-worker solution does appear to work, but there's still some 
work to do. Solution seems to be working in the client, but they are very 
unreliable in successfully posting to the back end (ELK and example server). 
Details follow:
   
   - I did see 'submit' events (after removing sendOnRefresh from refresh 
events in ./src/attachHandlers), and I did see a 'click' event on a button 
linked to a web link (e.g., navigate away from page).
   - Its behavior is terribly unreliable. I only observed the above events x2 
in about 25-50 sessions on the example page in Chrome and Safari. That being 
said, I did reliably see expected script behavior and network events in 
devtools. No error messages or info messages. But generally, no logs coming 
through to ELK or our example server (tried both)
   - I'm NO expert in webworkers. I suspect that the they may be behaving as 
expected in the client, but some feature of web workers are causing them to 
fail in posting data correctly to our backends. Seems like the backend is 
accepting one message sent by the webworkers, but no more. Unclear to me the 
conditions under which it accepts a message from a webworker. Tried restarting 
backends, but doesn't seem to reliably work.
   
   Other things:
   - I played around with a few different configs in @UncleGedd's sendOnClose 
function. I tried eliminating the condition on configs turning off. This worked 
in my navigator.sendBeacon event. See: 
https://github.com/apache/incubator-flagon-useralejs/blob/0ec3645b828ff1429ec70beba8165102180d443b/src/sendLogs.js#L60-L66
   - I did see about the same behavior in chrome and safari with pagehide 
instead of visibilitychange. pagehide isn't as good as visibilitychange, but 
behavior is more consistent across browsers it seems. Something to ponder 
later, once we figure out how to reliably post logs. see below:
   
   ```
   export function sendOnClose(logs, config) {
     if (!config.on) {
       return;
     }
     const worker = createWorker(workerSendLog)
     window.addEventListener('pagehide', function() {
         worker.postMessage({url: config.url, logs});
         logs.splice(0, logs.length)
     });
   }
   ```
   -visibilitychange triggerend sendOnClose unit test is still failing for me.
   
   Lots more testing to do on web workers. I'm going to do some testing with 
navigator.sendBeacon and pagehide in Safari tonight. At the moment, that is our 
most reliable solution. I'd like to see if there are any JSDOM examples of 
mocks for navigator.sendBeacon. @UncleGedd if you have any thoughts or want to 
do deeper testing with webworkers, feel free. Don't want to discourage you on 
this--they seem to be producing the right behavior in the client, but they're 
currently failing integration testing.
   
   FYSA: I merged test branch commits into UncleGedd's branch, took out 
sendOnRefresh (which was doing the work pushing 'submit' events, not 
sendOnClose), and pushed to a new branch here: 
https://github.com/apache/incubator-flagon-useralejs/blob/UncleGedd-sendOnClose/src/sendLogs.js.
 I also added a navigation button to the example page to test for submit events 
and page navigation behavior both.
   


-- 
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


Reply via email to