Skip to content Skip to sidebar Skip to footer

Is It Possible To Capture From An Element With Cross Origin Data?

i have this simple script that i found in the webRTC doc i triet to run it but it seems i'm missing something const leftVideo = document.getElementById('leftVideo'); const rightVi

Solution 1:

  1. Either you can set crossOrigin as shown in this link Example:

<videocrossOrigin="anonymous"src="https://cdn.myapp.com:81/video.mp4"></video>

you want to make sure link is using https

Reference: https://stackoverflow.com/a/35245146/8689969

  1. or you can create a readable stream using fetch, follow up doc on this link: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream which gives you blob url that should help resolving that issue: Example:

// Fetch the original imagefetch(video.filePath,  {
      mode: 'cors',
      headers: {
        'Access-Control-Allow-Origin':'*'
      }
    })
    // Retrieve its body as ReadableStream
    .then(response => {
      const reader = response.body.getReader();

      returnnewReadableStream({
        start(controller) {
          returnpump();
          functionpump() {
            return reader.read().then(({ done, value }) => {
              // When no more data needs to be consumed, close the streamif (done) {
                  controller.close();
                  return;
              }
              // Enqueue the next data chunk into our target stream
              controller.enqueue(value);
              returnpump();
            });
          }
        }  
      })
    })
    .then(stream =>newResponse(stream))
    .then(response => response.blob())
    .then(blob =>URL.createObjectURL(blob))
    .then((url) => {
      // gives the blob url which solves cors error in reading stream(using captureStream() func)console.log(url);

      // do your thing
    })
    .catch(err =>console.error(err));
  • Good luck...

Post a Comment for "Is It Possible To Capture From An Element With Cross Origin Data?"