使用Lighthouse CLI测试所有网站时mobile-friendly均返回false的问题咨询
audits.mobile-friendly.rawValue Always Returning False in Lighthouse CLI Let me walk through the most common reasons you might be seeing this issue, and how to debug each one:
1. You're running Lighthouse in Desktop Mode
If your CLI command includes the --desktop flag or uses a desktop preset, Lighthouse will simulate a desktop environment instead of mobile. Since the mobile-friendly audit is designed to validate mobile-specific criteria (like viewport settings, touch targets, etc.), running it against a desktop configuration will almost always return false.
Fix: Remove any --desktop flags, or explicitly specify the mobile preset with:
lighthouse <url> --preset=mobile --output=json --quiet
2. You're Misinterpreting What rawValue Represents
The audits.mobile-friendly.rawValue isn't a direct 1:1 match with Google's official Mobile-Friendly Test result. Lighthouse's version of this audit requires all mobile-friendly sub-checks to pass for rawValue to be true. Even a single failure (e.g., missing viewport meta tag, text too small, touch targets too close) will set this value to false.
Debug: Run Lighthouse on a site you know is mobile-friendly and inspect the full audit details in the JSON output. Look for audits['mobile-friendly'].details.items—this will list exactly which sub-checks failed, even if the site seems mobile-friendly at a glance.
3. Your Node Script Has a Property Access Error
In JavaScript, object properties with hyphens can't be accessed using dot notation. If your script is using audits.mobile-friendly.rawValue, that's invalid syntax (it will interpret mobile-friendly as a subtraction operation) and likely returning undefined, which you might be accidentally coercing to false.
Fix: Use bracket notation to access the audit correctly:
const mobileFriendlyValue = audits['mobile-friendly'].rawValue;
4. Network/Loading Issues Are Skewing Results
If your test environment has slow network speeds, proxy issues, or the sites you're testing fail to load completely, Lighthouse might miss critical mobile-friendly elements (like the viewport meta tag). This will cause the audit to fail even if the site is actually mobile-friendly.
Debug: Add the --view flag to your CLI command to generate an HTML report. Open the report and check the Mobile Friendly section—this will show you exactly why the audit failed, including any loading-related issues.
5. All Tested Sites Actually Fail Mobile-Friendly Checks
It's possible (though unlikely) that every site you're testing fails at least one of Lighthouse's mobile-friendly criteria. Use the HTML report from the previous step to verify each site's specific failures—you might be surprised how many sites overlook small details like touch target spacing or font size.
内容的提问来源于stack exchange,提问作者jonkeegan

