Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,17 @@ See [Commands Reference](./docs/commands_reference.md) for the full command list

## Frontend Inspector

The MageForge Inspector lets you inspect Magento blocks, templates, and performance metrics directly in your browser.
MageForge includes a unified in-browser DevTools dock and panel (strictly CSS-isolated from storefront styles across Luma, Hyvä, and custom themes) for auditing pages and inspecting Magento blocks, templates, cache telemetry, and Web Vitals.

**Features:**

- Template paths, block classes, and module names
- 1-click **Open in IDE** (PhpStorm, VS Code, Cursor, Zed, Sublime Text, or custom URL) with browser-saved Docker/DDEV host path mapping
- 1-click **Override & Open** directly into any editable `app/design/frontend` theme, including automatic cache cleaning
- PHP render times and cache status (lifetime, tags)
- Web Vitals: LCP, CLS, INP per element
- Accessibility checks: ARIA roles, contrast ratios, alt text
- **Unified DevTools Dock & Panel** — Switch between a floating popover and a docked right-hand sidebar drawer in Dark, Light, or Auto colour schemes
- **Interactive Element Inspector** — Compact non-intrusive Hover-HUD on storefront elements, interactive layout/DOM breadcrumbs, and `↑` / `↓` parent/child stepping
- **Page Block & Template Explorer** — Searchable, filterable tree of every rendered Magento block on the page (`All`, `Overrides`, `No Cache`, `Slow >50ms`) with live hover highlighting
- **Main-Thread & Core Web Vitals Profiler** — Live browser `PerformanceObserver` telemetry for TTFB & `Server-Timing` waterfalls, Google 4-phase `LCP` breakdown, `CLS` layout-shift culprits mapped to Magento `.phtml` blocks, runtime Magento AJAX/GraphQL/`customer-data` requests, Long Tasks (`>50 ms`) & `TBT`, Chromium `long-animation-frame` (LoAF) script/reflow attribution, render-blocking resources, and `INP` interactions
- **27 Automated Storefront Audits** — Accessibility (WCAG), SEO, Performance (including Main-Thread Blockers), HTML Quality, and Schema/JSON-LD checks with 1-click **Inspect** handoff from any finding straight to its `.phtml` template
- **1-Click Open in IDE & Template Override** — Open templates in PhpStorm, VS Code, Cursor, Zed, Sublime Text, or custom URLs (with automatic zero-config DDEV bind-mount / Mutagen host-path detection) or copy overrides into editable `app/design/frontend` themes
- **Unified Settings Hub** — Browser-persisted preferences for dock corner, panel layout, dock labels, default override target theme, and IDE path mappings

### Screenshot

Expand Down
46 changes: 46 additions & 0 deletions src/Block/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@
use OpenForgeProject\MageForge\Model\Config\Inspector as InspectorConfig;
use OpenForgeProject\MageForge\Model\ThemeList;
use OpenForgeProject\MageForge\Service\DeveloperAccessChecker;
use OpenForgeProject\MageForge\Service\Inspector\HostPathDetector;
use OpenForgeProject\MageForge\Service\Inspector\OverrideTokenManager;

/**
* Block for MageForge Inspector
*
* Only renders inspector assets when in developer mode, enabled in config, and from allowed IP
*
* @phpstan-import-type DetectedHostPaths from HostPathDetector
*/
class Inspector extends Template
{
/**
* @var array<string, string>|null
* @phpstan-var DetectedHostPaths|null
*/
private ?array $detectedHostPaths = null;

/**
* @param Context $context
* @param State $state
Expand All @@ -36,6 +45,7 @@
* @param ComponentRegistrarInterface $componentRegistrar
* @param DirectoryList $directoryList
* @param DesignInterface $design
* @param HostPathDetector $hostPathDetector
* @param array $data
* @phpstan-param array<string, mixed> $data
*/
Expand All @@ -49,6 +59,7 @@
private readonly ComponentRegistrarInterface $componentRegistrar,
private readonly DirectoryList $directoryList,
private readonly DesignInterface $design,
private readonly HostPathDetector $hostPathDetector,
array $data = [],
) {
parent::__construct($context, $data);
Expand Down Expand Up @@ -236,6 +247,41 @@
return rtrim(str_replace('\\', '/', $this->directoryList->getRoot()), '/');
}

/**
* Get auto-detected host Magento root path from DDEV/container mounts when available
*
* @return string
*/
public function getDetectedHostRoot(): string
{
return $this->getDetectedHostPaths()['hostRoot'];
}

/**
* Get auto-detected external container=host bind-mount mappings when available
*
* @return string
*/
public function getDetectedExternalMappings(): string
{
return $this->getDetectedHostPaths()['externalMappings'];
}

/**
* Memoize container mount path detection per block instance
*
* @return array<string, string>
* @phpstan-return DetectedHostPaths
*/
private function getDetectedHostPaths(): array
{
if ($this->detectedHostPaths === null) {
$this->detectedHostPaths = $this->hostPathDetector->detect();
}

return $this->detectedHostPaths;
}

