-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffscreen.js
More file actions
30 lines (28 loc) · 913 Bytes
/
offscreen.js
File metadata and controls
30 lines (28 loc) · 913 Bytes
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
// Listen for messages from the background script
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "playAudio") {
// Convert base64 back to blob
fetch(message.audioData)
.then((res) => res.blob())
.then((blob) => {
const audioUrl = URL.createObjectURL(blob);
const audio = new Audio(audioUrl);
audio
.play()
.then(() => {
console.log("Audio playing successfully");
})
.catch((error) => {
console.error("Error playing audio:", error);
});
// Clean up the URL object after the audio finishes playing
audio.onended = () => {
URL.revokeObjectURL(audioUrl);
};
})
.catch((error) => {
console.error("Error converting audio data:", error);
});
}
});
console.log("listener is listening");