Gathering detailed insights and metrics for audio-recorder-polyfill
Gathering detailed insights and metrics for audio-recorder-polyfill
Gathering detailed insights and metrics for audio-recorder-polyfill
Gathering detailed insights and metrics for audio-recorder-polyfill
audio-recorder-polyfill-add-importscripts
MediaRecorder polyfill to record audio in Edge and Safari
@eatsjobs/audio-recorder-polyfill-es
MediaRecorder polyfill to record audio in Edge and Safari
opus-media-recorder
MedialRecorer polyfill for Opus recording using WebAssembly
recorder-polyfill
Simple cross platform audio recorder polyfill based on audio-recorder-polyfill
MediaRecorder polyfill to record audio in Edge and Safari
npm install audio-recorder-polyfill
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.4.1
Package Id
audio-recorder-polyfill@0.4.1
Unpacked Size
29.30 kB
Size
7.15 kB
File Count
13
NPM Version
7.0.8
Node Version
15.2.1
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
No dependencies detected.
MediaRecorder polyfill to record audio in Edge and Safari. Try it in online demo and see API.
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
We recommend creating separated webpack/Parcel bundle with polyfill. In this case, polyfill will be downloaded only by Edge and Safari. Good browsers will download less.
Files recorded without the polyfill will not be playable on Safari, it is highly recommended to convert it to MP3 on the back-end of your application. If that’s not an option you can use the polyfill in all browsers to force the audio to be converted to the right format with the price of client’s performance.
1 entry: { 2 app: './src/app.js', 3+ polyfill: './src/polyfill.js' 4 }
Install polyfill as MediaRecorder in this new bundle src/polyfill.js
:
1import AudioRecorder from 'audio-recorder-polyfill' 2window.MediaRecorder = AudioRecorder
Add this code to your HTML to load this new bundle only for browsers without MediaRecorder support:
1+ <script> 2+ if (!window.MediaRecorder) { 3+ document.write( 4+ decodeURI('%3Cscript defer src="/polyfill.js">%3C/script>') 5+ ) 6+ } 7+ </script> 8 <script src="/app.js" defer></script>
Polyfill supports ES modules. You do not need to do anything for bundlers.
For quick hacks you can load polyfill from CDN. Do not use it in production because of low performance.
1import AudioRecorder from 'https://cdn.jsdelivr.net/npm/audio-recorder-polyfill/index.js' 2window.MediaRecorder = AudioRecorder
In the beginning, 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
.
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})
As default, this polyfill saves records to .wav
files. Compression
is not very good, but encoding is fast and simple.
For better compression you may use the MP3 encoder.
1import AudioRecorder from 'audio-recorder-polyfill' 2import mpegEncoder from 'audio-recorder-polyfill/mpeg-encoder' 3 4AudioRecorder.encoder = mpegEncoder 5AudioRecorder.prototype.mimeType = 'audio/mpeg' 6window.MediaRecorder = AudioRecorder
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.BlobEvent.timecode
is not supported.If you need audio format with better compression, you can change polyfill’s encoder:
1 import AudioRecorder from 'audio-recorder-polyfill' 2+ import customEncoder from './ogg-opus-encoder' 3+ 4+ AudioRecorder.encoder = customEncoder 5+ AudioRecorder.prototype.mimeType = 'audio/ogg' 6 window.MediaRecorder = AudioRecorder
The encoder should be a function with Web Worker in the body. Polyfill converts function to the string to make Web Worker.
1module.exports = () => { 2 function init (sampleRate) { 3 … 4 } 5 6 function encode (input) { 7 … 8 } 9 10 function dump (sampleRate) { 11 … 12 postMessage(output) 13 } 14 15 onmessage = e => { 16 if (e.data[0] === 'init') { 17 init(e.data[1]) 18 } else if (e.data[0] === 'encode') { 19 encode(e.data[1]) 20 } else if (e.data[0] === 'dump') { 21 dump(e.data[1]) 22 } 23 } 24}
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