mirror of
https://github.com/movie-web/extension.git
synced 2025-09-13 12:43:24 +00:00
Compare commits
2 Commits
1.0.2
...
fix-firefo
Author | SHA1 | Date | |
---|---|---|---|
|
9f34642a96 | ||
|
e1fa034074 |
13
src/background.ts
Normal file
13
src/background.ts
Normal file
@@ -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();
|
||||||
|
});
|
||||||
|
}
|
@@ -49,19 +49,20 @@ const mapBodyToFetchBody = (body: Request['body'], bodyType: Request['bodyType']
|
|||||||
|
|
||||||
const handler: PlasmoMessaging.MessageHandler<Request, Response<any>> = async (req, res) => {
|
const handler: PlasmoMessaging.MessageHandler<Request, Response<any>> = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
const url = makeFullUrl(req.body.url, req.body);
|
||||||
await assertDomainWhitelist(req.sender.tab.url);
|
await assertDomainWhitelist(req.sender.tab.url);
|
||||||
|
|
||||||
if (req.body.headers['User-Agent']) {
|
if (req.body.headers['User-Agent']) {
|
||||||
await setDynamicRules({
|
await setDynamicRules({
|
||||||
ruleId: MAKE_REQUEST_DYNAMIC_RULE,
|
ruleId: MAKE_REQUEST_DYNAMIC_RULE,
|
||||||
targetDomains: [new URL(req.body.url).hostname],
|
targetDomains: [new URL(url).hostname],
|
||||||
requestHeaders: {
|
requestHeaders: {
|
||||||
'User-Agent': req.body.headers['User-Agent'],
|
'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,
|
method: req.body.method,
|
||||||
headers: req.body.headers,
|
headers: req.body.headers,
|
||||||
body: mapBodyToFetchBody(req.body.body, req.body.bodyType),
|
body: mapBodyToFetchBody(req.body.body, req.body.bodyType),
|
||||||
@@ -80,6 +81,7 @@ const handler: PlasmoMessaging.MessageHandler<Request, Response<any>> = async (r
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.error('failed request', err);
|
||||||
res.send({
|
res.send({
|
||||||
success: false,
|
success: false,
|
||||||
error: err.message,
|
error: err.message,
|
||||||
|
Reference in New Issue
Block a user