Commit 08468773 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Restore old Audio prototype after exportFunction

exportFunction doesn't carry over a prototype, nor can I assign a non-function with it afterwards.
However, Firefox exports the "unsafe" stuff in wrappedJSObject, so I can actually get the original untrusted prototype,
exportFunction my new function, and then set it back.

I can't just use the prototype in content-script since it wouldn't be accessible from the webpage.
Interestingly enough, I have to use window.Audio rather than window.wrappedJSObject.Audio for creating the player as the
wrapped one doesn't appear to be working when used from this function. This one then still passes onto the website like
normal and plays sound.

BUG: 414512

Differential Revision:
parent f23d65ec
......@@ -867,12 +867,22 @@ function loadMediaSessionsShim() {
// It also doesn't seem to have the aggressive autoplay prevention Chrome has,
// so the horrible replyAfterRemoval hack from above isn't copied into this
// See Bug 411148: Music playing from the ownCloud Music app does not show up
var oldAudio = window.Audio;
exportFunction(function(...args) {
// A function exported with exportFunction loses its prototype, leading to Bug 414512
const oldAudio = window.Audio;
// It is important to use the prototype on wrappedJSObject as the prototype
// of the content script is restricted and not accessible by the website
const oldAudioPrototype = window.wrappedJSObject.Audio.prototype;
const audioConstructor = function(...args) {
const player = new oldAudio(...args);
return player;
}, window, {defineAs: "Audio"});
exportFunction(audioConstructor, window.wrappedJSObject, {defineAs: "Audio"});
window.wrappedJSObject.Audio.prototype = oldAudioPrototype;
} else {
executeScript(`function() {
var oldAudio = window.Audio;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment