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

Allow websites to disable default action handlers #338

Open
steimelchrome opened this issue Sep 4, 2024 · 5 comments
Open

Allow websites to disable default action handlers #338

steimelchrome opened this issue Sep 4, 2024 · 5 comments

Comments

@steimelchrome
Copy link
Contributor

The spec allows for user agents to implement default handlers for actions. However, sometimes the default handler does not make sense for the website's use case. The typical "solution" for this is for the website to implement an empty action handler for that action so that the default handler won't be run. However, this means that the user agent thinks that the website handles that action and therefore still shows e.g. a UI button for that action that ends up doing nothing.

I think there would be value in having some sort of API where the website can specify that it does not want a default handler even though it doesn't have a handler of its own.

@youennf
Copy link
Contributor

youennf commented Sep 23, 2024

sometimes the default handler does not make sense for the website's use case

@steimelchrome, can you describe some examples where the default handler does not make sense?

@steimelchrome
Copy link
Contributor Author

Sure:

seekto: For standard video playback, it's often helpful for the UA to provide seeking controls. However, for certain types of playback (e.g. ads) the website doesn't want to allow seeking (which is when they add the empty handler that just looks broken in the UI)

enterpictureinpicture: For standard video playback, it's also often helpful for the UA to provide a default control to enter video picture-in-picture. Again, some websites may not want to allow this feature and their only option is to "disable" by adding an empty handler

pause: Here's an example bug from a developer who uses an tag for game sounds: crbug.com/41463788. Giving users the ability to pause breaks the game and doesn't make sense

@steimelchrome
Copy link
Contributor Author

Discussed this at TPAC. The consensus was that this was worth fixing but we definitely want UAs to be able to still implement a default handler if they want to.

Here are a few options:

  1. Add a new method navigator.mediaSession.preventDefaultAction(action) (actual name tbd) that hints to the UA that action (a string representing a MediaSessionAction) should not have any default action handler.

  2. Add a new option to navigator.mediaSession.setActionHandler() which when set prevents default, e.g. navigator.mediaSession.setActionHandler(/*action=*/"seekto", /*handler=*/null, /*preventDefault=*/true);

  3. Treat a call to navigator.mediaSession.setActionHandler(action, null); as a hint that the UA should not provide a default, and navigator.mediaSession.setActionHandler(action, undefined) as a hint that the UA is welcome to provide one

  4. Don't specifically allow these hints, but ensure that the examples above are all possible to stop:

    a) To prevent seekto/seekforward/seekbackward: add a notion of "seekable range" to the media session api, and the website can set an empty seekable range to imply the content is not seekable.

    b) Preventing enterpictureinpicture is actually already solvable using the disablePictureInPicture attribute on HTMLVideoElement

    c) Preventing pause should be solvable using the new AudioSession API

Thoughts?

@youennf
Copy link
Contributor

youennf commented Sep 27, 2024

@steimelchrome, that is a great summary.
I would have a tendency to start with 4.
When we find evidence that this is not sufficient, we could introduce an options parameter (might be nice for other cases like the skip action), something like:

undefined setActionHandler(MediaSessionAction action, MediaSessionActionHandler? handler, MediaSessionActionHandlerOptions options);
dictionary MediaSessionActionHandlerOptions {
    boolean preventDefault;
}```

@youennf
Copy link
Contributor

youennf commented Oct 7, 2024

A potential edge case where disabling default action handlers might be useful, https://jsfiddle.net/xkn9u8wh/ on Safari macOS:

  1. Load a page that registers mediaSession.metadata and capture camera and microphone with AirPods.
  2. Remove AirPods.
  3. Video will pause while it is probably expected that video does not pause.

This happened to me on codepen.io which sets the metadata (probably on the top level frame), while capture happens on an iframe. The workaround is to register an empty pause command on the iframe doing capture.

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

2 participants