blocking DOMless Audio (Audio API extension)

Bug reports and enhancement requests
Post Reply
al_9x
Master Bug Buster
Posts: 931
Joined: Thu Mar 19, 2009 4:52 pm

blocking DOMless Audio (Audio API extension)

Post by al_9x »

https://developer.mozilla.org/en/Introd ... _Extension

Audio API extension enables audio playback via the window.Audio object. It should be treated as a plug-in and (optional) blocked.

The crude way is with a surrogate:

user_pref("noscript.surrogate.Audio.sources", "@^https?:");
user_pref("noscript.surrogate.Audio.replacement", "window.Audio=null;");

but, it deserves window.java treatment.
Last edited by al_9x on Sun Jun 19, 2011 11:25 pm, edited 1 time in total.
Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
al_9x
Master Bug Buster
Posts: 931
Joined: Thu Mar 19, 2009 4:52 pm

Re: blocking DOMless Audio (Audio API extension)

Post by al_9x »

What are you thoughts on blocking Audio()?
Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
User avatar
Giorgio Maone
Site Admin
Posts: 9524
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: blocking DOMless Audio (Audio API extension)

Post by Giorgio Maone »

Sorry, I believed I had already answered but probably I just hit the "Preview" button.

Yes, it should be done that way.
Mozilla/5.0 (Windows NT 5.2; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
al_9x
Master Bug Buster
Posts: 931
Joined: Thu Mar 19, 2009 4:52 pm

Re: blocking DOMless Audio (Audio API extension)

Post by al_9x »

document.createElement("audio") would also need to be blocked, don't know if there are other ways co construct the audio object.
Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
User avatar
Giorgio Maone
Site Admin
Posts: 9524
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: blocking DOMless Audio (Audio API extension)

Post by Giorgio Maone »

al_9x wrote:document.createElement("audio") would also need to be blocked, don't know if there are other ways co construct the audio object.
Would this work also while the element is not inserted in a document?
Mozilla/5.0 (Windows NT 5.2; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
al_9x
Master Bug Buster
Posts: 931
Joined: Thu Mar 19, 2009 4:52 pm

Re: blocking DOMless Audio (Audio API extension)

Post by al_9x »

Giorgio Maone wrote:
al_9x wrote:document.createElement("audio") would also need to be blocked, don't know if there are other ways co construct the audio object.
Would this work also while the element is not inserted in a document?
Yes.
Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
User avatar
Giorgio Maone
Site Admin
Posts: 9524
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: blocking DOMless Audio (Audio API extension)

Post by Giorgio Maone »

al_9x wrote:
Giorgio Maone wrote:
al_9x wrote:document.createElement("audio") would also need to be blocked, don't know if there are other ways co construct the audio object.
Would this work also while the element is not inserted in a document?
Yes.
PoC?
Mozilla/5.0 (Windows NT 5.2; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
al_9x
Master Bug Buster
Posts: 931
Joined: Thu Mar 19, 2009 4:52 pm

Re: blocking DOMless Audio (Audio API extension)

Post by al_9x »

modified https://developer.mozilla.org/User:sins ... _extension

Code: Select all

<!doctype html>
<html>
  <head>
        <title>Generating audio in real time</title>
        <script type="application/javascript">
        var notes = { "do": 3, "do#": 4, "re": 5, "re#": 6, "mi": 7, "fa": 8, "fa#": 9, "sol": 10, "sol#": 11, "la": 12, "la#": 13, "si": 14, "do+": 15 };
        var clavier = { Q: "do", Z: "do#", S: "re", E: "re#", D: "mi", F: "fa", T: "fa#", G:"sol", Y:"sol#", H:"la", U:"la#", J:"si", K:"do+" };
        var samples = new Float32Array(22050);
        var octave = 3;
        var DOM_KB = {};
        for(k in clavier) DOM_KB[eval("KeyboardEvent.DOM_VK_"+k)] = clavier[k];
       
        function playNOTE(note) {
            var output = document.createElement("audio");
            output.mozSetup(1, 44100);
            var len = samples.length;

            var f = 55 * Math.pow(2, octave + notes[note]/12);
            for (var j = 0; j < samples.length ; j++) {
             samples[j] = Math.sin( (j * f * Math.PI) / 44100);
            }
            output.mozWriteAudio(samples);
            output = null;
        }
       
        function playKEY(e) {
            if(e.charCode in DOM_KB)
                playNOTE(DOM_KB[e.charCode], octave);
            else switch(e.keyCode) {
                case KeyboardEvent.DOM_VK_PAGE_UP : changeOctave(octave+1); break;
                case KeyboardEvent.DOM_VK_PAGE_DOWN : changeOctave(octave-1); break;
            }
            return false;
        }
       
        function changeOctave(val) {
            if(val<2) octave = 2;
            else if(val > 8) octave = 8;
            else octave = val;
        }
        </script>
    </head>
    <body onkeypress="playKEY(event);">
        <button onclick="playNOTE('do');">Do</button>
        <button onclick="playNOTE('re');">Ré</button>
        <button onclick="playNOTE('mi');">Mi</button>
        <button onclick="playNOTE('fa');">Fa</button>
        <button onclick="playNOTE('sol');">Sol</button>
        <button onclick="playNOTE('la');">La</button>
        <button onclick="playNOTE('si');">Si</button>
        <button onclick="playNOTE('do+');">Do</button>
    </body>
</html>
Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
User avatar
Giorgio Maone
Site Admin
Posts: 9524
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: blocking DOMless Audio (Audio API extension)

Post by Giorgio Maone »

Please check latest development build 2.1.1.2rc6
Mozilla/5.0 (Windows NT 5.2; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
al_9x
Master Bug Buster
Posts: 931
Joined: Thu Mar 19, 2009 4:52 pm

Re: blocking DOMless Audio (Audio API extension)

Post by al_9x »

done
Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Post Reply