feat: 添加离屏文档创建和下载功能,优化录制逻辑
This commit is contained in:
@@ -1,3 +1,27 @@
|
||||
export default defineBackground(() => {
|
||||
console.log('Hello background!', { id: browser.runtime.id });
|
||||
|
||||
chrome.runtime.onMessage.addListener(async (msg, sender, sendResponse) => {
|
||||
if (msg.type === 'CREATE_OFFSCREEN') {
|
||||
const exists = await chrome.offscreen.hasDocument();
|
||||
if (!exists) {
|
||||
await chrome.offscreen.createDocument({
|
||||
url: 'offscreen.html',
|
||||
reasons: ['DISPLAY_MEDIA', 'USER_MEDIA', 'BLOBS', 'AUDIO_PLAYBACK'],
|
||||
justification: 'rrweb record & replay',
|
||||
});
|
||||
console.log('[bg] offscreen created');
|
||||
}
|
||||
sendResponse({ ok: true });
|
||||
}
|
||||
|
||||
if (msg.type === 'DOWNLOAD') {
|
||||
console.log('[bg] DOWNLOAD received');
|
||||
chrome.downloads.download({
|
||||
url: msg.dataUrl,
|
||||
filename: `rrweb-${Date.now()}.json`,
|
||||
saveAs: true,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user