New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 636274 link

Starred by 7 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug



Sign in to add a comment

navigator.share does not reject promise when user cancels picker

Project Member Reported by mgiuca@chromium.org, Aug 10 2016

Issue description

Version: 54
OS: Android L+

What steps will reproduce the problem?
(1) Run with --enable-experimental-web-platform-features.
(2) Call:
navigator.share({'text': 'test'}).then(() => console.log('success')).catch(e => console.error('failed:', e));
(3) Cancel the picker dialog.

What is the expected output?
Console error: "failed: user canceled picker"

What do you see instead?
Nothing happens. The promise is neither resolved nor rejected.

This is due to an apparently unsolvable problem on Android which is that the picker never broadcasts or calls a callback upon cancellation (only upon success). We don't have many great ideas for solving it. Two (bad) ideas are:
1. Re-implement the picker dialog ourselves,
2. A combination of detecting when the web view regains focus and waiting for a small amount of time to avoid races *shudder*.

We'll have to do one of the above unless someone gets a bright idea.
 

Comment 1 by mgiuca@chromium.org, Aug 10 2016

Description: Show this description
Project Member

Comment 2 by bugdroid1@chromium.org, Sep 7 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/06be389804f232f4e992be8e95b24322a1062ebb

commit 06be389804f232f4e992be8e95b24322a1062ebb
Author: mgiuca <mgiuca@chromium.org>
Date: Wed Sep 07 06:17:55 2016

WebShare: Fixed the API occasionally breaking on a particular page.

On Android, the WebShare Mojo pipe would occasionally be closed due to
the Java service dropping a callback without calling it. Now always
calls the callback.

Also partially fixes crbug.com/636274; previously the navigator.share
promise would not be rejected if the user cancels the picker. Now it is
rejected (though not immediately). This needs to be fixed better but at
least the promise will (eventually) be resolved or rejected.

BUG= 640324 ,636274

Review-Url: https://codereview.chromium.org/2307733003
Cr-Commit-Position: refs/heads/master@{#416862}

[modify] https://crrev.com/06be389804f232f4e992be8e95b24322a1062ebb/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
[modify] https://crrev.com/06be389804f232f4e992be8e95b24322a1062ebb/chrome/android/java/src/org/chromium/chrome/browser/webshare/ShareServiceImpl.java

The above CL partially resolves this issue. You will now *eventually* get a promise rejection if the user closes the picker (upon the next share attempt, globally). But it won't happen right away, so keeping this bug open.
Project Member

Comment 4 by bugdroid1@chromium.org, Sep 27 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/2a9911b41a53319b9b60a3624c8df34171315a53

commit 2a9911b41a53319b9b60a3624c8df34171315a53
Author: mgiuca <mgiuca@chromium.org>
Date: Tue Sep 27 08:57:49 2016

ShareHelper: Call onCancel when dismissed, in Kit Kat and earlier.

Previously, with the pre-Lollipop picker, onCancel was never called. Now
it is called immediately upon dismissing the dialog. In post-Lollipop,
there is still an ongoing issue where onCancel is not called immediately
upon closing the picker (it waits until the next share action); see
crbug.com/636274.

BUG= 646247 ,636274

Review-Url: https://codereview.chromium.org/2338683002
Cr-Commit-Position: refs/heads/master@{#421151}

[modify] https://crrev.com/2a9911b41a53319b9b60a3624c8df34171315a53/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java

Comment 5 by mgiuca@chromium.org, Sep 25 2017

 Issue 767817  has been merged into this issue.

Comment 6 by mgiuca@chromium.org, Nov 16 2017

Issue 765790 has been merged into this issue.

Comment 7 by mgiuca@chromium.org, Apr 27 2018

Issue 834316 has been merged into this issue.
Cc: tedc...@chromium.org
+tedchoc (I just sent you a private mail about this).
Cc: -tedc...@chromium.org mgiuca@chromium.org
Owner: tedc...@chromium.org
The bulk of the relevant code (on the Android side) is:
https://cs.chromium.org/chromium/src/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java

Start in ShareHelper.share(); the intent is fired in TargetChosenReceiver.sendChooserIntent. Note that there is a major fork based on whether the device is Lollipop MR1 or above (send a chooser intent) or earlier (manually show a picker inside Chrome, then send an intent to the chosen app). The bug only manifests in the MR1-or-above case.

ShareHelper.share() is called by:
https://cs.chromium.org/chromium/src/chrome/android/java/src/org/chromium/chrome/browser/webshare/ShareServiceImpl.java

You can manually test the whole API using:
http://wicg.github.io/web-share/demos/share.html

Sign in to add a comment