hello, I had been able to capture screenshots within the extension popup, but now I am opening a new window and would like to capture screenshots from the tab that launched the extension (it is a page extension).
first, I tried from the new window, but it fails.
now I am trying from the background page (using a background.html file to hold the canvas and video tags)
but the stream always returns as null or undefined.
I highly appreciate any insights on what is the right approach for this..
thks!
--- manifest ------
"background" : {
"page": "background.html",
"persistent": false
},
"page_action" :
{
"default_popup": "popup.html"
},
"permissions": ["activeTab", "declarativeContent", "tabCapture"],
-----background.html---
<html>
<head>
</head>
<body>
<video autoplay></video>
<canvas></canvas>
<script src="background.js"></script>
</body>
</html>
---background.js----
chrome.tabs.getSelected(null, function(tab) {
//what is the use of tab???
video = document.querySelector('video');
canvas = document.querySelector('canvas');
ctx = canvas.getContext('2d');
var MediaStreamConstraint = {
//audio: true,
video: true,
videoConstraints: {
mandatory: {
chromeMediaSource: 'tab',
minWidth: 640,
maxWidth: 800,
minHeight: 420,
maxHeight: 600
}
}
};
chrome.tabCapture.capture(MediaStreamConstraint, function(stream){
console.log(stream); //null or undefined
});
});