Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mobile-viewport-control

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobile-viewport-control

Dynamically control the mobile viewport

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20
decreased by-16.67%
Maintainers
1
Weekly downloads
 
Created
Source

Mobile Viewport Control

On mobile browsers, Apple set a non-standardized precedent of controlling the viewport with one or more meta tags:

<meta name="viewport" content="name=value,name=value,...">

See Quirksmode for more context: 1, 2

The goal of this project is to see if we can use these tags to dynamically modify the viewport at runtime. Specifically, we want to freeze the viewport at some zoom level, then restore the viewport later.

Generally, a user should be able to pinch-zoom a page. But for things like popup modals, the user experience is better if the viewport is preset like a native app.

Usage

npm install mobile-viewport-control
const viewport = require('mobile-viewport-control');
// ... or use `window.mobileViewportControl` if not used with package manager


// Freeze the viewport at a desired scale.
viewport.freeze(1.0, () => console.log("notified when frozen!"));

// Restore the viewport to what it was before freezing.
viewport.thaw(() => console.log("notified when thawed!"));

Compatibility

Compatibility is measured with a combination of automatic/manual testing:

  1. Measure Test - verify that we can measure the current viewport scale.
  2. Freeze Test - verify that we can set and freeze the viewport scale.
  3. Manual step - pinch-zoom before starting the test
  4. Manual step - verify that you cannot pinch-zoom after the test
  5. Thaw Test - verify that we can restore the viewport scale and bounds.
  6. Manual step - pinch-zoom before starting the test
  7. Manual step - verify that you can still pinch-zoom after the test
Mobile BrowserMeasure Test*Freeze TestThaw Test
iOS SafariYYY
iOS UIWebViewYFails if user pinch-zooms before freezing**Y if freeze succeeds.
iOS WKWebViewYYY
iOS SFSafariViewControllerYYY
iOS ChromeYYY
iOS FirefoxYYY
iOS Opera MiniYFails if user pinch-zooms before freezing**Y if freeze succeeds.
Android Browser (Stock)???
Android ChromeYYY
Android WebViewYYY
Android Chrome Custom TabsYYY
Android FirefoxYFailsFails
Android Opera MiniFailsFailsFails

* This test fails in the iOS Simulator because initial-scale is ignored there for wide pages for some reason.

** Pinch-zooming causes the page's scale to change from its specified initial-scale. This custom zoom level is maintained across refreshes. When opening in a new tab, the initial-scale is resumed.

Variables

We currently do not test all variables, but the test outcomes depend on the following:

  • browser/platform
  • page width (modify in test.css)
  • screen orientation (portrait or landscape)
  • refresh delay (for viewport changes to take effect)
  • initial zoom, influenced by either of:
    • default zoom specified in initial-scale
    • manual zoom remembered before page refresh
    • manual zoom after page load and before test run
  • initial zoom bounds (controlled by page's original viewport meta tags)

License

ISC License

FAQs

Package last updated on 27 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc