diff --git a/src/background.ts b/src/background.ts index 8a3d2608..8f44a312 100644 --- a/src/background.ts +++ b/src/background.ts @@ -1,6 +1,9 @@ import {Handle} from './lib/bridge/server'; import {InternalResponseBundle} from './lib/bridge/types'; import MessageSender = chrome.runtime.MessageSender; +import {ClientSend} from './lib/bridge/client'; +import {SendCookies} from './lib/bridge/handlers/send_cookies'; +import {setupCookieAlarm} from './lib/utils/alarm'; function unifiedHandler(request: any, sender: MessageSender, sendResponse: (response?: any) => void) { Handle(request, sender) @@ -39,3 +42,7 @@ chrome.runtime.onMessageExternal.addListener((request, sender, sendResponse) => unifiedHandler(request, sender, sendResponse); return true; }); + +chrome.runtime.onInstalled.addListener(async ({reason}) => { + await setupCookieAlarm(true); +}); diff --git a/src/lib/bridge/client.ts b/src/lib/bridge/client.ts index 9ffcb09e..1fb644dd 100644 --- a/src/lib/bridge/client.ts +++ b/src/lib/bridge/client.ts @@ -27,7 +27,7 @@ export async function ClientSend(handler: RequestHandler, // @ts-ignore Bad types runtimeNamespace().runtime.sendMessage( - window.CSFLOAT_EXTENSION_ID || chrome.runtime.id, + (typeof window !== 'undefined' && window.CSFLOAT_EXTENSION_ID) || chrome.runtime.id, bundle, // @ts-ignore Bad types (resp: InternalResponseBundle) => { diff --git a/src/lib/bridge/handlers/send_cookies.ts b/src/lib/bridge/handlers/send_cookies.ts index c600e0cf..70e7a521 100644 --- a/src/lib/bridge/handlers/send_cookies.ts +++ b/src/lib/bridge/handlers/send_cookies.ts @@ -1,5 +1,6 @@ import {SimpleHandler} from './main'; import {RequestType} from './types'; +import {setupCookieAlarm} from '../../utils/alarm'; export interface SendCookiesRequest {} @@ -43,6 +44,9 @@ export const SendCookies = new SimpleHandler { + if (alarm.name !== COOKIE_ALARM_NAME) { + return; + } + + await SendCookies.handleRequest({}, {}); + }); +}