cleanup and fix targetDomain

This commit is contained in:
Jorrin
2024-01-25 16:38:04 +01:00
parent 658f59eb24
commit a2647a58d6
2 changed files with 3 additions and 10 deletions

View File

@@ -12,7 +12,7 @@ type Body =
value: string; value: string;
} }
| { | {
bodyType: 'FormData' | 'URLSearchParams' | 'Object'; bodyType: 'FormData' | 'URLSearchParams' | 'object';
value: Record<string, string>; value: Record<string, string>;
}; };
@@ -50,7 +50,7 @@ const mapBodyToFetchBody = (body: Request['body']): BodyInit => {
}); });
return searchParams; return searchParams;
} }
if (body?.bodyType === 'Object') { if (body?.bodyType === 'object') {
return JSON.stringify(body.value); return JSON.stringify(body.value);
} }
if (body?.bodyType === 'string') { if (body?.bodyType === 'string') {
@@ -63,18 +63,14 @@ const handler: PlasmoMessaging.MessageHandler<Request, Response<any>> = async (r
try { try {
await assertDomainWhitelist(req.sender.tab.url); await assertDomainWhitelist(req.sender.tab.url);
console.log(req.body.headers['User-Agent']);
if (req.body.headers['User-Agent']) { if (req.body.headers['User-Agent']) {
console.log('preparing stream');
await setDynamicRules({ await setDynamicRules({
ruleId: 23498, ruleId: 23498,
targetDomains: [req.body.url], targetDomains: [new URL(req.body.url).hostname],
requestHeaders: { requestHeaders: {
'User-Agent': req.body.headers['User-Agent'], 'User-Agent': req.body.headers['User-Agent'],
}, },
}); });
const rules = await chrome.declarativeNetRequest.getDynamicRules();
console.log(rules);
} }
const response = await fetch(makeFullUrl(req.body.url, req.body), { const response = await fetch(makeFullUrl(req.body.url, req.body), {
@@ -95,8 +91,6 @@ const handler: PlasmoMessaging.MessageHandler<Request, Response<any>> = async (r
}, },
}); });
} catch (err) { } catch (err) {
console.log('error');
console.log(err);
res.send({ res.send({
success: false, success: false,
error: err.message, error: err.message,

View File

@@ -21,7 +21,6 @@ const handler: PlasmoMessaging.MessageHandler<Request, BaseResponse> = async (re
success: true, success: true,
}); });
} catch (err) { } catch (err) {
console.log(err);
res.send({ res.send({
success: false, success: false,
error: err.message, error: err.message,