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

Deal with user gesture limitations (permissions.request(), sidePanel.open()) #7327

Closed
fregante opened this issue Jan 12, 2024 · 5 comments · Fixed by #7471
Closed

Deal with user gesture limitations (permissions.request(), sidePanel.open()) #7327

fregante opened this issue Jan 12, 2024 · 5 comments · Fixed by #7471
Assignees
Labels
mv3 sidebar user experience Improve the user experience (UX)

Comments

@fregante
Copy link
Contributor

Continuing from #7237 (comment)

Some APIs like sidePanel.open() and permission.request() requires a "user gesture", which means they can only be called after the user clicks or types somewhere.

We have code that takes care of a similar limitation around the Clipboard API and I think we can write a utility simplify user gesture capture.

Proposal

function withUserGesture(message, fn) {
  try {
    await fn();
  } catch (error) {
    if (!isUserGestureError(error)) {
      throw error
    }
    const button = <button>{message}</button>;
    document.append(button);
    await oneEvent(button, 'click');
    button.remove();
    await fn();
  }
}

withUserGesture('Click anywhere to continue', async () => {
  await chrome.sidePanel.open()
});

This would be particularly for the sidePanel API (and the "open sidebar" brick) in MV3, so I'll tag this ticket as MV3/sidebar.

@fregante fregante added user experience Improve the user experience (UX) mv3 sidebar labels Jan 12, 2024
@grahamlangford
Copy link
Collaborator

I like the idea of the utility, but I'm not so sure about using a button. Adding the click handler to the document along with a toast feels like better UX and DX (just appending the button to the body doesn't give us any control over position). This is also something @BrandonPxBx should weigh in on.

@fregante
Copy link
Contributor Author

fregante commented Jan 12, 2024

That was pseudo-code, the style is TBD

@twschiller
Copy link
Contributor

twschiller commented Jan 12, 2024

A standard utility would be helpful and would let us have a standard UX. It doesn't replace avoiding the problem in the first place. Mod Creators/Users get confused by our Copy to Clipboard flow (they don't have a mental modal about page focus / gesture)

@fregante
Copy link
Contributor Author

Mod Creators/Users get confused by our Copy to Clipboard flow

Could that be a UI problem? Apple implemented a similar flow to block automated clipboard retrieval. The user is presented with a clear modal that lets the user confirm or deny the "paste".

Certainly it should be avoided if possible, but it's not always possible. For example with a "Load trigger" you just cannot open the sidebar automatically (I don't know how common this is, but...)

I'd say we can wrap those calls with the utility, while also pushing the user towards confirmation-free usage, e.g. "Open the sidebar in the first brick".

@BrandonPxBx
Copy link

I would hypothesize that users are confused by a toast message that says "Click anywhere to copy to clipboard" because there's 1) nothing specific to click on, and 2) clicking in a random place to copy something is a really out-of-the-ordinary pattern.

Since this is a fallback situation, I would treat it like an error, and I like @fregante's suggestion of using a button since it's a specific target with a clickable nature.

Message like "Something went wrong in Chrome [TRY AGAIN]" or generic that can be applied to everything is a small solution. Customizing with specific text and button labels is a larger, better solution IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mv3 sidebar user experience Improve the user experience (UX)
Development

Successfully merging a pull request may close this issue.

4 participants