-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
32 lines (30 loc) · 1.07 KB
/
Copy pathbackground.js
File metadata and controls
32 lines (30 loc) · 1.07 KB
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
/*
* Copyright © 2026 Cloudrun Ltd
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* Background service worker — handles feed fetches to bypass CORS
* restrictions that block direct fetch() from the popup context.
*/
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "fetchFeed") {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 15000);
fetch(request.url, { signal: controller.signal })
.then((response) => {
clearTimeout(timeout);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return response.text();
})
.then((text) => sendResponse({ ok: true, data: text }))
.catch((error) => {
clearTimeout(timeout);
sendResponse({ ok: false, error: error.message });
});
return true;
}
});