count of samples (frames) lost from microphone

I need a counter of lost frames from microphone or an event if samples from microphone are lost. I need this information to perfect timing microphone signal and audio output signal.

I have code:

   $micStream=await navigator.mediaDevices.getUserMedia(
      {
         audio:
         {
            echoCancellation: false,
            noiseSuppression: false,
            autoGainControl: false,
         }
      }
   );
   $micAudioCtx=new AudioContext();
   $micMS=$micAudioCtx.createMediaStreamSource($micStream);

      if($micAudioCtx.audioWorklet && $micAudioCtx.audioWorklet.addModule)
      {
         var $data=`
class RecorderProcessor extends AudioWorkletProcessor
{
   bufferSize=17640;
   written=0;
   buffer=new Float32Array(this.bufferSize);
   frame=0;

   process($inputs)
   {
      var $cd=$inputs[0][0];
      var $cf=currentFrame;
      if(!$cd) return true;

      if(this.frame<$cf && $cf-this.frame<500000)
      {
         for(var $i=this.frame; $i<$cf; $i++)
         {
            this.buffer[this.written++]=0;
            if(this.written===this.bufferSize)
            {
               this.port.postMessage(this.buffer.slice(0, this.bufferSize));
               this.written=0;
            }
         }
      }
      this.frame=$cf+$cd.length;
      for(var $i=0, $c=$cd.length; $i<$c; $i++)
      {
         this.buffer[this.written++]=$cd[$i];
         if(this.written===this.bufferSize)
         {
            this.port.postMessage(this.buffer.slice(0, this.bufferSize));
            this.written=0;
         }
      }
      return true;
   }
}

registerProcessor('VAProcessor', RecorderProcessor);
               `;
         $data='data:text/javascript;base64,'+btoa($data);
         await $micAudioCtx.audioWorklet.addModule($data);
         $micRec=new AudioWorkletNode($micAudioCtx, 'VAProcessor');
         $micRec.port.onmessage=function($e){anyFunctionToProcessSamples($e.data);};

Firefox loses one sample (or a small amount) from microphone in random moments. For example during higher load or launching other applications. I need information that samples was lost and count of lost samples.


BTW. I won’t be able to respond to your questions. I reported it to Stack Overflow support without any reaction…

I will be a grateful for any advice also.