mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Improve prevent-fetch
scriptlet
Related issue: https://github.com/AdguardTeam/AdguardFilters/issues/153796
This commit is contained in:
parent
00fb5f18b2
commit
e1ae17ed00
@ -274,6 +274,15 @@ function generateContentFn(directive) {
|
|||||||
if ( directive === 'true' ) {
|
if ( directive === 'true' ) {
|
||||||
return Promise.resolve(randomize(10));
|
return Promise.resolve(randomize(10));
|
||||||
}
|
}
|
||||||
|
if ( directive === 'emptyObj' ) {
|
||||||
|
return Promise.resolve('{}');
|
||||||
|
}
|
||||||
|
if ( directive === 'emptyArr' ) {
|
||||||
|
return Promise.resolve('[]');
|
||||||
|
}
|
||||||
|
if ( directive === 'emptyStr' ) {
|
||||||
|
return Promise.resolve('');
|
||||||
|
}
|
||||||
if ( directive.startsWith('length:') ) {
|
if ( directive.startsWith('length:') ) {
|
||||||
const match = /^length:(\d+)(?:-(\d+))?$/.exec(directive);
|
const match = /^length:(\d+)(?:-(\d+))?$/.exec(directive);
|
||||||
if ( match ) {
|
if ( match ) {
|
||||||
@ -1829,7 +1838,7 @@ builtinScriptlets.push({
|
|||||||
});
|
});
|
||||||
function noFetchIf(
|
function noFetchIf(
|
||||||
propsToMatch = '',
|
propsToMatch = '',
|
||||||
directive = ''
|
responseBody = ''
|
||||||
) {
|
) {
|
||||||
if ( typeof propsToMatch !== 'string' ) { return; }
|
if ( typeof propsToMatch !== 'string' ) { return; }
|
||||||
const safe = safeSelf();
|
const safe = safeSelf();
|
||||||
@ -1886,7 +1895,17 @@ function noFetchIf(
|
|||||||
if ( proceed ) {
|
if ( proceed ) {
|
||||||
return Reflect.apply(target, thisArg, args);
|
return Reflect.apply(target, thisArg, args);
|
||||||
}
|
}
|
||||||
return generateContentFn(directive).then(text => {
|
let responseType = '';
|
||||||
|
if ( details.mode === undefined || details.mode === 'cors' ) {
|
||||||
|
try {
|
||||||
|
const desURL = new URL(details.url);
|
||||||
|
responseType = desURL.origin !== document.location.origin
|
||||||
|
? 'cors'
|
||||||
|
: 'basic';
|
||||||
|
} catch(_) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return generateContentFn(responseBody).then(text => {
|
||||||
const response = new Response(text, {
|
const response = new Response(text, {
|
||||||
statusText: 'OK',
|
statusText: 'OK',
|
||||||
headers: {
|
headers: {
|
||||||
@ -1896,6 +1915,11 @@ function noFetchIf(
|
|||||||
Object.defineProperty(response, 'url', {
|
Object.defineProperty(response, 'url', {
|
||||||
value: details.url
|
value: details.url
|
||||||
});
|
});
|
||||||
|
if ( responseType !== '' ) {
|
||||||
|
Object.defineProperty(response, 'type', {
|
||||||
|
value: responseType
|
||||||
|
});
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user