addyosmani / addyosmani/critical

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

未关闭
#618 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
JavaScript
星标
10.3k
派生
390
PR 合并指标
30 天内没有已合并 PR

描述

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?

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。