Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop chrome from capturing a tab?

I'm trying to build an chrome extension similar to the chromecast one. I am using chrome.tabCapture to successfully start a audio/video stream. How do I stop the screen capture? I want to have a stop button, but I am not sure what to call to stop it. I can stop the LocalMediaStream, but the tab is still capturing and does not allow me to start a new capture without closing the tab. Any suggestions or maybe an api page I may have missed?

like image 895
mziemer Avatar asked Jan 15 '15 06:01

mziemer


People also ask

How do I stop Chrome from reloading tabs?

Head to chrome://discards to find a list of your active tabs. To stop one of the tabs from reloading when switching between them, uncheck the Auto Discardable option.

Why does Google Chrome keep reloading tabs?

Why are my tabs reloading? Your device is out of memory. Like your Android phone or tablet, Chrome is silently closing background tabs in order to make memory available. When you click on one of those tabs it reloads.

How do I stop Chrome from opening a new window when I click a link?

In the drop-down menu, just click on Search settings. On the following page, scroll down towards the bottom to the 'Where results open' section. Here, uncheck the box before the option that says chosen results will be shown in new browser windows.


1 Answers

Try stream.getVideoTracks()[0].stop(); to stop the screen capture. And to record the stream caught using chrome.tabCapture API , you could use RecordRTC.js

var video_constraints = {
    mandatory: {
        chromeMediaSource: 'tab'
    }
};
var constraints = {
    audio: false,
    video: true,
    videoConstraints: video_constraints
};

chrome.tabCapture.capture(constraints, function(stream) {
    console.log(stream)
    var options = {
        type: 'video',
        mimeType : 'video/webm',
        // minimum time between pushing frames to Whammy (in milliseconds)
        frameInterval: 20,
        video: {
            width: 1280,
            height: 720
         },
         canvas: {
            width: 1280,
            height: 720
         }
     };
     var recordRTC = new RecordRTC(stream, options);
     recordRTC.startRecording();

    setTimeout(function(){
        recordRTC.stopRecording(function(videoURL) {
            stream.getVideoTracks()[0].stop();
            recordRTC.save();
         });
    },10*1000);
});

I hope the above code snippet would help you :)

Edit 1: corrected the RecordRTC initialization.

like image 101
Muthu Avatar answered Sep 24 '22 03:09

Muthu