ChromeDevTools / devtools-protocol

Chrome DevTools Protocol
https://chromedevtools.github.io/devtools-protocol/
BSD 3-Clause "New" or "Revised" License
1.15k stars 226 forks source link

Puppeteer - request interception returns empty post data / form data. #122

Closed sookinoby closed 5 years ago

sookinoby commented 6 years ago

When using google's puppeteer with request interception

//sample code const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setRequestInterception(true);

//'some website with uses a tracker and post to backend using application/x-www-form-urlencoded the statistics of the website' await page.goto('https://www.maple-af.com/');

page.on('request', (request) => { console.log('REQUEST RECEIVED'); console.log(request.url); // none of these work (it prints either undefined or empty value) console.log(request.postData) console.log(request.formData) console.log(request.formData()) console.log(request.formData()) }) I inspected the whole request object in console and it shows empty.

However when I use chrome in headful (headless set to false) and manually inspect the request in dev tools, it form data is available.

smhall05 commented 5 years ago

Use: console.log(request._postData);

aslushnikov commented 5 years ago

@sookinoby You should use request.postData().

smhall05 commented 5 years ago
    console.log(request._postData.split("&"));
    console.log(request.postData().split("&"));

Both of these work for me, can you explain the difference?

aslushnikov commented 5 years ago

@smhall05 the _postData is a private field - it is not supposed to be used and might change eventually. The postData() is Puppeteer's public API - it will never change from now on.