MicrosoftEdge / MSEdgeExplainers

Home for explainer documents originated by the Microsoft Edge team
Creative Commons Attribution 4.0 International
1.29k stars 205 forks source link

[Web Install] Including computed manifest id in the API #669

Closed dmurph closed 7 months ago

dmurph commented 1 year ago

We often deal with issues where things a much harder in the user agent when given an install_url without knowing the manifest_id, and it often causes issues for admins who think they are installing X at a given install url, but things are set up correctly and it installs Y.

User agents also then are able to know things right away, like if the user has already installed that app, without needing to load the url, fetch manifest, etc.

So I would really recommend that the API includes both an install_url AND a manifest_id, allowing the caller to be extra specific about what they want, and for applicable errors to be given back to them (e.g. "The app you specified does not exist at that url")

diekus commented 1 year ago

@dmurph this is a great idea.

are you thinking something like adding the id as a param? Like the code below?

manifest file:

"id": "foo"

js file:

navigator.install('https://contoso.com', {id: 'foo'});

So if https://contoso.com can't be found as an installable app, then it'd check against installing https://contoso.com/foo ?

dmurph commented 1 year ago

I would want it required & the first argument: navigator.install('https://contoso.com/foo', 'https://contoso.com')

"Please install X, and you can find it at Y"

dmurph commented 1 year ago

Or if you want named arguments: navigator.install('https://contoso.com/foo', {install_url: 'https://contoso.com'});

Another way to think about this - urls change. The manifest id never changes.

dmurph commented 1 year ago

Some more context - this is hugely helpful in the following scenarios:

dmurph commented 10 months ago

Here is a better doc with my suggestion: https://bit.ly/web-install-api-shape-install-url

diekus commented 10 months ago

Hola @dmurph

We intend to make all web content installable through the API, and I believe that the proposal of having a manifest id and installURL as a best case ideal scenario is accurate.

I think both same-origin and cross-origin installs would work the same. They would have 2 shared signatures of the install method of the shape:

navigator.install(<manifest_id>, {installURL: <install url>}); (desired ideal case) navigator.install(<manifest_id>); (no installURL exists, method can be called with the manifest_id and this will follow the default fallback chain => installURL>start_url>document url)

there's also a shorthand no params version that applies to the same-origin installs that takes all default values for manifest_id and installURL, so a developer could do:

navigator.install(); and this would trigger: navigator.install(<doc url>, {installURL:<docURL>}); (in this case the app id will be the same as the document url)

In order to mitigate the issues with a developer updating a site/app with a new manifest_id then we propose a new API that allows an installed app to retrieve its id value. This would make it possible to compare ids and the developer would be able to show a message to "update" the app. This is similar behaviour to that of platform specific apps.

navigator.appId or navigator.getAppId() on installed web content.

dmurph commented 10 months ago

Based on all of the problems & footguns that can occur without having the manifest_id at API call time, I still strongly prefer requiring that.

Same-page install seems "less bad" to not have it, as the browser doesn't have to do more fetches to get that if it was already loaded. But - doesn't seem bad to still require it.

I had to create a another similar doc for our policy team for force-install w/o and manifest id, and why they should try to migrate to always having the manifest id: https://bit.ly/unvalidated-pwa-url-installation

diekus commented 8 months ago

@dmurph @amandabaker @HowardWolosky take a look at #716. This should address computed manifest_id and install_url.