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

[💡 Feature]: Modification of outbound network request props #12914

Open
1 task done
MubarakGj opened this issue May 20, 2024 · 5 comments
Open
1 task done

[💡 Feature]: Modification of outbound network request props #12914

MubarakGj opened this issue May 20, 2024 · 5 comments
Assignees
Labels
Enhancement help wanted Issues that are free to take by anyone interested Idea 💡 A new feature idea
Milestone

Comments

@MubarakGj
Copy link

Is your feature request related to a problem?

I would like to capture the network calls happening in the background while running the tests and modify the captured request headers and body before the request leaves the browser

Describe the solution you'd like.

If there is browser.intercept() method available which takes a call back function like
browser.intercept(“regex of url to be intercepted”, (request)=>{ // request modification commands});
This could be used to do all the actions that we want before a request is sent.

Describe alternatives you've considered.

we have used cypress to automate single tab use cases. it supports these kind of request interception and modification.

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@MubarakGj MubarakGj added Idea 💡 A new feature idea Needs Triaging ⏳ No one has looked into the issue yet labels May 20, 2024
@christian-bromann
Copy link
Member

@MubarakGj thanks for raising the issue.

I have to verify if this may already work in v9 our upcoming major release. I will get back to you on that.

@christian-bromann christian-bromann removed Needs Triaging ⏳ No one has looked into the issue yet labels May 20, 2024
@christian-bromann christian-bromann self-assigned this May 20, 2024
@thecotne
Copy link

// switch to Puppeteer
const puppeteerBrowser = await browser.getPuppeteer()
const page = (await puppeteerBrowser.pages())[0]
await page.setRequestInterception(true)
page.on('request', interceptedRequest => {
if (interceptedRequest.url().endsWith('webdriverio.png')) {
return interceptedRequest.continue({
url: 'https://user-images.githubusercontent.com/10379601/29446482-04f7036a-841f-11e7-9872-91d1fc2ea683.png'
})
}
interceptedRequest.continue()
})

@christian-bromann christian-bromann added the help wanted Issues that are free to take by anyone interested label May 28, 2024
@wdio-bot
Copy link
Contributor

Thanks for reporting!

We greatly appreciate any contributions that help resolve the bug. While we understand that active contributors have their own priorities, we kindly request your assistance if you rely on this bug being fixed. We encourage you to take a look at our contribution guidelines or join our friendly Discord development server, where you can ask any questions you may have. Thank you for your support, and cheers!

@christian-bromann christian-bromann added PR: New Feature 🚀 PRs that contain new features Enhancement and removed PR: New Feature 🚀 PRs that contain new features labels May 28, 2024
@christian-bromann
Copy link
Member

In v9 this is currently not possible but can be implemented right here. What type of user interface would you like to see? How would you like to modify request data?

@MubarakGj
Copy link
Author

MubarakGj commented Jun 9, 2024

if we have a method somthing like, browser.intercept(params...) to modify the requests sent to a specific destination, calling the method should modify all the requests sent to the URL after this point.
for simple modifications . ex: if we want to modify an header and add one extra header to the request then,

 browser.intercept("URL to intercept", {
    headers:{
  'header1':'value1', // modifies the value, if header already exists in request else adds the header
  'header2':'value2' 
  }
});

this can directly add those headers to all the intercepted requests or modify them if they already exist.
for complex modifications, if we have sth like the below would be helpful:

 browser.intercept("url to intercept", (req)=>{
    req.headers = {'header1':'value1'} //replacing the whole header section
    req.body['productId'] = '23456';
})

We can do even more things if we can intercept all the requests going out of the browser by giving a generic target URL value. something like "**/*" or "".
Also If we can have a way to set these interceptions at the browser session level (setting the interception once for all pages), we can avoid setting these on each page we navigate. This will help us to add the interception at the beginning of the script and we can intercept all requests till the execution is completed.

@christian-bromann christian-bromann added this to the v9 milestone Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement help wanted Issues that are free to take by anyone interested Idea 💡 A new feature idea
Projects
None yet
Development

No branches or pull requests

4 participants