Fix trusted-replace-fetch-response and trusted-replace-xhr-response
IDK if this is only me, but adding youtube.com#%#//scriptlet('trusted-replace-fetch-response', '"adSlots"', '"no_ads"', '/\W/') causes Youtube video never plays when they send adSlots. The same for youtube.com#%#//scriptlet('trusted-replace-fetch-response', '"adSlots"', '"no_ads"', '/.*/'):
Screenshot
Ext. v5.1.62 on Chrome 134.0.6998.89
For trusted-replace-xhr-response, one of the problems seems to be that withCredentials is not added to forgedRequest:
https://github.com/AdguardTeam/Scriptlets/blob/9a974151a0bee433bd863b4da6fae2bc22831307/src/scriptlets/trusted-replace-xhr-response.js#L178
and it looks like that causes a problem.
We could probably do something like:
const forgedRequest = new XMLHttpRequest();
forgedRequest.withCredentials = thisArg.withCredentials;
Another problem probably is that, if few xhr related scriptlets are used, then few the same headers are added in:
https://github.com/AdguardTeam/Scriptlets/blob/9a974151a0bee433bd863b4da6fae2bc22831307/src/scriptlets/trusted-replace-xhr-response.js#L245-L250
And it also causes problems.
We should also use new ProgressEvent instead of new Event in:
https://github.com/AdguardTeam/Scriptlets/blob/9a974151a0bee433bd863b4da6fae2bc22831307/src/scriptlets/trusted-replace-xhr-response.js#L227-L236
Related to - https://github.com/AdguardTeam/AdguardFilters/issues/217308#issue-3604260655
Or even better we should try to use simpler approach, similar like in uBO is used.
We could try to use class instead of Proxy, this way we probably would not need to use collectedHeaders/setRequestHeader and setTimeout with dispatchEvent.
[!IMPORTANT] The same problem apply to
xml-prunescriptlet.