playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[BUG] Protocol error (Network.getResponseBody): Request content was evicted from inspector cache

Open Ajaykumbhare opened this issue 2 years ago • 21 comments

I am trying to read a large JSON file around 24.9 MB using playwright. When I am making the request and trying to read the body using the playwright.BrowserContext response event but I am getting this error response.json: Protocol error (Network.getResponseBody): Request content was evicted from inspector cache at BrowserContext.<anonymous>

This issue is raised and it's closed. I have tried to execute same code snippet but it's not working in playwright.

  • Playwright Version: 1.20.1
  • Operating System: macOS Monterey v12.3 ( M1 )
  • Node.js version: v17.7.0
  • Browser: Chromium

What steps will reproduce the problem?

import playwright from 'playwright';

const getBrowser = async () => {
  const launchOptions = {
    devtools: false,
    headless: false,
    ignoreDefaultArgs: ['--disable-extensions', '--enable-automation'],
    args: [`--start-maximized`],
  };
  const browser = await playwright['chromium'].launch(launchOptions);
  const context = await browser.newContext({ viewport: null });
  return {
    context: context,
    newPage: () => context.newPage(),
    close: () => browser.close(),
  };
};

(async () => {
  const { newPage, context } = await getBrowser();
  const page = await newPage();
  const client = await page.context().newCDPSession(page);
  await client.send('Page.setLifecycleEventsEnabled', { enabled: true });
  await client.send('Network.enable', {
    maxResourceBufferSize: 1024 * 1204 * 100,
    maxTotalBufferSize: 1024 * 1204 * 200,
  });

  context.on('response', async (response) => {
    try {
      const url = response.url();
      if (url.includes('json')) {
        await response.json();
        // getting error in console:
      }
    } catch (e) {
      console.log(e);
    }
  });

  await page.goto(`https://raw.githubusercontent.com/json-iterator/test-data/master/large-file.json`, {
    waitUntil: 'networkidle',
  });
})();

What is the expected result? The expected result it the response of JSON

What happens instead? It throws following error

Protocol error (Network.getResponseBody): Request content was evicted from inspector cache
   at BrowserContext.<anonymous>

Ajaykumbhare avatar Apr 09 '22 07:04 Ajaykumbhare

Chromium holds a maximum of 10 megabytes in memory for resources, see here and here.

In theory it should be possible to increase it with Network.enable, but this needs to be done in Playwright's CDP session. I tried to increase it and it was working then fine with your repro.

Will clarify it with the team later.

mxschmitt avatar Apr 11 '22 10:04 mxschmitt

We'll p3 it for now an collecting feedback to see if other folks run into it since loading 10mb+ bodies is not very common.

mxschmitt avatar Apr 11 '22 16:04 mxschmitt

I ran into this issue. Is there a workaround for the time being?

hamtonp avatar Apr 22 '22 20:04 hamtonp

Running into the same issue while trying to download video clips of ~12-15 MB. I tried

await client.send('Network.enable', {
    maxResourceBufferSize: 1024 * 1024 * 25,
    maxTotalBufferSize: 1024 * 1024 * 1000,
});

which works in Puppeteer but not in Playwright.

manuelbieh avatar Jun 20 '22 21:06 manuelbieh

Could someone give a workaround for this problem?

meotimdihia avatar Aug 01 '22 06:08 meotimdihia

Same problem here…

dwt avatar Aug 26 '22 08:08 dwt

Firefox has the same problem.

meotimdihia avatar Jan 28 '23 07:01 meotimdihia

Me too.

gcil125 avatar Mar 06 '23 07:03 gcil125

me too

wacdev avatar Apr 02 '23 23:04 wacdev

Parse the json from html page.content() instead of response.json()

sspread avatar Apr 12 '23 06:04 sspread

Same problem here

tiqii avatar May 09 '23 10:05 tiqii

Same 😢

danvoyce avatar Aug 22 '23 12:08 danvoyce

Same problem

Verm1n avatar Sep 06 '23 14:09 Verm1n

Same problem,How to solve?

qingdaoqin avatar Sep 13 '23 04:09 qingdaoqin

Same problem

Ayu889900 avatar Nov 26 '23 03:11 Ayu889900

Same problem

hcura-qa avatar Nov 30 '23 17:11 hcura-qa

In theory it should be possible to increase it with Network.enable, but this needs to be done in Playwright's CDP session. I tried to increase it and it was working then fine with your repro.

Just hit this issue.

How to send 'Network.enable' command for the Playwright's CDP session? Sending this command in CDPSession returned by newCDPSession is not working

blikblum avatar Jan 09 '24 12:01 blikblum

hey, any updates on this issue. I'm still getting the same Error: response.json: Protocol error (Network.getResponseBody): Request content was evicted from inspector cache when the response resource was only 7.8MB Any workaround or at least any timeline when we can expect it to be fixed, looks like it's opened for more then a year and a half now, image

Ahsanmumtaz1105 avatar Feb 10 '24 09:02 Ahsanmumtaz1105

Me too.

akichim21 avatar May 12 '24 13:05 akichim21

The problem is gone when I switched the browser to Firefox.

chow-chun-mun avatar Jul 01 '24 18:07 chow-chun-mun