Protocol error (Page.getResourceContent): Agent is not enabled. (Puppeteer)

Protocol error (Page.getResourceContent): Agent is not enabled. (Puppeteer)

Problem Description:

I’m having a problem running this code.

const client = await page.target().createCDPSession();
    const content = await client.send("Page.getResourceContent", {
      frameId: String(page.mainFrame()._id),
      url,
    });

I got this error:

{
  level: 'debug',
  message: 'Protocol error (Page.getResourceContent): Agent is not enabled.',
  name: 'ProtocolError'
}

PS: in the old version of puppeteer i used the code below and it worked fine.

const content = await page._client.send("Page.getResourceContent", {
      frameId: String(page.mainFrame()._id),
      url,
    });

Anyone know why??

i haven’t figured out a solution for this and i couldn’t understand what this error means.

Solution – 1

The error message "Agent is not enabled" has nothing to do with the HTTP User-Agent header but refers to an agent within chrome that needs to be enabled in order to retrieve page contents.

The term "agent" is a bit misleading since the protocol documentation speaks about domains which need to be enabled in order to debug them (the term "agent" refers to the way this is implemented in Chrome internally, I suppose)

So, the question is which domain does need to be enabled in order to access the page contents? In hindsight it is quite obvious: the Page domain needs to be enabled as we are calling a method in this domain. I only found this out after stumbling over this example, though.

Once I added the Page.enable request to script to activate the Page domain, the error message disappeared.

My solution:

      const client = await page.target().createCDPSession();

      await client.send("Page.enable");       
      await client.send("DOM.enable");        
      await client.send("Network.enable");    

      const content = await client.send("Page.getResourceContent", {
      frameId: String(page.mainFrame()._id),
      url,
    });
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject