npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

add-to-homescreen-fork-scaliebe

v1.0.1

Published

A simple JavaScript library to show a popup encouraging users to add a website to their home screen.

Downloads

16

Readme

add-to-homescreen 📱

Motivation

Adding to home screen allows mobile websites and PWA's to open like native apps without registering in the Apple or Google App Stores. Currently, it is very difficult to get users to add web apps to their home screen, limiting the utility of mobile websites compared to native apps. See related Medium blog post.

This Library

This drop-in JS Library for mobile websites effectively guides a user to add the website to their home screen on both IOS and Android. Instructions and UI in this library have been "battle-tested" and has yielded an ~85% home screen install rate on IOS and Android across all ages in past implementations.

Here is a demo (please open on your phone) of library use within a hypothetical app "Aardvark"

261203234-855108a0-e0ed-4213-8789-76d59345dd46 (1)

Browser Support

All major browsers on IOS and Android are supported. Here are the guides shown for each platform/browser:

IOS - Safari browser

IOS - Chrome browser

Android - Chrome browser

Browser Fallback Support

All major browsers on IOS and Android are supported, but in the edge case of a non-compliant or desktop browser, a message is shown to redirect the user to a supported browser. (This feature can be toggled on/off using the showErrorMessageForUnsupportedBrowsers flag.)

Desktop users

In-App Browsers

Facebook and Linkedin in-app browsers on IOS and Android

User is guided to open the link in the system browser.

Twitter, Instagram and Threads in-app browsers on IOS

These apps all use SFSafariViewController and can be handled similarly.

iPhone users not on Safari or Chrome or in-app browser

Android users not on Chrome or in-app browser

Installation

Prerequisite

Make sure your site has the minimum requirements for installing a web app on homescreen for IOS and Android.

  1. At https://your-website.com/apple-touch-icon.png, include a square icon of your app that is (1) at least 40 x 40 pixels and (2) specifically named apple-touch-icon.png(example).

  2. At https://your-website.com/manifest.json, include a web manifest file manifest.json (example). Reference the manifest in your index HTML file.

    index.html

    <head>
    ...
    <link rel="manifest" href="manifest.json">
    ..
    </head>

Usage (If you're not making changes to library)

This should be a quick drop-in library into your mobile website.

  1. Include the library JavaScript and CSS files in your header (You can use JSDelivr CDN if you're just using the library directly and not making any changes):

    index.html

    <head>
    ...
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/philfung/[email protected]/dist/add-to-homescreen.min.css">
    <script src="https://cdn.jsdelivr.net/gh/philfung/[email protected]/dist/add-to-homescreen.min.js"></script>
    ...
    </head>
  2. Call the library onload.

    index.html

    <script>
    document.addEventListener('DOMContentLoaded', function () { // document.getElementById('addToHomeScreen').addEventListener('click', function () and add <button id="addToHomeScreen">Add to Home Screen</button> somewhere on your page to get a button instead.
    
     window.AddToHomeScreenInstance = new window.AddToHomeScreen({
      appName: 'Aardvark',                                   // Name of the app.
                                                             // Required.
      appIconUrl: 'apple-touch-icon.png',                    // App icon link (square, at least 40 x 40 pixels).
                                                             // Required.
      assetUrl: 'https://cdn.jsdelivr.net/gh/philfung/[email protected]/dist/assets/img/',  // Link to directory of library image assets.
                                                                                                // Required. 
      showErrorMessageForUnsupportedBrowsers: window.AddToHomeScreen.SHOW_ERRMSG_UNSUPPORTED.ALL, // Show an error message if add-to-home-screen is not supported for this browser
                                                                                                  // (e.g.  "adding to home screen is not supported in IOS Firefox, please open this [website] in IOS Safari instead." or "adding to home screen is not supported on desktop, please open this [website] in your mobile browser instead".  You can also set more granular permissions to show error messages only on mobile browsers and not on desktop browsers, etc)
                                                                                                  // Optional. Default: window.AddToHomeScreen.SHOW_ERRMSG_UNSUPPORTED.ALL 
      allowUserToCloseModal: false,                          // Allow user to close the 'Add to Homescreen' message? Not allowing will increase installs.
                                                             // Optional. Default: false.
      maxModalDisplayCount: -1                               // If set, the modal will only show this many times.
                                                             // Optional. Default: -1 (no limit).  (Debugging: Use this.clearModalDisplayCount() to reset the count)
    });
             
     ret = window.AddToHomeScreenInstance.show();             // show "add-to-homescreen" instructions to user, or do nothing if already added to homescreen
    });
    </script>
    </body>

Here's an example implementation.

Usage (If you're making changes to library)

Build the library:

npm run build

Test locally:

npm start

Next, save the dist directory to a CDN of your choice. Follow the steps in the previous section.

Dependencies

No dependencies. This is written in raw ES6 javascript and all css is namespaced to minimize codebase conflict and bloat.

License

License: MIT

Todos

  • [ ] Bug: Fix browser instructions:
    • Android
      • [ ] Edge
  • [ ] Bug: Fix in-app browser detection:
    • IOS
      • [ ] Reddit
      • [ ] Google App
      • [ ] Medium App
    • Android
      • [ ] Twitter
      • [ ] LinkedIn
      • [ ] Threads
      • [ ] Instagram
      • [ ] Reddit
      • [ ] Google App
      • [ ] Medium App