there are problems while multiple browser extension use new XMLHttpRequestInterceptor()
For Example, there are two browser extension, both browser extension use new XMLHttpRequestInterceptor().
const batchInterceptor = new BatchInterceptor({ interceptors: [new XMLHttpRequestInterceptor()] });
then will happen:
after first extension execute: globalThis.XMLHttpRequest = A Proxy(globalThis.XMLHttpRequest);
after second extension execute: globalThis.XMLHttpRequest = B Proxy(A Proxy(globalThis.XMLHttpRequest));
maby 'IS_PATCHED_MODULE' doesn't work because Symbol('isPatchedModule') is diffrent in two execution context:
invariant( !(PureXMLHttpRequest as any)[IS_PATCHED_MODULE], 'Failed to patch the "XMLHttpRequest" module: already patched.' )
export const IS_PATCHED_MODULE: unique symbol = Symbol('isPatchedModule').
so can Symbol('isPatchedModule') modify width Symbol.for('isPatchedModule')?
or there is other way to solve multiple new XMLHttpRequestInterceptor() in diffrent execution context?
Hi, @meiqi502. I believe your initial assessment of this is correct: symbol identity differs so Interceptors sees no existing interceptor attached, which results in them being needlessly nested.
so can Symbol('isPatchedModule') modify width Symbol.for('isPatchedModule')?
I like it. Do you want to open a pull request with this? Should be enough to edit the symbol itself in src/glossary.ts and run the tests to verify. I will help with the code review, if any.
Released: v0.41.9 🎉
This has been released in v0.41.9.
Get these changes by running the following command:
npm i @mswjs/interceptors@latest
Predictable release automation by Release.