Open Bug 1251795 Opened 4 years ago Updated 3 days ago

Add global media support for web extension


(WebExtensions :: General, enhancement, P3)



(Not tracked)


(Reporter: mattw, Unassigned)


(Blocks 2 open bugs)



(2 obsolete files)

No description provided.
No longer depends on: 1246024
Iteration: 47.3 - Mar 7 → 48.1 - Mar 21
Iteration: 48.1 - Mar 21 → ---
Component: WebExtensions: Untriaged → WebExtensions: General
Priority: -- → P5
While this is pending, could someone fix the compatiblity listing @ ? It's not accurate for Firefox. I tried adding the compatibility table but I'm pretty lost on how the template engine works.
Yes, it's fixed now and thank you for showing me how to do that myself in the future!
Duplicate of this bug: 1377773
Duplicate of this bug: 1412666
Any update on this? It has been open for 2 years and it is going to break some Add-ons starting with Firefox 57:
Until this issue is fixed by Mozilla, people can use Chromium [1] with the
Streamkeys extension [2].

Actually, it appears that media keys *are working*, just not globally. Example

  "name": "wh",
  "version": "1.0.0",
  "manifest_version": 2,
  "background": {
    "scripts": ["xr.js"]
  "commands": {
    "ya": {
      "suggested_key": {
        "default": "MediaPlayPause"

and "xr.js":

  zu => console.log(zu)

Until global is implemented:

the above will only work if the browser has focus.
Media keys are still not working on macOS, even if Firefox has focus. Apparently, media keys on macOS act as "global hot keys" and are not currently implemented. The Chromium source cites this blog post as the source for their implementation:

Please consider this for this issue.
Maybe some mod could add this bug to the block list ;)
Once 1251795 is solved, 448910 will be solved as well.

Some ideas on behavior:
If you use the media keys, then you only want to play one song at a time.
If the OS and the browser are playing media: ignore the media keys all along.
If the OS is playing something, but the browser isn't, let the OS handle the request.
If the browser is playing something but the OS isn't, then we are concerned: Play/Pause the playback of the one thing that's playing at the moment/has been played last.
If the browser is already playing more than one media element currently, then ignore the media keys.
next/previous probably can only be handled on a per domain/service basis afaik (because youtube and others already provide keys for that, to which these can be mapped), for all other domains those keys need to be provided by an API to the website or ignored.
This behavior should work completely in the background (when the browser is minimized), because that's when you're usually using those keys ;)

On OSes where it's supported: (Opt-in) show the overlay for media (like on windows 10: )

another suggestion:
offer a way to set alternative keys for Firefox itself, that work even when the OS is playing back media.
Maybe even only for one domain (like youtube/soundcloud etc.)
User can then again map those shortcuts to certain keys on their keyboard (example for logitech: )
Assignee: matthewjwein → nobody
Product: Toolkit → WebExtensions
(In reply to Steven Penny from comment #10)
> Actually, it appears that media keys *are working*, just not globally.
> Example
> "manifest.json":
> {
>   "name": "wh",
>   "version": "1.0.0",
>   "manifest_version": 2,
>   "background": {
>     "scripts": ["xr.js"]
>   },
>   "commands": {
>     "ya": {
>       "suggested_key": {
>         "default": "MediaPlayPause"
>       }
>     }
>   }
> }
> and "xr.js":
> browser.commands.onCommand.addListener(
>   zu => console.log(zu)
> );
> Until global is implemented:
> the above will only work if the browser has focus.

That's actually the only Media event implemented. I tested yesterday and found that all my media keys send the MediaPlayPause event. This bug is probably really easy to fix for Windows considering the current behavior; probably just some key mappings are needed.
My testing on Ubuntu 16.04, Firefox 62.0.3 with Carlin Scott's browser-media-keys extension showed that a number of extended keys all trigger the MediaPlayPause event in Firefox.

In particular the following keys: XF86Tools, XF86WLAN, XF86Search, XF86LaunchA, XF86Explorer.
Type: defect → enhancement
Flags: needinfo?(jmathies)
Flags: needinfo?(jmathies)
Whiteboard: [commands]triaged → [webext?]
Summary: [commands] Add support for Chrome's media keys → Add support for Chrome's media keys
Priority: P5 → P3
Whiteboard: [webext?]

Moving down in priority? This is a pretty important issue for Firefox and media playback I would think.

So, I've recently had to switch browsers due to some problems I've had with Safari, and realized that the media keys don't work. Don't worry though! I came up with a quick patch for macOS. Obviously this on its own wouldn't be enough to cover all supported platforms on this ticket, but if the firefox team is interested in letting me take this on, I'd be happy to see what I can do.

I submitted the work I've done so far on phabricator. It is nowhere close to perfect, and has a ton of problems, but hopefully it will give you a good idea of how I would handle this.

I realize I'm probably not following the proper channels on this, so thank you for your patience.

Needinfo-ing Jimm to review the patches (although he may be out of office for a while).

Flags: needinfo?(jmathies)
Attachment #9098695 - Attachment is obsolete: true
Flags: needinfo?(jmathies)

We should maintain this bug as an implementation for supporting sending global media keys to web extension, and use other bugs to track the implementation for each platform.

On OSX, we have bug1591230.
On Windows, we have bug1584542.
On Linux, we have bug1584030.

Summary: Add support for Chrome's media keys → Add global media support for web extension

Comment on attachment 9094796 [details]
Bug 1251795 On macOS use MediaPlayer library for media keys when available.

Revision D46890 was moved to bug 1591230. Setting attachment 9094796 [details] to obsolete.

Attachment #9094796 - Attachment is obsolete: true

An extension that would benefit the most from this is

Depends on: 1591620
You need to log in before you can comment on or make changes to this bug.