webdriverio-community/wdio-intercept-service

How to stop intercepting / Setting the value of '__webdriverajax' exceeded the quota

muhserks opened this issue ยท 6 comments

At >200 entries in __webdriverajax inside session storage, the browser starts throwing errors and ajax requests are not working anymore.
So is there something to disable the intercepting after calling browser.setupInterceptor();? Like browser.stopInterceptor(); and maybe a method to clear the content of __webdriverajax ?

From what I've briefly read it should do it on its own, when navigating to a new page (or even only domain?), but if the app does not work that way you end up with "'__webdriverajax' exceeded the quota" in the long run.

Re-executing browser.setupInterceptor(), as that will remove the session storage item with the library's namespace key.

Hm ... Sorry for being stupid, but that is not really working out.
Yes, the session storage gets cleared, but the interceptor hook is still present and will continue to fill __webdriverajax.
If I have a long running test, where I want to intercept some ajax in the first step and then I have lots of steps where I don't want to bother with Ajax, it will just continue to fill up __webdriverajax.

My first workaround was this:

browser.execute(() => {
            (window as { [key: string]: any }).oldFetch = window.fetch;
            (window as { [key: string]: any }).originalOpen = XMLHttpRequest.prototype.open;
            (window as { [key: string]: any }).originalSend = XMLHttpRequest.prototype.send;
            (window as { [key: string]: any }).originalSetRequestHeader =
                XMLHttpRequest.prototype.setRequestHeader;
            (window as { [key: string]: any }).originalAbort = XMLHttpRequest.prototype.abort;
        });
browser.setupInterceptor();
browser.waitUntil(() => {
            return browser.getRequests().length > 0 && browser.hasPendingRequests() == false;
        });
browser.execute(() => {
            window.fetch = (window as { [key: string]: any }).oldFetch;
            XMLHttpRequest.prototype.open = (window as { [key: string]: any }).originalOpen;
            XMLHttpRequest.prototype.send = (window as { [key: string]: any }).originalSend;
            XMLHttpRequest.prototype.setRequestHeader = (
                window as { [key: string]: any }
            ).originalSetRequestHeader;
            XMLHttpRequest.prototype.abort = (window as { [key: string]: any }).originalAbort;
        });
browser.execute('window.sessionStorage.removeItem("__webdriverajax");');

But at the end I changed it to just wait for some elements to update, even tough, this is really not a good solution (flakey) in my case, but the workaround from above is pretty stupid inside my framework.

I am not really sure If am able to create a meaningful PR to restore the native functions like outlined above in the workaround.
But I hope you get the idea of what the issue is and I hope that I don't miss anything here.

Anyway, thanks for replying.

Yeah, my apologies, I should have clarified that reexecuting the setup method is just a "clean" way to reset the clock.

It's definitely a valid request to want some nice, supported manner in which to disengage the interceptor.

As far as compatibility goes, I think the safest thing to do would be to add a flag to the serialization code and then a method e.g. disableInterceptor that toggles said flag. I consider this safer than restoring the originals because we cannot know if someone "after us" did the same thing we did. If someone else had, then reassigning the original methods to their respective object properties would undo their work.

Appreciate it. Now just label the issue correctly as feature request or whatever is applicable ๐Ÿ˜„

It did not came to my mind to do it via a flag, but you are right. It makes much more sense.

I will try ... but please bear with me. Either someone is faster than me, or we will do some cycles when it comes to a PR from side. So since I am the only one requesting it, I guess it is just fair. But feel free to leave some thumbs up ๐Ÿ˜„

@christian-bromann this issue can be closed with a new release

This functionality is available in versions >= 4.3.0