Disable Chrome pinch zoom for use in kiosk

We've had a similar problem, it manifests as the browser zooming but javascript receiving no touch event (or sometimes just a single point before zooming starts).

We've found these possible (but possibly not long-term) solutions:

1. Disable the pinch / swipe features when using kiosk mode

If these command-line settings remain in Chrome, you can do the following:

chrome.exe --kiosk --incognito --disable-pinch --overscroll-history-navigation=0
  • --disable-pinch - disables the pinch-to-zoom functionality
  • --overscroll-history-navigation=0 - disables the swipe-to-navigate functionality

2. Disable pinch zoom using the Chrome flags chrome://flags/#enable-pinch

Navigate to the URL chrome://flags/#enable-pinch in your browser and disable the feature.

The pinch zoom feature is currently experimental but turned on by default which probably means it will be force-enabled in future versions. If you're in kiosk mode (and control the hardware/software) you could probably toggle this setting upon installation and then prevent Chrome updates going forward.

There is already a roadmap ticket for removing this setting at Chromium Issue 304869.

The fact that the browser reacts before javascript can prevent it is definitely a bug and has been logged at the Chromium bug tracker. Hopefully it will be fixed before the feature is permanently enabled or fingers-crossed they'll leave it as a setting.

3. Disable all touches, whitelist for elements and events matching your app

In all tests that we've conducted, adding preventDefault() to the document stops the zooming (and all other swipe/touch events) in Chrome:

document.addEventListener('touchstart', function(event){
    event.preventDefault();
}, {passive: false});

If you attach your touch-based functionality higher up in the DOM, it'll activate before it bubbles to the document's preventDefault() call. In Chrome it is also important to include the eventListenerOptions parameter because as of Chrome 51 a document-level event listener is set to {passive: true} by default.

This disables normal browser features like swipe to scroll though, you would probably have to implement those yourself. If it's a full-screen, non-scrollable kiosk app, maybe these features won't be important.


html {
  touch-action:none;
}

This will disable browser handling of all panning and zooming gestures. The gesture will still be available for handling by javascript code.

https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action


Just so anyone stumbling across this page is aware the flag in Chrome to disable 'pinch to zoom' is now:

Google Chrome/Chromium/Canary version above 50:

chrome://flags/#touch-events

Google Chrome/Chromium/Canary version less then 50 or old versions:

chrome://flags/#enable-pinch.


I'm dealing with the same issue. I think I can handle it reasonably well with the following approach

  • determine the css pixel width of the html element: document.documentElement.clientWidth
  • compare this measurement to the known pixel width of the kiosk screen
  • if the html element is wider, in css pixels than the screen is, in physical pixels, that means it's scaled
  • if the html element is scaled, apply a zoom to the body element to compensate. The formula is `body.style.zoom = htmlElementClientWidth / screenPhysicalPixelWidth

This techique has the beneficial side effect of automatically scaling the UI to whatever size the current window is, which is helpful for development if I'm developing on a screen smaller than the target screen.

More on screen pixels vs css pixels, and a discussion of how the html element expands to fill the available space at quirksmode.org.


Another solution that currently works in Chrome (54) is to add an event listener for the 'touchstart' event and call preventDefault() based on the length of the targetTouches or touches on the event.

This solution prevents a pinch (any two fingered gesture for that matter), but still provides flexibility with how you want to respond to the event. It's a nice solution because it doesn't require you to disable touch events altogether (as required if you want to disable pinch using the chrome flags, since chrome://flags/#enable-pinch no longer exists).

window.addEventListener('touchstart', function(e) {
  if (e.targetTouches.length === 2) {
    e.preventDefault();
  }
}, false);
Some text that you can't pinch zoom on Chrome (tested in 54)