Skip to content

Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.

fix(pagespeed): skip Lighthouse categories with a null score

Nikolai V.2d6ffe37963b
diff --git a/scripts/pagespeed_check.py b/scripts/pagespeed_check.py
index 4ba0381..837390c 100644
--- a/scripts/pagespeed_check.py
+++ b/scripts/pagespeed_check.py
@@ -155,7 +155,12 @@ def run_pagespeed(
# Lighthouse scores
lr = data.get("lighthouseResult", {})
for cat_key, cat_data in lr.get("categories", {}).items():
- result["lighthouse_scores"][cat_key] = round(cat_data.get("score", 0) * 100)
+ # Lighthouse emits score: null for categories it could not evaluate
+ # (scoreDisplayMode "error"/"notApplicable"). Skip them rather than
+ # multiplying None, and rather than reporting a misleading 0/100.
+ cat_score = cat_data.get("score")
+ if cat_score is not None:
+ result["lighthouse_scores"][cat_key] = round(cat_score * 100)
# Lab metrics from Lighthouse audits
audits = lr.get("audits", {})
diff --git a/tests/test_pagespeed_null_category_score.py b/tests/test_pagespeed_null_category_score.py
new file mode 100644
index 0000000..f5f89f3
--- /dev/null
+++ b/tests/test_pagespeed_null_category_score.py
@@ -0,0 +1,65 @@
+"""Lighthouse emits `score: null` for categories it could not evaluate
+(scoreDisplayMode "error" or "notApplicable"). `cat_data.get("score", 0)`
+only defaults on a *missing* key, so an explicit null reached the multiply
+and raised TypeError, losing the whole PSI run — including the categories
+that did score.
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+from unittest import mock
+
+ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(ROOT / "scripts"))
+
+import pagespeed_check # noqa: E402
+
+
+class _Response:
+ status_code = 200
+
+ def __init__(self, payload):
+ self._payload = payload
+
+ def raise_for_status(self):
+ return None
+
+ def json(self):
+ return self._payload
+
+
+def _psi_payload():
+ return {
+ "analysisUTCTimestamp": "2026-08-29T00:00:00.000Z",
+ "lighthouseResult": {
+ "categories": {
+ "performance": {"score": 0.91},
+ "accessibility": {"score": None}, # not evaluated
+ "seo": {"score": 0.5},
+ },
+ "audits": {},
+ },
+ }
+
+
+def test_null_category_score_does_not_crash_the_run():
+ with mock.patch.object(
+ pagespeed_check.requests, "get", return_value=_Response(_psi_payload())
+ ):
+ result = pagespeed_check.run_pagespeed("https://example.com")
+
+ assert result["error"] is None, result["error"]
+ assert result["lighthouse_scores"]["performance"] == 91
+ assert result["lighthouse_scores"]["seo"] == 50
+
+
+def test_unscored_category_is_omitted_not_reported_as_zero():
+ with mock.patch.object(
+ pagespeed_check.requests, "get", return_value=_Response(_psi_payload())
+ ):
+ result = pagespeed_check.run_pagespeed("https://example.com")
+
+ # A category Lighthouse refused to score is absent, not a 0/100 failure.
+ assert "accessibility" not in result["lighthouse_scores"], result["lighthouse_scores"]