/**
* Get currently active frontend theme code
*
Expand Down Expand Up @@ -273,13 +319,13 @@
}

$fullPath = $theme->getFullPath();
$themePath = is_string($fullPath) && $fullPath !== ''

Check warning on line 322 in src/Block/Inspector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (Infection)

Escaped Mutant for Mutator "LogicalAnd": @@ @@ } $fullPath = $theme->getFullPath(); - $themePath = is_string($fullPath) && $fullPath !== '' + $themePath = is_string($fullPath) || $fullPath !== '' ? $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $fullPath) : null; $relativePath = '';
? $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $fullPath)
: null;
$relativePath = '';
if (is_string($themePath) && $themePath !== '') {

Check warning on line 326 in src/Block/Inspector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (Infection)

Escaped Mutant for Mutator "LogicalAnd": @@ @@ ? $this->componentRegistrar->getPath(ComponentRegistrar::THEME, $fullPath) : null; $relativePath = ''; - if (is_string($themePath) && $themePath !== '') { + if (is_string($themePath) || $themePath !== '') { $normalizedPath = rtrim(str_replace('\\', '/', $themePath), '/'); $relativePath = $root !== '' && str_starts_with($normalizedPath, $root . '/') ? substr($normalizedPath, strlen($root) + 1)
$normalizedPath = rtrim(str_replace('\\', '/', $themePath), '/');

Check warning on line 327 in src/Block/Inspector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (Infection)

Escaped Mutant for Mutator "UnwrapStrReplace": @@ @@ : null; $relativePath = ''; if (is_string($themePath) && $themePath !== '') { - $normalizedPath = rtrim(str_replace('\\', '/', $themePath), '/'); + $normalizedPath = rtrim($themePath, '/'); $relativePath = $root !== '' && str_starts_with($normalizedPath, $root . '/') ? substr($normalizedPath, strlen($root) + 1) : $normalizedPath;

Check warning on line 327 in src/Block/Inspector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (Infection)

Escaped Mutant for Mutator "UnwrapRtrim": @@ @@ : null; $relativePath = ''; if (is_string($themePath) && $themePath !== '') { - $normalizedPath = rtrim(str_replace('\\', '/', $themePath), '/'); + $normalizedPath = str_replace('\\', '/', $themePath); $relativePath = $root !== '' && str_starts_with($normalizedPath, $root . '/') ? substr($normalizedPath, strlen($root) + 1) : $normalizedPath;
$relativePath = $root !== '' && str_starts_with($normalizedPath, $root . '/')

Check warning on line 328 in src/Block/Inspector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (Infection)

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ $relativePath = ''; if (is_string($themePath) && $themePath !== '') { $normalizedPath = rtrim(str_replace('\\', '/', $themePath), '/'); - $relativePath = $root !== '' && str_starts_with($normalizedPath, $root . '/') + $relativePath = $root !== '' && str_starts_with($normalizedPath, $root) ? substr($normalizedPath, strlen($root) + 1) : $normalizedPath; }

Check warning on line 328 in src/Block/Inspector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (Infection)

Escaped Mutant for Mutator "LogicalAnd": @@ @@ $relativePath = ''; if (is_string($themePath) && $themePath !== '') { $normalizedPath = rtrim(str_replace('\\', '/', $themePath), '/'); - $relativePath = $root !== '' && str_starts_with($normalizedPath, $root . '/') + $relativePath = $root !== '' || str_starts_with($normalizedPath, $root . '/') ? substr($normalizedPath, strlen($root) + 1) : $normalizedPath; }

Check warning on line 328 in src/Block/Inspector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (Infection)

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ $relativePath = ''; if (is_string($themePath) && $themePath !== '') { $normalizedPath = rtrim(str_replace('\\', '/', $themePath), '/'); - $relativePath = $root !== '' && str_starts_with($normalizedPath, $root . '/') + $relativePath = $root !== '' && str_starts_with($normalizedPath, '/') ? substr($normalizedPath, strlen($root) + 1) : $normalizedPath; }
? substr($normalizedPath, strlen($root) + 1)
: $normalizedPath;
}
Expand All @@ -299,11 +345,11 @@
}

ksort($editable);
ksort($readOnly);

Check warning on line 348 in src/Block/Inspector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (Infection)

Escaped Mutant for Mutator "FunctionCallRemoval": @@ @@ } ksort($editable); - ksort($readOnly); + $encoded = json_encode( array_values([...$editable, ...$readOnly]),

$encoded = json_encode(
array_values([...$editable, ...$readOnly]),
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE,

Check warning on line 352 in src/Block/Inspector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (Infection)

Escaped Mutant for Mutator "BitwiseOr": @@ @@ $encoded = json_encode( array_values([...$editable, ...$readOnly]), - JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE, + JSON_UNESCAPED_SLASHES & JSON_UNESCAPED_UNICODE, ); return $encoded !== false ? $encoded : '[]';
);

return $encoded !== false ? $encoded : '[]';
Expand Down
Loading
Loading