mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Fix broken trusted-replace-fetch-response
when using propsToMatch
This commit is contained in:
parent
7f23861e10
commit
d28b715811
@ -3364,6 +3364,12 @@ function trustedReplaceFetchResponse(
|
|||||||
propNeedles.set(prop, value);
|
propNeedles.set(prop, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const propReducer = (src, des, prop) => {
|
||||||
|
if ( src[prop] !== undefined ) {
|
||||||
|
des[prop] = src[prop];
|
||||||
|
}
|
||||||
|
return des;
|
||||||
|
};
|
||||||
self.fetch = new Proxy(self.fetch, {
|
self.fetch = new Proxy(self.fetch, {
|
||||||
apply: function(target, thisArg, args) {
|
apply: function(target, thisArg, args) {
|
||||||
if ( logLevel === true ) {
|
if ( logLevel === true ) {
|
||||||
@ -3375,13 +3381,18 @@ function trustedReplaceFetchResponse(
|
|||||||
if ( propNeedles.size !== 0 ) {
|
if ( propNeedles.size !== 0 ) {
|
||||||
const props = [
|
const props = [
|
||||||
'cache', 'credentials', 'destination', 'method',
|
'cache', 'credentials', 'destination', 'method',
|
||||||
'redirect', 'referrer', 'referrer-policy', 'url',
|
'mode', 'redirect', 'referrer', 'referrer-policy',
|
||||||
|
'url',
|
||||||
];
|
];
|
||||||
const normalArgs = args[0] instanceof Object
|
const normalArgs = args[0] instanceof Object
|
||||||
? props.reduce((p, a) => { a[p] = args[0][p]; }, {})
|
? props.reduce((a, p) => propReducer(args[0], a, p), {})
|
||||||
: { url: args[0] };
|
: { url: args[0] };
|
||||||
|
if ( args[1] instanceof Object ) {
|
||||||
|
props.reduce((a, p) => propReducer(args[0], a, p), normalArgs);
|
||||||
|
}
|
||||||
for ( const prop of props ) {
|
for ( const prop of props ) {
|
||||||
let value = normalArgs[prop];
|
let value = normalArgs[prop];
|
||||||
|
if ( value === undefined ) { continue; }
|
||||||
if ( typeof value !== 'string' ) {
|
if ( typeof value !== 'string' ) {
|
||||||
try { value = JSON.stringify(value); }
|
try { value = JSON.stringify(value); }
|
||||||
catch(ex) { }
|
catch(ex) { }
|
||||||
@ -3430,6 +3441,9 @@ function trustedReplaceFetchResponse(
|
|||||||
log('trusted-replace-fetch-response:', reason);
|
log('trusted-replace-fetch-response:', reason);
|
||||||
return responseBefore;
|
return responseBefore;
|
||||||
});
|
});
|
||||||
|
}).catch(reason => {
|
||||||
|
log('trusted-replace-fetch-response:', reason);
|
||||||
|
return fetchPromise;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user