From 5360e65ee933e0749366536145acbf750f871be3 Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Tue, 25 Aug 2020 08:51:00 -0700 Subject: [PATCH] setPointerCapture/releasePointerCapture exception handling --- src/mousetracker.js | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 5bb32655..ba8116e4 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -1620,12 +1620,18 @@ if ( $.MouseTracker.havePointerCapture ) { if ( $.MouseTracker.havePointerEvents ) { - if ( $.MouseTracker.unprefixedPointerEvents ) { - tracker.element.setPointerCapture( gPoint.id ); - //$.console.log('element.setPointerCapture() called'); - } else { - tracker.element.msSetPointerCapture( gPoint.id ); - //$.console.log('element.msSetPointerCapture() called'); + // Can throw InvalidPointerId + // (should never happen for setPointerCapture so we'll log a warning) + try { + if ( $.MouseTracker.unprefixedPointerEvents ) { + tracker.element.setPointerCapture( gPoint.id ); + //$.console.log('element.setPointerCapture() called'); + } else { + tracker.element.msSetPointerCapture( gPoint.id ); + //$.console.log('element.msSetPointerCapture() called'); + } + } catch ( e ) { + $.console.warn('setPointerCapture() called on invalid pointer ID'); } } else { tracker.element.setCapture( true ); @@ -1674,12 +1680,19 @@ if ( $.MouseTracker.havePointerCapture ) { if ( $.MouseTracker.havePointerEvents ) { - if ( $.MouseTracker.unprefixedPointerEvents ) { - tracker.element.releasePointerCapture( gPoint.id ); - //$.console.log('element.releasePointerCapture() called'); - } else { - tracker.element.msReleasePointerCapture( gPoint.id ); - //$.console.log('element.msReleasePointerCapture() called'); + // Can throw InvalidPointerId + // (can happen depending on browser event timing (Firefox touch) + // so we won't log a warning) + try { + if ( $.MouseTracker.unprefixedPointerEvents ) { + tracker.element.releasePointerCapture( gPoint.id ); + //$.console.log('element.releasePointerCapture() called'); + } else { + tracker.element.msReleasePointerCapture( gPoint.id ); + //$.console.log('element.msReleasePointerCapture() called'); + } + } catch ( e ) { + /* eslint-disable no-empty */ } } else { tracker.element.releaseCapture();