Handle media session callbacks before passing it on to the browser
ClosedPublic

Authored by broulik on Sun, Aug 11, 12:41 PM.

Details

Summary

The Media Session API standard evolves quite fast, so there's new actions that we might be able to support that the browser itself doesn't know yet, for instance the "stop" action.
By registering the callback to ourselves before calling into the browser, we're still able to handle it in the extension even if not supported by the browser.

Test Plan

The following now works:

navigator.mediaSession.setActionHandler("stop", () => {
    console.log("stop player");
});

Clicked Stop in context menu of media controller applet, got the callback executed.
Previously an exception would be thrown when calling setActionHandler

Diff Detail

Repository
R856 Plasma Browser Integration
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
broulik created this revision.Sun, Aug 11, 12:41 PM
Restricted Application added a project: Plasma. · View Herald TranscriptSun, Aug 11, 12:41 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
broulik requested review of this revision.Sun, Aug 11, 12:41 PM
fvogt added inline comments.Mon, Aug 12, 5:16 PM
extension/content-script.js
687

Why add this check and not just save the exception thrown from oldSetActionHandler for throwing later?

Otherwise the addon controls which browser functionality is accessible.

broulik updated this revision to Diff 63618.Mon, Aug 12, 8:04 PM
broulik retitled this revision from Handle media session callbacks even when the requested one isn't supported by the browser to Handle media session callbacks before passing it on to the browser.
broulik edited the summary of this revision. (Show Details)
  • Register ourselves before passing on to the browser which may throw
fvogt accepted this revision.Mon, Aug 12, 8:18 PM
This revision is now accepted and ready to land.Mon, Aug 12, 8:18 PM
This revision was automatically updated to reflect the committed changes.