Skip to content

Critical fails with net::ERR_ABORTED at file:///*/*.html when making critical CSS for multiple dimensions.Β #618

@VladyslavSavka

Description

@VladyslavSavka

I don't know if it is a bug or if I'm doing something wrong, but on the critical version 4.0.0, my code works just fine. It looks like this:

`const puppeteer = require("puppeteer");

async function testPenthouseWithRealUserAgent() {
  const { generate } = await import("critical");
  const browser = await puppeteer.launch({
    executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
    headless: false,
    args: [
      "--no-sandbox",
      "--disable-setuid-sandbox", 
      "--disable-dev-shm-usage",
      "--disable-blink-features=AutomationControlled",
    ],
  });

  try {
    console.log('πŸš€ Testing critical with real user agent...');

    const criticalCSS = await generate({
      src: 'https://example.com',
      userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
      strict: false, // Don't break on CSS parsing errors
      request: {
        https: {
          rejectUnauthorized: false // Handle TLS certificate issues
        }
      },
      penthouse: {
        blockJSRequests: false,
        userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
        puppeteer: {
          getBrowser: () => {
            console.log('Returning existing browser instance to penthouse');
            return browser;
          },
        },
      },
      dimensions: [
        {
          width: 1300,
          height: 900,
        },
        {
          width: 375,
          height: 667,
        }
      ],
    });
    
    console.log('πŸ“Š Critical CSS result:', criticalCSS);
    console.log('πŸ“Š Critical CSS length:', criticalCSS.css ? criticalCSS.css.length : 'No CSS');
    console.log('πŸ“„ First 200 chars:', criticalCSS.css ? criticalCSS.css.substring(0, 200) : 'No CSS');  
  } catch (error) {
    console.log('❌ Penthouse failed:', error.message);
  }
  
  await browser.close();
}`

The same code when upgraded to version 7.2.1 throws error:
net::ERR_ABORTED at file:///private/var/folders/w0/h7jgcvv57c39qxjq7_snr5q00000gn/T/0118f06a51def9c16c12b60cf64a8f79/b68014cf31423d469b1bfc0c5875fe5b.html

Debugging logs show that critical makes cleanup after successfully making CSS for the first dimension. When it tries to make it for the second dimension, it is not able to read the HTML since it was already deleted.

The question is: Was the creation of CSS for multiple dimensions changed from v4 to v7, or is this a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions