-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,7 +223,7 @@ async function applyHeader(isManual = false) { | |
|
||
browser.webRequest.onBeforeRequest.addListener( | ||
async (details) => { | ||
await applyHeader() | ||
await applyHeader(); | ||
}, | ||
{ urls: ['https://*.kagi.com/*'] }, | ||
[], | ||
|
@@ -392,44 +392,51 @@ if (browser.contextMenus !== undefined) { | |
which will then find out the PP extension was uninstalled, and hence reinstate X-Kagi-Authorize. | ||
*/ | ||
|
||
const KAGI_PRIVACY_PASS_EXTENSION_ID = "[email protected]"; // Firefox only | ||
const KAGI_PRIVACY_PASS_EXTENSION_ID = '[email protected]'; // Firefox only | ||
|
||
async function requestPPMode() { | ||
if (IS_CHROME) { | ||
return; | ||
} | ||
let pp_mode_enabled = false; | ||
try { | ||
pp_mode_enabled = await browser.runtime.sendMessage(KAGI_PRIVACY_PASS_EXTENSION_ID, "status_report"); | ||
pp_mode_enabled = await browser.runtime.sendMessage( | ||
KAGI_PRIVACY_PASS_EXTENSION_ID, | ||
'status_report', | ||
); | ||
} catch (ex) { | ||
// other end does not exist, likely Privacy Pass extension disabled/not installed | ||
pp_mode_enabled = false; // PP mode not enabled | ||
} | ||
await browser.storage.local.set({ "pp_mode_enabled": pp_mode_enabled }) | ||
await browser.storage.local.set({ pp_mode_enabled: pp_mode_enabled }); | ||
} | ||
|
||
async function isPPModeEnabled() { | ||
if (IS_CHROME) { | ||
return false; | ||
} | ||
const { pp_mode_enabled } = await browser.storage.local.get({ "pp_mode_enabled": false }); | ||
const { pp_mode_enabled } = await browser.storage.local.get({ | ||
pp_mode_enabled: false, | ||
}); | ||
return pp_mode_enabled; | ||
} | ||
|
||
if (!IS_CHROME) { | ||
// PP extension sent an unsolicited status report | ||
// We update our internal assumption, and update header application | ||
browser.runtime.onMessageExternal.addListener(async (request, sender, sendResponse) => { | ||
if (sender.id !== KAGI_PRIVACY_PASS_EXTENSION_ID) { | ||
// ignore messages from extensions other than the PP one | ||
return; | ||
} | ||
// check the message is about the PP mode | ||
if ('enabled' in request) { | ||
// update X-Kagi-Authorization header application | ||
await applyHeader(); | ||
} | ||
}); | ||
browser.runtime.onMessageExternal.addListener( | ||
async (request, sender, sendResponse) => { | ||
if (sender.id !== KAGI_PRIVACY_PASS_EXTENSION_ID) { | ||
// ignore messages from extensions other than the PP one | ||
return; | ||
} | ||
// check the message is about the PP mode | ||
if ('enabled' in request) { | ||
// update X-Kagi-Authorization header application | ||
await applyHeader(); | ||
} | ||
}, | ||
); | ||
} | ||
|
||
// when extension is started, ask for status report, and apply header accordingly | ||
|