From e1fa0340747f8e398c2529994a27fcabe39f608b Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 31 Jan 2024 18:55:22 +0100 Subject: [PATCH 1/2] Add background script to reload on load. Painful fix --- src/background.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/background.ts diff --git a/src/background.ts b/src/background.ts new file mode 100644 index 0000000..1b79798 --- /dev/null +++ b/src/background.ts @@ -0,0 +1,13 @@ +import { isChrome } from '~utils/extension'; + +// Both brave and firefox for some reason need this extension reload, +// If this isn't done, they will never load properly and will fail updateDynamicRules() +if (isChrome()) { + chrome.runtime.onStartup.addListener(() => { + chrome.runtime.reload(); + }); +} else { + browser.runtime.onStartup.addListener(() => { + browser.runtime.reload(); + }); +} From 9f34642a963789a389f2ca60205672761dd8b6d8 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 31 Jan 2024 18:55:34 +0100 Subject: [PATCH 2/2] Add some logging and use full urls --- src/background/messages/makeRequest.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/background/messages/makeRequest.ts b/src/background/messages/makeRequest.ts index cd778a8..bdc16fa 100644 --- a/src/background/messages/makeRequest.ts +++ b/src/background/messages/makeRequest.ts @@ -49,19 +49,20 @@ const mapBodyToFetchBody = (body: Request['body'], bodyType: Request['bodyType'] const handler: PlasmoMessaging.MessageHandler> = async (req, res) => { try { + const url = makeFullUrl(req.body.url, req.body); await assertDomainWhitelist(req.sender.tab.url); if (req.body.headers['User-Agent']) { await setDynamicRules({ ruleId: MAKE_REQUEST_DYNAMIC_RULE, - targetDomains: [new URL(req.body.url).hostname], + targetDomains: [new URL(url).hostname], requestHeaders: { 'User-Agent': req.body.headers['User-Agent'], }, }); } - const response = await fetch(makeFullUrl(req.body.url, req.body), { + const response = await fetch(url, { method: req.body.method, headers: req.body.headers, body: mapBodyToFetchBody(req.body.body, req.body.bodyType), @@ -80,6 +81,7 @@ const handler: PlasmoMessaging.MessageHandler> = async (r }, }); } catch (err) { + console.error('failed request', err); res.send({ success: false, error: err.message,