Gathering detailed insights and metrics for @eatsjobs/audio-recorder-polyfill-es
Gathering detailed insights and metrics for @eatsjobs/audio-recorder-polyfill-es
Gathering detailed insights and metrics for @eatsjobs/audio-recorder-polyfill-es
Gathering detailed insights and metrics for @eatsjobs/audio-recorder-polyfill-es
MediaRecorder polyfill to record audio in Edge and Safari
npm install @eatsjobs/audio-recorder-polyfill-es
Typescript
Module System
Node Version
NPM Version
JavaScript (92.41%)
Pug (7.59%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
587 Stars
239 Commits
76 Forks
16 Watchers
2 Branches
16 Contributors
Updated on Jul 02, 2025
Latest Version
0.1.1
Package Id
@eatsjobs/audio-recorder-polyfill-es@0.1.1
Unpacked Size
53.55 kB
Size
9.29 kB
File Count
10
NPM Version
6.4.1
Node Version
10.15.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
22
MediaRecorder polyfill to record audio in Edge and Safari 11. Try it in online demo.
1navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
2 recorder = new MediaRecorder(stream)
3 recorder.addEventListener('dataavailable', e => {
4 audio.src = URL.createObjectURL(e.data)
5 })
6 recorder.start()
7})
Install package:
1npm install --save audio-recorder-polyfill
If you bundle your app with "Webpack", "Roll up" or "Parcel", you can dynamic import the polyfill before you application loads
1 if (!window.MediaRecorder || isIE || isSafari) { 2 import('audio-recorder-polyfill').then((MediaRecorderPolyfill) => { 3 window.MediaRecorder = MediaRecorderPolyfill.default || MediaRecorderPolyfill; 4 }).then(() => { 5 // start the app 6 }); 7 }
Or you can load the "UMD" bundle
1function loadScript(url, callback) { 2 var script = document.createElement("script") 3 script.type = "text/javascript"; 4 if(script.readyState) { // only required for IE <9 5 script.onreadystatechange = function() { 6 if ( script.readyState === "loaded" || script.readyState === "complete" ) { 7 script.onreadystatechange = null; 8 callback(); 9 } 10 }; 11 } else { //Others 12 script.onload = function() { 13 callback(); 14 }; 15 } 16 17 script.src = url; 18 document.getElementsByTagName("head")[0].appendChild(script); 19} 20if (!window.MediaRecorder || isIE || isSafari) { 21 var umdURL = 'https://unpkg.com/audio-recorder-polyfill/dist/audio-polyfill.umd.js'; 22 loadScript(umdURL, function() { 23 window.MediaRecorder = window.MediaRecorderPolyfill; 24 // startApplication() 25 }); 26}
You can also use the ".mjs" module right in the browser that supports new script type=module tags
1<script type='module'> 2 import MediaRecorderPolyfill from 'https://unpkg.com/audio-recorder-polyfill/dist/audio-polyfill.mjs' 3 4</script>
In the begging, we need to show a warning in browsers without Web Audio API:
1if (MediaRecorder.notSupported) { 2 noSupport.style.display = 'block' 3 dictaphone.style.display = 'none' 4}
Then you can use standard MediaRecorder API:
1let recorder
2
3recordButton.addEventListener('click', () => {
4 // Request permissions to record audio
5 navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
6 recorder = new MediaRecorder(stream)
7
8 // Set record to <audio> when recording will be finished
9 recorder.addEventListener('dataavailable', e => {
10 audio.src = URL.createObjectURL(e.data)
11 })
12
13 // Start recording
14 recorder.start()
15 })
16})
17
18stopButton.addEventListener('click', () => {
19 // Stop recording
20 recorder.stop()
21 // Remove “recording” icon from browser tab
22 recorder.stream.getTracks().forEach(i => i.stop())
23})
If you need to upload record to the server, we recommend using timeslice
.
MediaRecorder will send recorded data every specified millisecond.
So you will start uploading before recording would finish.
1// Will be executed every second with next part of audio file
2recorder.addEventListener('dataavailable', e => {
3 sendNextPiece(e.data)
4})
5// Dump audio data every second
6recorder.start(1000)
Chrome records natively only to .webm
files. Firefox to .ogg
.
This polyfill saves records to .wav
files. Compression
is not very good, but encoding is fast and simple.
You can get used file format in e.data.type
:
1recorder.addEventListener('dataavailable', e => {
2 e.data.type //=> 'audio/wav' with polyfill
3 // 'audio/webm' in Chrome
4 // 'audio/ogg' in Firefox
5})
This polyfill tries to be MediaRecorder API compatible. But it still has small differences.
timeslice
or requestData()
call, dataavailable
will receive a separated file
with header on every call. In contrast, MediaRecorder sends header only
to first dataavailable
. Other events receive addition bytes
to the same file.stop()
during inactive
state) instead of throwing an error.BlobEvent.timecode
is not supported.If you need audio format with better compression, you can change polyfill encoder:
1 window.MediaRecorder = require('audio-recorder-polyfill') 2+ MediaRecorder.encoder = require('./ogg-opus-encoder') 3+ MediaRecorder.mimeType = 'audio/ogg'
The encoder should be a function with Web Worker in the body. Polyfill converts function to the string to make Web Worker.
1module.exports = function () { 2 function encode (input) { 3 … 4 } 5 6 function dump (sampleRate) { 7 … 8 postMessage(output) 9 } 10 11 onmessage = function (e) { 12 if (e.data[0] === 'encode') { 13 encode(e.data[1]) 14 } else { 15 dump(e.data[1]) 16 } 17 } 18}
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/4 approved changesets -- score normalized to 0
Reason
project is archived
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
61 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More