Skip to content

Commit 9ce3056

Browse files
committed
Improve prevent-fetch scriptlet
Add `statusText` as overridable property in response instance. Supported values are: `""`, `"Not Found"`. `statusText` defaults to `"OK"` when not overridden.
1 parent 324102c commit 9ce3056

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

assets/resources/scriptlets.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,11 +2089,13 @@ function noFetchIf(
20892089
}
20902090
const validResponseProps = {
20912091
ok: [ false, true ],
2092-
type: [ 'basic', 'cors', 'opaque' ],
2092+
statusText: [ '', 'Not Found' ],
2093+
type: [ 'basic', 'cors', 'default', 'error', 'opaque' ],
2094+
};
2095+
const responseProps = {
2096+
statusText: { value: 'OK' },
20932097
};
2094-
let responseProps;
20952098
if ( /^\{.*\}$/.test(responseType) ) {
2096-
responseProps = {};
20972099
try {
20982100
Object.entries(JSON.parse(responseType)).forEach(([ p, v ]) => {
20992101
if ( validResponseProps[p] === undefined ) { return; }
@@ -2104,7 +2106,7 @@ function noFetchIf(
21042106
catch(ex) {}
21052107
} else if ( responseType !== '' ) {
21062108
if ( validResponseProps.type.includes(responseType) ) {
2107-
responseProps = { type: { value: responseType } };
2109+
responseProps.type = { value: responseType };
21082110
}
21092111
}
21102112
self.fetch = new Proxy(self.fetch, {
@@ -2147,7 +2149,6 @@ function noFetchIf(
21472149
return generateContentFn(responseBody).then(text => {
21482150
safe.uboLog(logPrefix, `Prevented with response "${text}"`);
21492151
const response = new Response(text, {
2150-
statusText: 'OK',
21512152
headers: {
21522153
'Content-Length': text.length,
21532154
}

0 commit comments

Comments
 (0)