Restore old Audio prototype after exportFunction
ClosedPublic

Authored by broulik on Apr 9 2020, 4:32 PM.

Details

Summary

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

Test Plan

The websites mentioned in the bug report

work now

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.Apr 9 2020, 4:32 PM
Restricted Application added a project: Plasma. · View Herald TranscriptApr 9 2020, 4:32 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
broulik requested review of this revision.Apr 9 2020, 4:32 PM
fvogt accepted this revision.Apr 9 2020, 6:23 PM

I can't find a better way to do this either...

Some notes:

  • window.eval works as expected so if not entirely unlucky (old firefox?) this can be replaced by using executeScript completely (PR incoming)
  • On chrome it works by accident as window.Audio.prototype is Object. exportFunction seems to clean that up, presumably to prevent access to the content script's Object (which != window.Object...)

So I'm wondering whether the other overrides should also set the protoype properly? Currently window.Audio.prototype != Audio on non-firefox.

This revision is now accepted and ready to land.Apr 9 2020, 6:23 PM
fvogt added a comment.Apr 9 2020, 6:51 PM

D28709 conflicts/supersedes this now. window.Audio.prototype != Audio is a separate issue though, which might still need fixing.

broulik abandoned this revision.Apr 9 2020, 7:09 PM

Superseded by D28709

broulik reclaimed this revision.Apr 14 2020, 9:09 AM

Apparently there's no good alternative.
In the future might make sense to refactor this to use a moz-extensions <script> tag but for a bugfix release I would want the prototype issue fixed and then we can try to make enhanced media controls working somehow.

This revision is now accepted and ready to land.Apr 14 2020, 9:09 AM
This revision was automatically updated to reflect the committed changes.