I am trying to log all network requests in a page. My goal is to later filter for particular requests and check their initiator. The code below runs fine if I comment line 12 const request_initiator = interceptedRequest.initiator();. But the initiator is something really need. According to puppeteer's docs I am calling it correctly.
Here is my code:
const puppeteer = require('puppeteer');
(async() => {
const results = [];
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', interceptedRequest => {
const request_url = interceptedRequest.url();
const request_method = interceptedRequest.method();
const request_payload = interceptedRequest.postData();
const request_initiator = interceptedRequest.initiator();
results.push({
request_url,
request_method,
request_payload,
request_initiator
})
interceptedRequest.continue();
});
await page.goto('https://testurl.com');
await browser.close();
return results
})().then(function(result) {
console.log(result)
});
Here is the error I am getting:
UnhandledPromiseRejectionWarning: TypeError: interceptedRequest.initiator is not a function
at /Users/test/Desktop/code/tagv2/tcv2/index.js:12:54
at /Users/test/Desktop/code/tagv2/tcv2/node_modules/peteer/lib/cjs/vendor/mitt/src/index.js:51:62
at Array.map (<anonymous>)
at Object.emit (/Users/test/Desktop/code/tagv2/tcv2/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:51:43)
at Page.emit (/Users/test/Desktop/code/tagv2/tcv2/node_modules/puppeteer/lib/cjs/puppeteer/common/EventEmitter.js:72:22)
at /Users/test/Desktop/code/tagv2/tcv2/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:143:100
at /Users/test/Desktop/code/tagv2/tcv2/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:51:62
at Array.map (<anonymous>)
at Object.emit (/Users/test/Desktop/code/tagv2/tcv2/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:51:43)
at NetworkManager.emit (/Users/test/Desktop/code/tagv2/tcv2/node_modules/puppeteer/lib/cjs/puppeteer/common/EventEmitter.js:72:22)
(node:22974) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:22974) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.