Improve `prevent-xhr` scriptlet

This commit is contained in:
Raymond Hill 2024-11-08 08:48:07 -05:00
parent 41616df866
commit ce4908b341
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 3 additions and 1 deletions

View File

@ -1345,11 +1345,11 @@ function preventXhrFn(
'content-type': '', 'content-type': '',
'content-length': '', 'content-length': '',
}, },
url: haystack.url,
props: { props: {
response: { value: '' }, response: { value: '' },
responseText: { value: '' }, responseText: { value: '' },
responseXML: { value: null }, responseXML: { value: null },
responseURL: { value: haystack.url },
}, },
}); });
xhrInstances.set(this, xhrDetails); xhrInstances.set(this, xhrDetails);
@ -1405,6 +1405,7 @@ function preventXhrFn(
xhrDetails.headers['content-length'] = `${xhrDetails.props.response.value}`.length; xhrDetails.headers['content-length'] = `${xhrDetails.props.response.value}`.length;
Object.defineProperties(xhrDetails.xhr, { Object.defineProperties(xhrDetails.xhr, {
readyState: { value: 4 }, readyState: { value: 4 },
responseURL: { value: xhrDetails.url },
status: { value: 200 }, status: { value: 200 },
statusText: { value: 'OK' }, statusText: { value: 'OK' },
}); });
@ -1414,6 +1415,7 @@ function preventXhrFn(
Promise.resolve(xhrText).then(( ) => xhrDetails).then(details => { Promise.resolve(xhrText).then(( ) => xhrDetails).then(details => {
Object.defineProperties(details.xhr, { Object.defineProperties(details.xhr, {
readyState: { value: 1, configurable: true }, readyState: { value: 1, configurable: true },
responseURL: { value: xhrDetails.url },
}); });
safeDispatchEvent(details.xhr, 'readystatechange'); safeDispatchEvent(details.xhr, 'readystatechange');
return details; return details;