Modify API Response rule stops Replace String rule from happening
Expected Behavior
I have two rules set up for the same URL contains. One of this is Replace String on the request and the other is Modify API Response for the response. I expect that both occur when I send a request and both rules are active.
Current Behavior
When Modify API Response is active (using javascript) the Replace String is not happening. The URL is not getting redirected with the modification. This is picked up with the lack of redirect on the network tab, no logging for the Replace String in the Requestly tab, and also the URL console.log call in the Modify API Response code.
Steps to Reproduce
-
Create a Replace String rule. Verify it works
-
Create a Modify API Response rule with the same URL.
-
Replace String will stop working.
-
Deactivate Modify API Response. Replace String will start working again.
Your Environment
- Operating System and version : Mac OS 12.4
- Extension Version : ? latest for Chrome
- Desktop App Version :
@jgostylo If I get it correctly, you are trying to redirect a request to another endpoint (using Replace String rule) and want to modify response of the redirected endpoint (not original endpoint).
As we mention in Modify Response Rule UI, Only API Responses triggered by XHR/fetch can be modified by Chrome Extension. You cannot modify response of a redirected URL using extension.
We avoid this by not allowing URL redirection of a request if user has already selected to modify response of the original request.
As a workaround, if it is fetch API call, you can make another API request to the redirected URL in JS code you wrote to modify response.
Something like:
async function modifyResponse(args) {
const { url } = args;
const newResponse = await fetch(replaceStringInUrl(url)); // equivalent to your Replace String rule
const newResponseJSON = await newResponse.json();
newResponseJSON.value = "modified"; // replace with your code
return newResponseJSON;
}
Otherwise, you may try our Desktop Application which supports your use-case. (Downloads page)
You did understand my report correctly. Thank you for the explanation and the work arounds!
@lazyvab I didn't know that we support async-await in our ModifyResponse using JS in the extension code :-)
@sachinjain024 Yes you are lucky, if the API request is made via fetch method.
This is not supported for XMLHttpRequest.
@lazyvab Do we need any discussion on this or Can we close this?