-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PWA] Installation guide #25058
[PWA] Installation guide #25058
Conversation
Preview URLs External URLs (5)URL:
(comment last updated: 2023-03-08 00:45:51) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few typos
files/en-us/web/progressive_web_apps/guides/installation/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/progressive_web_apps/guides/installation/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/progressive_web_apps/guides/installation/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/progressive_web_apps/guides/installation/index.md
Outdated
Show resolved
Hide resolved
Co-authored-by: dawei-wang <dawei-wang@users.noreply.github.com>
This technique relies on the [`beforeinstallprompt`](/en-US/docs/Web/API/Window/beforeinstallprompt_event) event, which is fired on the global [`Window`](/en-US/docs/Web/API/Window) object as soon as the browser has determined that the PWA is installable. A PWA can: | ||
|
||
- add a UI element for the user to install the PWA (for example, its own "Install" button) | ||
- listen for the `beforeinstallprompt` event | ||
- cancel the event's default behavior by calling [`preventDefault()`](/en-US/docs/Web/API/Event/preventDefault) | ||
- keep a reference to the [`BeforeInstallPromptEvent`](/en-US/docs/Web/API/BeforeInstallPromptEvent), and in the event handler for its own "Install" button, call the [`BeforeInstallPromptEvent.prompt()`](/en-US/docs/Web/API/BeforeInstallPromptEvent/prompt) method. This method will show the browser prompt that asks the user if they want to install the PWA. | ||
|
||
For example: | ||
|
||
```js | ||
window.addEventListener("beforeinstallprompt", (event) => { | ||
// Don't let the default prompt go. | ||
event.preventDefault(); | ||
|
||
// Instead, wait for the user to click the install button. | ||
installButton.addEventListener("click", () => event.prompt()); | ||
}); | ||
``` | ||
|
||
The `prompt()` method returns a {{jsxref("Promise")}} that resolves with a string `"accepted"` or `"dismissed"` indicating whether or not the user chose to install the PWA. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this is too instructional and belongs in a How-to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we have the custom install flow as part of the How-To section in our shared doc. Maybe it can be here too, only shorter? In any case, we should link to the How-To here, once it exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I'll keep something here but remove the sample code. Later on we can add links to the How-to pages for the details.
Once the PWA is installed its icon is shown on the device alongside any other apps that the user has installed, and clicking the icon launches the app. | ||
|
||
You can use the [`display`](/en-US/docs/Web/Manifest/display) manifest key to control the _display mode_: that is, how the PWA appears when it is launched. In particular: | ||
|
||
- `"standalone"` indicates that the PWA should look and feel like a platform-specific application, with no browser UI elements | ||
- `"browser"` indicates that the PWA should be opened as a new browser tab or window, just like a normal website. | ||
|
||
If the browser does not support a given display mode, `display` will fall back to a supported display mode according to a predefined sequence. The [`display_override`](/en-US/docs/Web/Manifest/display_override) enables you to redefine the fallback sequence. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an OK level of detail, and we could link to the How-to for specific instructions and example code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that's a good idea. Let's add the link when we can with a leading sentence like "For more information about the various display modes and how they fallback, see ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it. I left a few minor comments, but overall this looks like great content.
files/en-us/web/progressive_web_apps/guides/installation/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/progressive_web_apps/guides/installation/index.md
Outdated
Show resolved
Hide resolved
|
||
For a full description of every key, see the [web app manifest reference documentation](/en-US/docs/Web/Manifest). | ||
|
||
### Additional installability requirements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTPS and service worker are both, for now, required by all browsers to consider an app as installable. Together with manifest, these 3 criteria have been part of the PWA's DNA from the start, and I think they should each have an h3-level section like the one you used for manifest.
|
||
If the PWA has more than one page, every page must reference the manifest in this way. | ||
|
||
The manifest contains a single JSON object containing a collection of keys, each of which defines some aspect of the PWA's appearance or behavior. Here's a rather minimal manifest, containing just two keys: `"name"` and `"icons"`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In manifest language, we call the top-level properties members
, not keys
. Using members here would make things consistent with specs and other docs out there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, looking at your how-to last week I was going to complain that you use "members" instead of "keys" but then I saw that was what the spec (and most of the MDN manifest reference) uses. So yes.
On mobile: | ||
|
||
- Firefox, Chrome, Edge, Opera, and Samsung Internet Browser all support installing PWAs on Android. | ||
- Only Safari is allowed to install PWAs on iOS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this will change with the latest version of webkit. See https://webkit.org/blog/13878/web-push-for-web-apps-on-ios-and-ipados/ and search for "Third-party browser support for Add to Home Screen".
This technique relies on the [`beforeinstallprompt`](/en-US/docs/Web/API/Window/beforeinstallprompt_event) event, which is fired on the global [`Window`](/en-US/docs/Web/API/Window) object as soon as the browser has determined that the PWA is installable. A PWA can: | ||
|
||
- add a UI element for the user to install the PWA (for example, its own "Install" button) | ||
- listen for the `beforeinstallprompt` event | ||
- cancel the event's default behavior by calling [`preventDefault()`](/en-US/docs/Web/API/Event/preventDefault) | ||
- keep a reference to the [`BeforeInstallPromptEvent`](/en-US/docs/Web/API/BeforeInstallPromptEvent), and in the event handler for its own "Install" button, call the [`BeforeInstallPromptEvent.prompt()`](/en-US/docs/Web/API/BeforeInstallPromptEvent/prompt) method. This method will show the browser prompt that asks the user if they want to install the PWA. | ||
|
||
For example: | ||
|
||
```js | ||
window.addEventListener("beforeinstallprompt", (event) => { | ||
// Don't let the default prompt go. | ||
event.preventDefault(); | ||
|
||
// Instead, wait for the user to click the install button. | ||
installButton.addEventListener("click", () => event.prompt()); | ||
}); | ||
``` | ||
|
||
The `prompt()` method returns a {{jsxref("Promise")}} that resolves with a string `"accepted"` or `"dismissed"` indicating whether or not the user chose to install the PWA. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we have the custom install flow as part of the How-To section in our shared doc. Maybe it can be here too, only shorter? In any case, we should link to the How-To here, once it exists.
|
||
### Customizing installation | ||
|
||
By default, the install prompt contains the name and icon for the PWA. If you provide values for the [`description`](/en-US/docs/Web/Manifest/description) and [`screenshots`](/en-US/docs/Web/Manifest/screenshots) manifest keys, then, on Android only, these values will be shown in the install prompt, giving the user extra context and motivation to install the PWA. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, the install prompt contains the name and icon for the PWA. If you provide values for the [`description`](/en-US/docs/Web/Manifest/description) and [`screenshots`](/en-US/docs/Web/Manifest/screenshots) manifest keys, then, on Android only, these values will be shown in the install prompt, giving the user extra context and motivation to install the PWA. | |
By default, the install prompt contains the name and icon for the PWA. If you provide values for the [`description`](/en-US/docs/Web/Manifest/description) and [`screenshots`](/en-US/docs/Web/Manifest/screenshots) manifest members, then, on Android only, these values will be shown in the install prompt, giving the user extra context and motivation to install the PWA. |
(probably worth doing a search/replace on the entire document for keys->members).
Also, I think Chrome for desktop now also uses screenshots and description. I definitely saw it a few months ago, but now it seems disabled. So I think they're working on it behind a flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, when I tested last week it didn't seem to be supported in Chrome desktop. I think compat is challenging in this project, and we should have a separate compat page where we document all such issues.
Once the PWA is installed its icon is shown on the device alongside any other apps that the user has installed, and clicking the icon launches the app. | ||
|
||
You can use the [`display`](/en-US/docs/Web/Manifest/display) manifest key to control the _display mode_: that is, how the PWA appears when it is launched. In particular: | ||
|
||
- `"standalone"` indicates that the PWA should look and feel like a platform-specific application, with no browser UI elements | ||
- `"browser"` indicates that the PWA should be opened as a new browser tab or window, just like a normal website. | ||
|
||
If the browser does not support a given display mode, `display` will fall back to a supported display mode according to a predefined sequence. The [`display_override`](/en-US/docs/Web/Manifest/display_override) enables you to redefine the fallback sequence. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that's a good idea. Let's add the link when we can with a leading sentence like "For more information about the various display modes and how they fallback, see ..."
Note that this new page should also replace https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Add_to_home_screen (we should check if there's more content on the A2HS page that needs to be saved). |
Co-authored-by: Patrick Brosset <patrickbrosset@gmail.com>
|
||
### HTTPS | ||
|
||
For a web app to be installable, it must be served over HTTPS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth mentioning something like: "For local development purposes, browsers do not require HTTPS if the web app is accessed via the localhost
domain".
files/en-us/web/progressive_web_apps/guides/installation/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/progressive_web_apps/guides/installation/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/progressive_web_apps/guides/installation/index.md
Outdated
Show resolved
Hide resolved
files/en-us/web/progressive_web_apps/guides/installation/index.md
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,142 @@ | |||
--- | |||
title: Installation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One additional comment: how about making this a bit longer and more explicit? I wonder if enough people will get the context from the URL and breadcrumbs on the page. I think a more self-explanatory title might be helpful. Something like "Making PWAs installable".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I love this title but I couldn't think of anything better :).
Co-authored-by: Patrick Brosset <patrickbrosset@gmail.com>
Co-authored-by: Patrick Brosset <patrickbrosset@gmail.com>
Co-authored-by: Patrick Brosset <patrickbrosset@gmail.com>
Part of mdn/mdn#280.
This PR adds a guide page to PWA installation. It will replace https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Installing.
Some notes and things.
@captainbrosset , @estelle .