microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.49k stars 3.57k forks source link

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

Open Ajaykumbhare opened 2 years ago

Ajaykumbhare commented 2 years ago

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.

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>
mxschmitt commented 2 years ago

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 commented 2 years ago

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.

hamtonp commented 2 years ago

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

manuelbieh commented 2 years ago

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.

meotimdihia commented 2 years ago

Could someone give a workaround for this problem?

dwt commented 2 years ago

Same problem here…

meotimdihia commented 1 year ago

Firefox has the same problem.

gcil125 commented 1 year ago

Me too.

wacdev commented 1 year ago

me too

sspread commented 1 year ago

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

tiqii commented 1 year ago

Same problem here

danvoyce commented 1 year ago

Same 😢

Verm1n commented 1 year ago

Same problem

qingdaoqin commented 12 months ago

Same problem,How to solve?

Ayu889900 commented 9 months ago

Same problem

hcura-qa commented 9 months ago

Same problem

blikblum commented 8 months ago

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

Ahsanmumtaz1105 commented 7 months ago

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

akichim21 commented 3 months ago

Me too.

chow-chun-mun commented 2 months ago

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

Docdez commented 1 week ago

I join in