question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: No data found for resource with given identifier

See original GitHub issue

Perhaps you can help me with this, I try to get body from some ajax request on the page, but I all time getting Error: No data found for resource with given identifier and looks like problem only with this request, maybe I’m missing something

const CDP = require('chrome-remote-interface');

setTimeout(() => {
    CDP(async (client) => {
        const {Network, Page, Runtime} = client;
        Network.requestWillBeSent(({requestId, request}) => {
            if(request.url.indexOf("ct2/results/rpc") != -1){
                console.log(`REQ [${requestId}] ${request.method} ${request.url} \n`);
            }
        });
        Network.responseReceived(async ({requestId, response}) => {
            if(response.url.indexOf("ct2/results/rpc") != -1){
                const {body, base64Encoded} = await Network.getResponseBody({requestId});
                console.log(`RES [${requestId}] body: ${body} \n`);
            }
        });
        try {
            await Promise.all([Network.enable(), Page.enable()]);
            await Page.navigate({url: 'https://clinicaltrials.gov/ct2/results?cond=Parents&term=&cntry1=&state1=&Search=Search&recrs=a#wrapper'});
            await Page.loadEventFired();
            await Runtime.evaluate({
                expression: `document.querySelector('.paginate_button.next').click()`
            });
        } catch (err) {
            console.error(err);
        }
    }).on('error', (err) => {
        console.error(err);
    });
}, 1000);

Thanks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:24 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
cyrus-andcommented, Sep 9, 2017

This happens because AFAIK you’re only allowed to call Network.getResponseBody when the Network.loadingFinished event has fired. Unfortunately this event doesn’t contain the associated request object so you have to keep track of the requestId for which you want to fetch the response body.

I implemented this in the following using a Set:

const CDP = require('chrome-remote-interface');

setTimeout(() => {
    CDP(async (client) => {
        const {Network, Page, Runtime} = client;

        const requests = new Set(); // <---------- HERE

        Network.requestWillBeSent(({requestId, request}) => {
            if(request.url.indexOf("ct2/results/rpc") != -1){
                console.log(`REQ [${requestId}] ${request.method} ${request.url} \n`);

                requests.add(requestId); // <---------- HERE

            }
        });
        Network.loadingFinished(async ({requestId}) => {

            if (requests.has(requestId)) { // <---------- HERE

                const {body, base64Encoded} = await Network.getResponseBody({requestId});
                console.log(`RES [${requestId}] body: ${body} \n`);
            }
        });
        try {
            await Promise.all([Network.enable(), Page.enable()]);
            await Page.navigate({url: 'https://clinicaltrials.gov/ct2/results?cond=Parents&term=&cntry1=&state1=&Search=Search&recrs=a#wrapper'});
            await Page.loadEventFired();
            await Runtime.evaluate({
                expression: `document.querySelector('.paginate_button.next').click()`
            });
        } catch (err) {
            console.error(err);
        }
    }).on('error', (err) => {
        console.error(err);
    });
}, 1000);
2reactions
bookincommented, Sep 9, 2017

Thank you very much for your help, only you are helping people)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome Extension: "No resource with given identifier found ...
To solve this, just use a single debugger and do not detach it, or only detach when it's safe to. var gAttached =...
Read more >
Can't get API to work - JavaScript - The freeCodeCamp Forum
The response section simply says “Failed to load response data: no data found for resource with given identifier.”
Read more >
[HTTP Request Error] Failed to load response data
[HTTP Request Error] Failed to load response data ... Body: Failed to load response data: No data found for resource with given identifier....
Read more >
Chrome Extension: “No resource with given identifier found ...
I'm writing a Chrome Extension that can get HTTP response for a site. I try to use debugger for getting response body: var...
Read more >
How to Fix Chrome's Failed to Load Response Data Error
2. Add a breakpoint in the Sources tab · In Chrome DevTools, click on the Sources tab.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found