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

Prevent links in standalone web apps opening Mobile Safari #3835

Closed
sebastianbenz opened this issue Jun 29, 2016 · 11 comments · Fixed by #23844

Comments

@sebastianbenz
Copy link
Collaborator

commented Jun 29, 2016

The default behavior for iOS web apps in standalone mode to open links in mobile safari and leave the standalone modus. This is unwanted behavior for AMP sites in standalone mode.

How do we reproduce the issue?

  1. Add https://ampbyexample.com to the homescreen on an iOS device
  2. Launch the website from the homescreen
  3. Click on the Github link -> mobile safari opens (expected behavior)
  4. Click on a ABE sample link -> mobile safari opens (unwanted behavior - we should stay in the standalone webapp mode)

Suggestion

Detect iOS standalone mode and open links via document.location.href = ... if within the same domain.

Considerations

This might be unwanted behavior. We could make this optional by extracting this into a separate component (e.g. amp-web-app) + introducing an opt-out flag for links.

@cramforce

This comment has been minimized.

Copy link
Member

commented Jun 29, 2016

Do we do anything special with these links right now?

@mkhatib

This comment has been minimized.

Copy link
Contributor

commented Jun 29, 2016

I don't believe we are. The global document listener is only added on iframe'd documents. These don't look iframe'd.

We're sure this is not Safari's default behavior with standalone web apps? Will test this out a bit and see what's happening.

@mkhatib mkhatib added this to the Current milestone Jun 29, 2016

@mkhatib

This comment has been minimized.

Copy link
Contributor

commented Jun 29, 2016

Ok, just created this jsbin to test this out - try adding it to homescreen and open it from there. It does seem iOS opens links in Safari regardless (tried setting target=_self or target=_top but it still opens them in Safari when in standalone.

@sebastianbenz do you have an example where this is not happening and instead links are navigated in the standalone page?

@sebastianbenz

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 29, 2016

This is actually the normal behavior in Safari. The workaround I've linked is a common approach to work around this behavior.

@PaulKinlan

This comment has been minimized.

Copy link

commented Jun 29, 2016

I wrote this a short while ago to handle a lot of the edge cases for what iOS does in standalone mode. https://gist.github.com/PaulKinlan/d66f777f5bde04926f29fc5c7ff345e7

It handles the entry point (useful for unifying with manfiest) and it also redirects the user back to the page they were last on when it navigates outside the standalone experience (this is useful because external URL's to the current site should really open up a new window and not reuse the current window)

@mkhatib

This comment has been minimized.

Copy link
Contributor

commented Jun 29, 2016

Ah I see. I totally misread this at first - rereading the issue clarify what you meant. Thanks both! We could definitely use the global click handler in AMP to make sure this happens. Thanks for the links.

@cramforce I think we should do this for sure for same-origin or relative links, let me know what do you think.

@cramforce

This comment has been minimized.

Copy link
Member

commented Jun 29, 2016

SGTM

@cramforce

This comment has been minimized.

Copy link
Member

commented Feb 8, 2017

I suppose we can close in favor of #3861

@cramforce cramforce closed this Feb 8, 2017

@sebastianbenz

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 8, 2017

@cramforce #3861 describes a related but different problem. Both require different fixes.

@adelinamart

This comment has been minimized.

Copy link
Contributor

commented Feb 22, 2018

@sebastianbenz is this needed? Thanks.

@sebastianbenz

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.