diff --git a/browser/extensions/pictureinpicture/data/picture_in_picture_overrides.js b/browser/extensions/pictureinpicture/data/picture_in_picture_overrides.js index af5687db484e..4b9bf7cfa730 100644 --- a/browser/extensions/pictureinpicture/data/picture_in_picture_overrides.js +++ b/browser/extensions/pictureinpicture/data/picture_in_picture_overrides.js @@ -12,13 +12,14 @@ let AVAILABLE_PIP_OVERRIDES; // See PictureInPictureControls.jsm for these values. // eslint-disable-next-line no-unused-vars const TOGGLE_POLICIES = browser.pictureInPictureChild.getPolicies(); - const KEYBOARD_CONTROLS = browser.pictureInPictureChild.getKeyboardControls(); AVAILABLE_PIP_OVERRIDES = { // The keys of this object are match patterns for URLs, as documented in // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns // // Example: + // const KEYBOARD_CONTROLS = browser.pictureInPictureChild.getKeyboardControls(); + // // // "https://*.youtube.com/*": { // policy: TOGGLE_POLICIES.THREE_QUARTERS, @@ -73,7 +74,6 @@ let AVAILABLE_PIP_OVERRIDES; netflix: { "https://*.netflix.com/*": { - keyboardControls: ~KEYBOARD_CONTROLS.SEEK, videoWrapperScriptPath: "video-wrappers/netflix.js", }, "https://*.netflix.com/browse*": { policy: TOGGLE_POLICIES.HIDDEN }, diff --git a/browser/extensions/pictureinpicture/video-wrappers/netflix.js b/browser/extensions/pictureinpicture/video-wrappers/netflix.js index 4e8cf773edb4..8f97f280b450 100644 --- a/browser/extensions/pictureinpicture/video-wrappers/netflix.js +++ b/browser/extensions/pictureinpicture/video-wrappers/netflix.js @@ -17,6 +17,12 @@ class PictureInPictureVideoWrapper { } this.player = netflixPlayerAPI.getVideoPlayerBySessionId(sessionId); } + getCurrentTime(video) { + return this.player.getCurrentTime(); + } + getDuration(video) { + return this.player.getDuration(); + } play() { this.player.play(); } @@ -55,6 +61,31 @@ class PictureInPictureVideoWrapper { }); } } + + setCurrentTime(video, position) { + let oldTime = this.player.getCurrentTime(); + let duration = this.player.getDuration(); + let isHome = position == 0; + let isEnd = position >= duration; + // Read pipChild's expected seek result to determine if we want + // to move forward/backwards, or go to the start/end + let seekDirection = position - oldTime; + // But ignore pipChild's proposed seek forward/backward time for a better viewing + // experience. 10 seconds (10000ms) seems to be the best value for compatibility. + // The new currentTime will not always be 10 seconds forward/backward though, since Netflix + // adjusts the new currentTime when seek() is called, according to the current timestamp. + let seekTimeMS = 10000; + let newTime = 0; + + if (isHome || isEnd) { + newTime = position; + } else if (seekDirection < 0) { + newTime = Math.max(oldTime - seekTimeMS, 0); + } else if (seekDirection > 0) { + newTime = Math.min(oldTime + seekTimeMS, duration); + } + this.player.seek(newTime); + } } this.PictureInPictureVideoWrapper = PictureInPictureVideoWrapper; diff --git a/toolkit/actors/PictureInPictureChild.jsm b/toolkit/actors/PictureInPictureChild.jsm index 427c7332eb53..c70bcec51781 100644 --- a/toolkit/actors/PictureInPictureChild.jsm +++ b/toolkit/actors/PictureInPictureChild.jsm @@ -2306,6 +2306,9 @@ class PictureInPictureChildVideoWrapper { let retVal = wrappedMethod.call(this.#siteWrapper, ...args); if (!validateRetVal) { + logConsole.debug( + `Invalid return value validator was found for method ${name}(). Replacing return value ${retVal} with null.` + ); Cu.reportError( `No return value validator was provided for method ${name}(). Returning null.` ); @@ -2313,6 +2316,7 @@ class PictureInPictureChildVideoWrapper { } if (!validateRetVal(retVal)) { + logConsole.debug("Invalid return value:", retVal); Cu.reportError( `Calling method ${name}() returned an unexpected value: ${retVal}. Returning null.` ); @@ -2322,6 +2326,7 @@ class PictureInPictureChildVideoWrapper { return retVal; } } catch (e) { + logConsole.debug("Error:", e.message); Cu.reportError(`There was an error while calling ${name}(): `, e.message); }