Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser crashes when a navigational request is aborted using --single-process flag #253

Open
heaven opened this issue Apr 3, 2024 · 1 comment
Labels

Comments

@heaven
Copy link

heaven commented Apr 3, 2024

This is rather a question, not a bug report.

The main problem is when intercepting a navigation request (e.g. a link to a page points or redirects to a pdf or another type of document we don't want to).

For example a simple approach:

  // Enable request interceptions
  await page.setRequestInterception(true);

  // do not load images and fonts
  await page.on("request", (request) => {
    if (request.isInterceptResolutionHandled()) return;

    if (request.isNavigationRequest())
      request.abort("blockedbyclient");
    else
      request.continue();
  });

Or intercepting the response:

  const client = await page.createCDPSession();
  const cTypeHeader = "content-type";
  const cTypeExp = /\bhtml\b/i;
  const errorReason = "BlockedByClient";

  // intercept request when response headers were received
  await client.send('Fetch.enable', {
    patterns: [{ urlPattern: '*', resourceType: 'Document', requestStage: 'Response' }],
  });

  await client.on('Fetch.requestPaused', async evt => {
    const requestId = evt.requestId;
    const status = evt.responseStatusCode;

    if (status >= 200 && status <= 299) {
      const headers = evt.responseHeaders || [];
      const contentType = headers.find(h => h.name.toLowerCase() == cTypeHeader)?.value;

      // Do not allow anything other than html document.
      if (contentType && !cTypeExp.test(contentType))
        return await client.send('Fetch.failRequest', { requestId, errorReason }).catch(none);
    }

    await client.send('Fetch.continueRequest', { requestId }).catch(none);
  });

Both lead to the same situation when the browser kills the renderer and occasionally dies as they are in a single process 😀

The bug report is here and I was about to submit one more with crbug.com. But was also wondering if it is possible to run chromium without the --single-process flag. I tried just removing the flag but didn't have much success so far.

@heaven heaven added the bug Something isn't working label Apr 3, 2024
@Sparticuz Sparticuz added upstream and removed bug Something isn't working labels Apr 4, 2024
@Sparticuz Sparticuz changed the title [Bug]: Browser crashes when a navigational request is aborted using --single-process flag Browser crashes when a navigational request is aborted using --single-process flag Apr 4, 2024
@Sparticuz
Copy link
Owner

This is the comment I have in the code for --single-process

// Needs to be single-process to avoid `prctl(PR_SET_NO_NEW_PRIVS) failed` error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants