Laravel Türkiye Discord Kanalı Forumda kod paylaşılırken dikkat edilmesi gerekenler!Birlikte proje geliştirmek ister misiniz?
  • YardımLaravel
  • Spatie Lighthouse paketini kurduktan sonra böyle bir hata alıyorum.

Could not run Lighthouse. Error :node:internal/process/promises:288 triggerUncaughtException(err, true /* fromPromise */); ^ ChromeNotInstalledError at new LauncherError (file:///C:/xampp/htdocs/e-ticaret/node_modules/chrome-launcher/dist/utils.js:22:22) at new ChromeNotInstalledError (file:///C:/xampp/htdocs/e-ticaret/node_modules/chrome-launcher/dist/utils.js:49:9) at Launcher.launch (file:///C:/xampp/htdocs/e-ticaret/node_modules/chrome-launcher/dist/chrome-launcher.js:192:23) at Module.launch (file:///C:/xampp/htdocs/e-ticaret/node_modules/chrome-launcher/dist/chrome-launcher.js:33:20) at C:\xampp\htdocs\e-ticaret\vendor\spatie\lighthouse-php\bin\lighthouse.js:7:41 { message: 'No Chrome installations found.', code: 'ERR_LAUNCHER_NOT_INSTALLED' } Node.js v18.20.7 ``

https://spatie.be/docs/lighthouse-php/v1/installation-setup burada bahsedilen her şeyi kurdum fakat çözüme ulaşamadım.

<?php

namespace App\Filament\Admin\Resources\AdminResource\Pages;

use Filament\Forms;
use Filament\Pages\Page;
use Filament\Actions\Action;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\Storage;
use Spatie\Lighthouse\Lighthouse;
use Spatie\Lighthouse\Enums\Category;
use Filament\Support\Exceptions\Halt;
use Filament\Tables\Columns\TextColumn;

class LighthouseAnalysis extends Page implements Forms\Contracts\HasForms
{
    use Forms\Concerns\InteractsWithForms;

    protected static ?string $navigationLabel = 'Lighthouse Analizi';
    protected static ?string $title = 'Lighthouse Sayfa Analizi';
    protected static ?int $navigationSort = 5;

    public $url = '';
    public $performance = true;
    public $accessibility = true;
    public $bestPractices = true;
    public $seo = true;
    public $pwa = false;
    public $throttleCpu = true;
    public $scores = [];
    public $audits = [];
    public $hasResult = false;
    public $reportPath = null;

    protected static string $view = 'filament.pages.lighthouse-analysis';

    public function mount(): void
    {
        $this->form->fill();
    }

    public function form(Form $form): Form
    {
        return $form
            ->schema([
                Grid::make(3)
                    ->schema([
                        TextInput::make('url')
                            ->label('URL')
                            ->placeholder('https://example.com')
                            ->required()
                            ->url()
                            ->columnSpan(2),
                    ]),
                Grid::make(5)
                    ->schema([
                        Checkbox::make('performance')
                            ->label('Performans')
                            ->default(true),
                        Checkbox::make('accessibility')
                            ->label('Erişilebilirlik')
                            ->default(true),
                        Checkbox::make('bestPractices')
                            ->label('En İyi Uygulamalar')
                            ->default(true),
                        Checkbox::make('seo')
                            ->label('SEO')
                            ->default(true),
                        Checkbox::make('pwa')
                            ->label('PWA')
                            ->default(false),
                    ]),
                Grid::make(1)
                    ->schema([
                        Checkbox::make('throttleCpu')
                            ->label('CPU Kısıtlaması (Daha doğru sonuçlar için)')
                            ->default(true),
                    ])
            ]);
    }

    public function runAnalysis(): void
    {
        $this->validate();

        try {
            $lighthouse = Lighthouse::url($this->url);

            // Kategorileri ekleme
            $categories = [];
            if ($this->performance) $categories[] = Category::Performance;
            if ($this->accessibility) $categories[] = Category::Accessibility;
            if ($this->bestPractices) $categories[] = Category::BestPractices;
            if ($this->seo) $categories[] = Category::Seo;
            if ($this->pwa) $categories[] = Category::Pwa;

            if (empty($categories)) {
                Notification::make()
                    ->title('En az bir kategori seçmelisiniz.')
                    ->danger()
                    ->send();
                return;
            }

            $lighthouse->categories(...$categories);

            // CPU kısıtlaması
            if ($this->throttleCpu) {
                $lighthouse->throttleCpu();
            }

            // Notification to inform user analysis is starting
            Notification::make()
                ->title('Analiz başlatılıyor...')
                ->success()
                ->send();

            // Run the analysis
            $result = $lighthouse->run();

            // Get scores and update the page
            $this->scores = $result->scores();

            // Get some important audits
            $this->audits = [
                'first-contentful-paint' => $result->audit('first-contentful-paint'),
                'largest-contentful-paint' => $result->audit('largest-contentful-paint'),
                'total-blocking-time' => $result->audit('total-blocking-time'),
                'cumulative-layout-shift' => $result->audit('cumulative-layout-shift'),
                'speed-index' => $result->audit('speed-index'),
            ];

            // Save HTML report
            $filename = md5($this->url) . '-' . now()->format('YmdHis') . '.html';
            $path = 'lighthouse/' . $filename;
            $fullPath = storage_path('app/public/' . $path);

            // Ensure directory exists
            if (!file_exists(dirname($fullPath))) {
                mkdir(dirname($fullPath), 0755, true);
            }

            $result->saveHtml($fullPath);
            $this->reportPath = Storage::url($path);

            $this->hasResult = true;

            Notification::make()
                ->title('Analiz başarıyla tamamlandı!')
                ->success()
                ->send();
        } catch (\Exception $e) {
            Notification::make()
                ->title('Hata oluştu!')
                ->body($e->getMessage())
                ->danger()
                ->send();
        }
    }

    protected function getFormActions(): array
    {
        return [
            Action::make('runAnalysis')
                ->label('Analiz Et')
                ->submit(),
        ];
    }

    protected function getHeaderActions(): array
    {
        return [];
    }
}

    koti42

    $lighthouse = new Lighthouse($url);
    
    $lighthouse->withChromeOptions([
        'chromeFlags' => [
            '--headless',
        ],
        'chromePath' => [
            '/path/to/chrome/binary',
        ]
    ]);
    
    //...
    
    $lighthouse->run();

    Burada /path/to/chrome/binary kısmını Chrome binary neredeyse orayı değiştirerek deneyebilir misiniz? Windows kullandığınız için exe yolunu tam olarak yazacaksınız, mesela C:/Program Files/Google/Chrome/Application/chrome.exe gibi.

      mgsmus Direk ana sunucuda da denedim abi aslında aynı hatayı aldım devamlı olarak. En sonunda sinir etti

      Api de patlıyor cevap vermiyor arada ama günün sonunda çözüldü diyebilirim