input-onmessage.js (930B)
1 // Responds to onmessage events from other frames to check for pending input. 2 onmessage = async e => { 3 if (e.data !== 'check-input') return; 4 5 const discreteOptions = { includeContinuous: false }; 6 const continuousOptions = { includeContinuous: true }; 7 8 // Use a reasonable time to wait after dispatching events, since we want to be 9 // able to test for cases where isInputPending returns false. 10 const DISPATCH_WAIT_TIME_MS = 500; 11 12 // Wait a reasonable amount of time for the event to be enqueued. 13 const end = performance.now() + DISPATCH_WAIT_TIME_MS; 14 let hasDiscrete; 15 let hasContinuous; 16 do { 17 hasDiscrete = navigator.scheduling.isInputPending(discreteOptions); 18 hasContinuous = navigator.scheduling.isInputPending(continuousOptions); 19 } while (performance.now() < end && !(hasDiscrete && hasContinuous)); 20 21 e.source.postMessage({ 22 discrete: hasDiscrete, 23 continuous: hasContinuous, 24 }, '*'); 25 }