Files
background.js
content.js
manifest.json
popup.css
popup.html
popup.js
Code
6 219
background.js
let recorder;
let recordedChunks = [];
let agentModeActive = false;
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'startRecording') {
if (agentModeActive) {
startRecording(message.quality);
} else {
console.error('Not in Agent mode');
// Optionally notify user
}
} else if (message.action === 'stopRecording') {
stopRecording();
} else if (message.action === 'agentModeDetected') {
agentModeActive = true;
} else if (message.action === 'agentModeLeft') {
agentModeActive = false;
}
});
async function startRecording(quality) {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (!tab.url.includes('chat.openai.com') && !tab.url.includes('chatgpt.com')) {
console.error('Not on ChatGPT page');
return;
}
const constraints = quality === '720p' ? { video: { width: 1280, height: 720 }, audio: true } : { video: { width: 1920, height: 1080 }, audio: true };
try {
const stream = await chrome.tabCapture.capture(constraints);
recorder = new MediaRecorder(stream, { mimeType: 'video/mp4;codecs=avc1.42E01E,mp4a.40.2' });
recordedChunks = [];
recorder.ondataavailable = (event) => {
if (event.data.size > 0) {
recordedChunks.push(event.data);
}
};
recorder.onstop = () => {
const blob = new Blob(recordedChunks, { type: 'video/mp4' });
const url = URL.createObjectURL(blob);
chrome.downloads.download({
url: url,
filename: `chatgpt_agent_recording_${Date.now()}.mp4`
});
stream.getTracks().forEach(track => track.stop());
chrome.storage.local.set({ isRecording: false });
agentModeActive = false; // Reset after recording
};
recorder.start();
chrome.storage.local.set({ isRecording: true });
} catch (error) {
console.error('Failed to start recording:', error);
// Fallback to webm if mp4 not supported
try {
const stream = await chrome.tabCapture.capture(constraints);
recorder = new MediaRecorder(stream, { mimeType: 'video/webm' });
recordedChunks = [];
recorder.ondataavailable = (event) => {
if (event.data.size > 0) {
recordedChunks.push(event.data);
}
};
recorder.onstop = () => {
const blob = new Blob(recordedChunks, { type: 'video/webm' });
const url = URL.createObjectURL(blob);
chrome.downloads.download({
url: url,
filename: `chatgpt_agent_recording_${Date.now()}.webm`
});
stream.getTracks().forEach(track => track.stop());
chrome.storage.local.set({ isRecording: false });
agentModeActive = false;
};
recorder.start();
chrome.storage.local.set({ isRecording: true });
} catch (fallbackError) {
console.error('Fallback recording also failed:', fallbackError);
}
}
}
function stopRecording() {
if (recorder && recorder.state === 'recording') {
recorder.stop();
}
}