Skip to content
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

Control the default behavior at the moment of completion of the installation #995

Open
hanguokai opened this issue Aug 17, 2021 · 6 comments

Comments

@hanguokai
Copy link
Member

(I originally posted this at manifest-incubations, then @dmurph suggested to post it here)

Currently, after installation of a PWA app, Chrome loads current page into the app automatically. But not all web pages in the origin should be loaded into the app. For example, the landing page of the app introduce the application and show an install button. After installation, the app should be launched with it's start_url, not current visited url.

The website should be able to control the default behavior after installation. For example:

  • don't launch the app after installation, stay on the current page, and supply a launchApp() method for developers.
  • launch the app with start_url (not current url), and stay on the current page
@marcoscaceres
Copy link
Member

This sounds like it might be a chrome bug/behavior?

@hanguokai
Copy link
Member Author

(I read the spec roughly. This behavior is not defined in the spec.)

This sounds like it might be a chrome bug/behavior?

It depends on how to solve the problem.

  • From the perspective of standard: there should be more explanations or notes for installation related behaviors.
  • From the perspective of browser implementation: after installation, browser can let the user manually launch the app, like installing a native app.
  • From the perspective of developers: browser can provide an API for developers to control this behavior. I initially considered from this perspective.

On desktop OS, I think chrome's current behavior is inappropriate. But developers have a workaround for it:

window.matchMedia('(display-mode: standalone)').addEventListener('change', (evt) => {
    if(evt.matches) { // display mode changed to 'standalone' after installation
        location.replace(start_url or other appropriate url);
    }
});

@dmurph
Copy link
Collaborator

dmurph commented Aug 30, 2021

Hm, that would false trigger in the following circumstances, but that might be wanted by the developer?

  • Using the 'open with' icon if the website is installed & open in a tab
  • Going from fullscreen back to standalone window (just using the fullscreen support)

But I think this is also, in a way, yes a feature of chrome. We re-parent the window contents, so that any current state is saved (all form controls, editing, etc).

So yeah - not sure how much of this is spec-land vs user-agent-land feature requests. But I could see a feature request about giving web apps more control over exactly what happens on install (what page is loaded). Not sure about privacy implications though... could make an easy fake windows login prompt

@hanguokai
Copy link
Member Author

that would false trigger in the following circumstances, but that might be wanted by the developer?

Yes, that workaround code is only used in pages that should never be opened in the (standalone display mode) app. To better understand, I made a simple PWA example, https://webvideoplayer.org/ . After installation from homepage(index.html), chrome load index.html into the app, and the workaround code change the page to player.html (the app itself). The code is only used in index.html, not in player.html.

I could see a feature request about giving web apps more control over exactly what happens on install (what page is loaded).

Yes, that’s what I filed this issue is about.

@dmurph
Copy link
Collaborator

dmurph commented Jul 21, 2023

Circling back - this should be possible to detect with the 'onappinstalled' event in Chrome, at which you can navigate the page.

In Safari - the start_url always loaded on launch after install I believe, so this isn't an issue there. @hanguokai does that approach work for you?

@hanguokai
Copy link
Member Author

In Safari - the start_url always loaded on launch after install I believe, so this isn't an issue there.

Yes, this is the behavior I expect in my use case.

this should be possible to detect with the 'onappinstalled' event in Chrome, at which you can navigate the page.

I read the chrome official article 2 years ago. But I didn't realize that this is a cancelable event from the article. Do you mean I should call the preventDefault() like below:

window.addEventListener('appinstalled', function(event) {
  event.preventDefault(); // cancel the default behavior, i.e. launch the app with current page
});

If so, after installation, I would like to turn the install button into the launch button, just like after installing an Android app in Google Play.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants