Fixup new Audio() constructor and apply autoplay prevention evasion to document.createElement
ClosedPublic

Authored by broulik on Oct 22 2019, 6:20 PM.

Details

Summary

The arguments apparently weren't properly forwarded to the constructor, breaking e.g. new Audio("foo") calls. This uses the much nicer spread syntax introduced in ES6.
Also, document.createElement("audio") is affected in the same way as new Audio()
The evasion is now only done when the player actually starts playing, not immediately when it is created, since we only care about playing players.

BUG: 411742

Test Plan

The following were tested, play sound fine now (or still work), and get media controls if the played sound is longer than the minimum threshold (8 seconds):
(Mostly aggregated from past p-b-i Bug reports about media controls)

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.Oct 22 2019, 6:20 PM
Restricted Application added a project: Plasma. · View Herald TranscriptOct 22 2019, 6:20 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
broulik requested review of this revision.Oct 22 2019, 6:20 PM
fvogt added a comment.Oct 22 2019, 6:25 PM

Is this not needed for <video/> as well?

I am not sure. I thought since a video is likely in the DOM or otherwise it won't be visible, the user can at least play it.
But then I just remembered how Spotify used a <video> tag for playing its music...

fvogt accepted this revision.Oct 30 2019, 11:54 AM

IMO this looks uglier than multiline C macros, but ok...

This revision is now accepted and ready to land.Oct 30 2019, 11:54 AM
broulik planned changes to this revision.Oct 30 2019, 11:55 AM
broulik updated this revision to Diff 69545.Nov 10 2019, 7:01 PM
broulik retitled this revision from Apply autoplay prevention evasion also to document.createElement to Fixup new Audio() constructor and apply autoplay prevention evasion to document.createElement.
broulik edited the summary of this revision. (Show Details)
broulik edited the test plan for this revision. (Show Details)
  • Only apply hack on playback
  • Use better syntax
  • More testing
This revision is now accepted and ready to land.Nov 10 2019, 7:01 PM
broulik requested review of this revision.Nov 10 2019, 7:02 PM
broulik updated this revision to Diff 69622.Nov 12 2019, 7:53 AM
  • Add missing play() call
broulik edited the test plan for this revision. (Show Details)Nov 12 2019, 7:56 AM
broulik updated this revision to Diff 69638.Nov 12 2019, 3:01 PM
  • Also apply the same thing to Firefox
This revision was not accepted when it landed; it landed in state Needs Review.Nov 14 2019, 6:37 PM
This revision was automatically updated to reflect the committed changes.