Skip to content

Commit 9631484

Browse files
committed
feat(extension): enhance offscreen document management and logging
- Implemented a keep-alive mechanism for the offscreen document using setInterval. - Added logging for WebSocket ping messages and improved message logging format. - Registered the offscreen document creation on Chrome runtime startup.
1 parent 94be933 commit 9631484

5 files changed

Lines changed: 25 additions & 4 deletions

File tree

apps/extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@lgamila/extension",
33
"displayName": "LGamila Live",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"description": "This extension shows you a real-time list of all Moroccan Twitch and Kick streamers who are currently live.",
66
"author": "Stormix <hello@stormix.dev>",
77
"scripts": {

apps/extension/src/background/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ async function createOffscreenDocument() {
2424
}
2525

2626
createOffscreenDocument();
27+
28+
chrome.runtime.onStartup.addListener(createOffscreenDocument);
29+
self.onmessage = (_e) => {
30+
// Keep the offscreen document alive
31+
};

apps/extension/src/background/notifications.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const showNotification = (parsed: ServerToClient) => {
3434
};
3535

3636
chrome.runtime.onMessage.addListener(async (message) => {
37-
logger.info('Received message', message);
37+
logger.info('Received message', JSON.stringify(message));
3838
const parsed = serverToClient.safeParse(message);
3939

4040
if (!parsed.success) {
@@ -69,7 +69,7 @@ chrome.runtime.onMessage.addListener(async (message) => {
6969
return;
7070
}
7171

72-
logger.info('Creating notification', parsed.data.data);
72+
logger.info('Creating notification', JSON.stringify(parsed.data.data));
7373
chrome.notifications.create(
7474
{
7575
type: 'basic',
@@ -94,6 +94,10 @@ chrome.runtime.onMessage.addListener(async (message) => {
9494
showNotification(parsed.data);
9595
break;
9696
}
97+
case 'ping': {
98+
logger.info('Ping received', JSON.stringify(parsed.data.data));
99+
break;
100+
}
97101
default:
98102
return;
99103
}

apps/extension/src/lib/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const APP_NAME = 'LGamila Live';
2-
export const APP_VERSION = '1.1.0';
2+
export const APP_VERSION = '1.1.1';
33
export const APP_DESCRIPTION =
44
'This extension shows you a real-time list of all Moroccan Twitch and Kick streamers who are currently live.';
55
export const APP_AUTHOR = 'Stormix <hello@s.dev>';

apps/extension/src/offscreen.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { WS_URL } from './lib/constants';
33
import { logger } from './lib/logger';
44

55
logger.info('Offscreen script loaded');
6+
7+
// Keep the offscreen document alive
8+
setInterval(async () => {
9+
(await navigator.serviceWorker.ready).active.postMessage('keepAlive');
10+
}, 10_000);
11+
612
const ws = new WebSocket(WS_URL);
713

814
ws.onopen = () => {
@@ -26,6 +32,12 @@ ws.onmessage = async (event) => {
2632
logger.info('WebSocket connected', payload.id);
2733
break;
2834
case 'ping':
35+
logger.info('WebSocket ping received', payload.id);
36+
chrome.runtime.sendMessage({
37+
type: 'ping',
38+
data: { id: payload.id, timestamp: Date.now() },
39+
});
40+
2941
ws.send(
3042
JSON.stringify(
3143
clientToServer.parse({

0 commit comments

Comments
 (0)