From e7ca90b75ff7c05b544f60a7648104dcb5b67c29 Mon Sep 17 00:00:00 2001 From: Jorrin <43169049+JorrinKievit@users.noreply.github.com> Date: Sun, 3 Mar 2024 20:14:56 +0100 Subject: [PATCH] add firstPartyDomain for first-party isolation --- src/background/messages/makeRequest.ts | 4 ++++ src/utils/extension.ts | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/background/messages/makeRequest.ts b/src/background/messages/makeRequest.ts index 3039d21..61d77ca 100644 --- a/src/background/messages/makeRequest.ts +++ b/src/background/messages/makeRequest.ts @@ -3,6 +3,7 @@ import type { PlasmoMessaging } from '@plasmohq/messaging'; import type { BaseRequest } from '~types/request'; import type { BaseResponse } from '~types/response'; import { removeDynamicRules, setDynamicRules } from '~utils/declarativeNetRequest'; +import { isFirefox } from '~utils/extension'; import { makeFullUrl } from '~utils/fetcher'; import { assertDomainWhitelist } from '~utils/storage'; @@ -69,6 +70,9 @@ const handler: PlasmoMessaging.MessageHandler> = async (r const cookies = await (chrome || browser).cookies.getAll({ url: response.url, + ...(isFirefox() && { + firstPartyDomain: new URL(response.url).hostname, + }), }); res.send({ diff --git a/src/utils/extension.ts b/src/utils/extension.ts index 3a338fc..9999b34 100644 --- a/src/utils/extension.ts +++ b/src/utils/extension.ts @@ -1,3 +1,11 @@ export const isChrome = () => { return chrome.runtime.getURL('').startsWith('chrome-extension://'); }; + +export const isFirefox = () => { + try { + return browser.runtime.getURL('').startsWith('moz-extension://'); + } catch { + return false; + } +};