Search code examples
google-chromezoomingkioskpinch

Disable Chrome pinch zoom for use in kiosk


We are using Chrome in kiosk mode and accidentally users are causing the application to zoom with the recent addition of pinch zoom support. They then think they've broken it and simply walk away leaving the application (and subsequently a 55" touch screen) in a broken state.

Now the only thing to work has been stopping event propagation for touch events over 2 points. Issues with that are we can't do multitouch apps in that case and if you act fast the browser reacts before javascript. Which in our tests still happen on accident by users.

I've done the Meta tags, they do not work. Honestly I wish I could disable chrome zooming at all but I cant find a way to do that.

How can I stop the browser from zooming?


Solution

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