-
Notifications
You must be signed in to change notification settings - Fork 10
/
background.js
34 lines (30 loc) · 1.11 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const startRecording = async () => {
await chrome.tabs.query({'active': true, 'lastFocusedWindow': true, 'currentWindow': true}, async function (tabs) {
// Get current tab to focus on it after start recording on recording screen tab
const currentTab = tabs[0];
// Create recording screen tab
const tab = await chrome.tabs.create({
url: chrome.runtime.getURL('recording_screen.html'),
pinned: true,
active: true,
});
// Wait for recording screen tab to be loaded and send message to it with the currentTab
chrome.tabs.onUpdated.addListener(async function listener(tabId, info) {
if (tabId === tab.id && info.status === 'complete') {
chrome.tabs.onUpdated.removeListener(listener);
await chrome.tabs.sendMessage(tabId, {
name: 'startRecordingOnBackground',
body: {
currentTab: currentTab,
},
});
}
});
});
};
// Listen for startRecording message from popup.js
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.name === 'startRecording') {
startRecording();
}
});