Disable Chrome pinch zoom for use in kiosk - google-chrome

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?

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)

As of Version 51.0.2704.84 m, chrome://flags/#touch-events disables all the touch-events not only the pinch function. FYI. Hopefully, Google will return this functionality in future release.

Related

Chrome Inspector - Dimensions removed?

Does anyone else have the problem that since yesterday in Chrome the dimensions of the browserwindow aren't shown anymore?
Could this come from an Chrome Update or is it a problem only of my browser?
I find this issue to. Because I use it every day it's critical for me. This may help you:
https://gist.github.com/mrpapercut/7a004210306b62dcf813
But I think it's just a f***up and they roll back it soon.
In version 48.0.2564.116 the dimensions are shown in the page only while I am actively resizing the window with the developer tools open -- they disappear after a short delay. Version 49.0.2623.87 (current as I post this) removes this tooltip.
You can force the dimensions to be visible at all times by turning on "Device Mode" (the iPhone-looking button second from the left in the developer toolbar.)

Google Chrome Developer Tools - Disable the new device emulation ruler without turning off emulation

As many others, I also want to get rid of the new device emulation ruler in Chrome/Chromium Dev Tools.
But I still want to keep device emulation, because I need to have the website I work on at a specific resolution (more exactly at a specific width). However the rulers are just a distraction most of the time, and the interface is occupying valuable vertical screen space.
Unfortunately you can't at this time.
Thanks for the feedback though. We're working on a solution for hiding much of the UI when not needed – most likely, we'll start with a 'mini' mode that makes the rulers smaller and collapses emulation into a single row.
Work in progress can be seen here: https://code.google.com/p/chromium/issues/detail?id=409607 (also the best place for further feedback)

Disable grid in chrome device emulation

I know this question may not fit well here but this really is driving me crazy for few hours now :( I use chrome to simulate how websites look on different mobile devices. I clicked something wrong that led to a grid with rulers to appear. I don't know WTF to do to disable this grid. This is the screenshot:
I uninstalled and reinstalled the browser and it returns back.
I reset the developer tools to default settings and it's still there.
This is really becoming a nightmare for me for few hours now. I want the regular emulation without these rulers and grid and top bar. Thanks
There is a small blue button on the left of Elements which actually does the magic.
You didn't click anything wrong. Your Chrome updated itself to 38.2125 and the emulator now has those attributes. Further more, the touch function is broken.
To fix the problem, download the "Canary" version of Chrome. You're still required to see the grid, but the screen is improved and easier to see your layout. Also, the touch function is fixed.
Get Chrome Canary here: https://www.google.com/intl/en/chrome/browser/canary.html
That button just enables/disables the emulator. The OP is looking for a way to disable the background grid while emulating mobile devices.
If you're looking to disable the multi-colored grid lines that show up as an overlay, check out the console dock on the bottom of dev tools. There is a tab labeled rendering and try disabling "Show composited layer borders". If you're still seeing the rulers, that setting is in the Settings (gear) of dev tools, there is an option under the Elements heading for "Show rulers".

Disable zooming on page in chrome

For a HTML game I want to disable the normal zooming functionality in Chrome.
This question talks about how to use the viewport meta tag to disable zoom in Chrome on Android but this does not seem to work in normal desktop chrome.
While this doesn't answer my original question (I asked about a page displayed in Chrome) I just wanted to document that Chromium (the OSS behind Chrome) seems to have a flag which controls whether it will support the viewport meta tag:
// Enables the use of the viewport meta tag, which allows
// pages to control aspects of their own layout. This also turns on touch-screen
// pinch gestures.
const char kEnableViewport[] = "enable-viewport";
(soure: http://src.chromium.org/svn/trunk/src/content/public/common/content_switches.cc)
So, if packaging the game into its own chromium instance is an option (which in my case is likely), zooming could be disabled via the viewport meta tag.

Pinch-to-zoom as scroll wheel in web browser

I have a Windows 7 tablet (an ASUS EP121), and I am using a web browser to display a Google Maps-based web application that I have created. Basically, I want the pinch gesture to zoom the Google Map (similar to using the scroll wheel to zoom a Google Map when using a mouse), rather than zooming the entire web page.
In Opera, Firefox, and Chrome, the pinch gesture simply zooms in the entire page. This behavior makes perfect sense for most use cases, but I'm wondering if there is any setting, in any of these browsers (e.g., Opera, FF, Chrome) that can cause the pinch gesture to behave like a mousewheel instead of zooming in the entire page?
Interestingly enough, in Arora, the pinch gesture can be used to zoom in/out a Google Map; however, other issues are preventing me from using Arora effectively that I think will be more difficult to address than the issues I am raising in this question.
Another option would be to disable pinch gestures (I know this is possible in Firefox, I'm sure the other browsers have some means to do the same), and then try to let the application take care of it. Are there any thoughts on going this route? Would something like jQuery mobile be able to accomplish this?
As a last resort, I could use Qt's webkit and implement my own event handling (basically creating a stripped down Arora), but I'm really hoping there's an easier way that utilizes currently available browsers.
Thanks.
If anyone ever runs into the same problem that I had here, I have created a very simple WebKit-based web browser using Qt that implements a pinch gesture and uses it to fire off a scroll wheel event.
It works quite well (especially for Google Maps) and the source is available on github here. I've tested the code on Windows 7 and Ubuntu Linux 12.04; it works without any problems.