Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
muhserks opened this issue Mar 13, 2022 · 6 comments

Comments

@muhserks
Copy link
Contributor

muhserks commented Mar 13, 2022

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.

@tehhowch
Copy link
Contributor

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

@muhserks
Copy link
Contributor Author

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.

@tehhowch
Copy link
Contributor

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.

@muhserks
Copy link
Contributor Author

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 😄

@tehhowch
Copy link
Contributor

tehhowch commented Sep 8, 2022

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

@tehhowch
Copy link
Contributor

This functionality is available in versions >= 4.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants