Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate request IDs in Puppeteer

Chromium/Puppeteer seems to be reusing request IDs.

I'm counting the requests and response IDs, I was expecting to get two of each ID (one on the request, then the same on on its response.request()._requestId) but I'm finding that there are more.

I'm collecting the metrics with these two events:

    page.on('request', (request) => {
        const requestId = request._requestId;
        if (counter[requestId])
            counter[requestId]++;
        else
            counter[requestId.toString()] = 1;
    });

    page.on('response', (response) => {

        const requestId = response.request()._requestId;

        if (counter[requestId])
            counter[requestId]++;
        else
            counter[requestId] = 1;
    });

Results from stringifying the counter object:

{
    "750DF247357DA37DCCBE84ACEB1BB07E": 4,
    "22596.2": 2,
    "22596.3": 2,
    "22596.4": 2,
    "22596.5": 2,
    "22596.6": 2,
    "22596.7": 2,
    "22596.12": 2,
    "22596.13": 2,
    "22596.14": 2,
    "22596.19": 2,
    "22596.22": 2,
    "22596.35": 2,
    "22596.36": 2,
    "22596.37": 2,
    "22596.38": 2,
    "22596.39": 2,
    "22596.40": 2,
    "22596.41": 2,
    "22596.42": 2,
    "22596.43": 2,
    "22596.44": 2,
    "22596.45": 2,
    "22596.46": 2,
    "22596.47": 2,
    "22596.48": 2,
    "22596.49": 2,
    "22596.50": 6,
    "22596.51": 3,
    "22596.52": 3,
    "22596.53": 3,
    "22596.54": 3,
    "22596.55": 3,
    "22596.58": 2,
    "9D29F14302C8451741C1169CB32CDF21": 4,
    "581B16FB 5232782601F519C9558B218B": 4,
    "22596.60": 4,
    "22596.61": 2,
    "22596.62": 2,
    "22596.63": 2,
    "22596.65": 2,
    "22596.67": 2,
    "22596.68": 6,
    "22596.69": 2,
    "22596.70": 2,
    "22596.74": 2,
    "22596.76": 2,
    "22596.78": 2,
    "22596.79": 2,
    "22596.80": 2,
    "22596.86": 2,
    "22596.87": 2,
    "22596.88": 2,
    "22596. 89": 2,
    "22596.90": 2,
    "22596.91": 2,
    "22596.92": 2,
    "22596.93": 2,
    "22596.94": 2,
    "22596.95": 2,
    "22596.96": 2,
    "22596.97": 2,
    "817C68343178670A2608D3103FBBED3E": 4,
    "22596.98": 3,
    "22596.99": 2,
    "22596.100": 2,
}

Is the _requestId supposed to be a unique number within the page? What

like image 496
BanksySan Avatar asked Nov 28 '25 23:11

BanksySan


1 Answers

I had the same problem... to solve i coded as follows:

In "on request", use: const requestId = request._interceptionId

In "on response", use: const requestId = response.request()._interceptionId

I hope it works

like image 58
Jonathan Fabra Gomez Avatar answered Nov 30 '25 13:11

Jonathan Fabra Gomez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!