Summary
In plugins/api-mock-interceptor/src/core/interceptor.ts (lines 236-295), the XHR onreadystatechange wrapper calls the original handler with a newly constructed Event object instead of forwarding the actual event.
Current Behavior
const originalOnReadyStateChange = xhr.onreadystatechange;
xhr.onreadystatechange = function() {
// ... interceptor logic ...
if (originalOnReadyStateChange) {
return originalOnReadyStateChange.call(this, new Event('readystatechange'));
}
};
Problem
The original handler receives a synthetic new Event('readystatechange') instead of the real browser event. This means:
event.target will be null instead of the XHR object
event.currentTarget will be null
- Any custom properties the browser adds to the event are lost
- Code that inspects
event.target to get the XHR reference will break
Suggested Fix
Capture and forward the actual event:
xhr.onreadystatechange = function(event: Event) {
// ... interceptor logic ...
if (originalOnReadyStateChange) {
return originalOnReadyStateChange.call(this, event);
}
};
Priority
Low-Medium — most XHR handlers use this (which is correctly bound) rather than event.target, but it's a correctness issue.
Summary
In
plugins/api-mock-interceptor/src/core/interceptor.ts(lines 236-295), the XHRonreadystatechangewrapper calls the original handler with a newly constructedEventobject instead of forwarding the actual event.Current Behavior
Problem
The original handler receives a synthetic
new Event('readystatechange')instead of the real browser event. This means:event.targetwill benullinstead of the XHR objectevent.currentTargetwill benullevent.targetto get the XHR reference will breakSuggested Fix
Capture and forward the actual event:
Priority
Low-Medium — most XHR handlers use
this(which is correctly bound) rather thanevent.target, but it's a correctness issue.