-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
49 lines (44 loc) · 1.47 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// background.js
function log(message, type = 'info') {
const timestamp = new Date().toISOString();
switch (type) {
case 'info':
console.log(`%c[INFO - ${timestamp}] ${message}`, 'color: blue');
break;
case 'warn':
console.warn(`%c[WARN - ${timestamp}] ${message}`, 'color: orange');
break;
case 'error':
console.error(`%c[ERROR - ${timestamp}] ${message}`, 'color: red');
break;
default:
console.log(`[LOG - ${timestamp}] ${message}`);
}
}
chrome.runtime.onInstalled.addListener(() => {
log('Media Converter Extension installed');
});
chrome.runtime.onStartup.addListener(() => {
log('Media Converter Extension started');
});
chrome.runtime.onSuspend.addListener(() => {
log('Media Converter Extension suspended');
});
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "fetchImage") {
fetch(request.url)
.then(response => response.blob())
.then(blob => {
const reader = new FileReader();
reader.onloadend = () => {
sendResponse({ dataUrl: reader.result });
};
reader.readAsDataURL(blob);
})
.catch(error => {
console.error('Fetch error:', error);
sendResponse({ error: error.message });
});
return true;
}
});