muaz-khan / RecordRTC

RecordRTC is WebRTC JavaScript library for audio/video as well as screen activity recording. It supports Chrome, Firefox, Opera, Android, and Microsoft Edge. Platforms: Linux, Mac and Windows.
https://www.webrtc-experiment.com/RecordRTC/
MIT License
6.54k stars 1.75k forks source link

"TypeError: URL is not a constructor" when try to refresh page and this fixed it #841

Open fkadeal opened 1 year ago

fkadeal commented 1 year ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch recordrtc@5.6.2 for the project I'm working on.

stack is { "next": "^13.4.1", node: "18.16" }

Here is the diff that solved my problem:

diff --git a/node_modules/recordrtc/RecordRTC.js b/node_modules/recordrtc/RecordRTC.js
index c0c07c8..fe096ee 100644
--- a/node_modules/recordrtc/RecordRTC.js
+++ b/node_modules/recordrtc/RecordRTC.js
@@ -1730,7 +1730,12 @@ if (typeof AudioContext === 'undefined') {
 }

 /*jshint -W079 */
-var URL = window.URL;
+// var URL = window.URL;
+function URL(url, base) {
+  this.url = url;
+  this.base = base;
+  return window.URL;
+}

 if (typeof URL === 'undefined' && typeof webkitURL !== 'undefined') {
     /*global URL:true */
@@ -4992,7 +4997,12 @@ function MultiStreamsMixer(arrayOfMediaStreams, elementClass) {
     }

     /*jshint -W079 */
-    var URL = window.URL;
+    // var URL = window.URL;
+    function URL(url, base) {
+      this.url = url;
+      this.base = base;
+      return window.URL;
+    }

     if (typeof URL === 'undefined' && typeof webkitURL !== 'undefined') {
         /*global URL:true */

This issue body was partially generated by patch-package.

KitsonBroadhurst commented 1 year ago

Thanks for the fix, will use this too, but looks like the PR for the code change hasn't been merged in 12 months

Jkhall81 commented 8 months ago

WOOOOOOO HOOO. fkadeal, you are a saint!! I'm working on a coding challenge for an internship and hit a brick wall. have to record video from a webcam... and.... this solved my problem!