diff --git a/extension/content-script.js b/extension/content-script.js --- a/extension/content-script.js +++ b/extension/content-script.js @@ -682,9 +682,17 @@ // Call the original native implementation // "call()" is needed as the real setActionHandler is a class member // and calling it directly is illegal as it lacks the context - // We'll register the callback for ourself after this since it may - // throw for unsupported callback names. - var ret = oldSetActionHandler.call(navigator.mediaSession, name, cb); + // The browser throws for unsupported callback names but we might + // still be able to handle it + if (!["play", "pause", "seekbackward", "seekforward", "previoustrack", "nexttrack", "skipad", "stop"].includes(name)) { + throw new TypeError("Failed to execute 'setActionHandler' on 'MediaSession': The provided value '" + name + "' is not a valid enum value of type MediaSessionAction."); + } + + try { + var ret = oldSetActionHandler.call(navigator.mediaSession, name, cb); + } catch (e) { + console.warn("Failed to register media session callback", name, "with the browser:", e); + } if (cb) { ${mediaSessionsClassName}.callbacks[name] = cb;