Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Browser Kit

Browser Kit Laravel Package

symfony/browser-kit

Symfony BrowserKit simulates a web browser in PHP for testing and automation: make requests, follow links, click buttons, and submit forms programmatically. Includes an implementation powered by Symfony HttpClient for real HTTP requests.

View on GitHub
Deep Wiki
Context7

Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically

Frequently asked questions about Browser Kit
Can I use Symfony BrowserKit for functional testing in Laravel instead of Dusk?
Yes, BrowserKit is a lightweight alternative to Laravel Dusk for testing static HTML interactions like form submissions, link clicks, and redirects. It’s ideal for server-side testing without requiring a headless browser. However, it lacks JavaScript execution, so pair it with Dusk or Playwright for SPAs.
How do I install Symfony BrowserKit in a Laravel project?
Run `composer require symfony/browser-kit` to install the package. No additional Laravel-specific setup is needed—it integrates directly with PHPUnit or PestPHP. For HTTP requests, use Symfony’s HttpClient or Laravel’s built-in `Http` facade for consistency.
Does BrowserKit support Laravel’s testing helpers like `actingAs()`?
BrowserKit doesn’t natively support Laravel’s `actingAs()` or `followRedirects()`, but you can manually handle sessions and redirects using its `getResponse()` and `followRedirect()` methods. For auth flows, combine it with Laravel’s auth helpers or middleware in your test setup.
What Laravel versions and PHP versions does BrowserKit support?
BrowserKit requires PHP 8.1+ and works seamlessly with Laravel 10+ (LTS). It’s compatible with Laravel’s latest versions, as it depends on Symfony components that align with Laravel’s ecosystem. Check the [Symfony docs](https://symfony.com/doc/current/components/browser_kit.html) for minor version specifics.
Can I use BrowserKit for web scraping in Laravel?
Yes, BrowserKit is perfect for scraping static HTML pages, extracting data from forms, or interacting with APIs. For dynamic content (JavaScript-rendered pages), pair it with Symfony Panther or consider Playwright. Use Laravel Queues to run scrapers asynchronously for large-scale tasks.
How do I handle cookies and sessions with BrowserKit in Laravel?
BrowserKit manages cookies automatically during requests. For sessions, use its `getCookieJar()` method to inspect or modify cookies. In Laravel, you can integrate with the session driver (e.g., `session()->put()`) by manually setting cookies before requests or using middleware to persist session state.
Will BrowserKit work with Laravel’s HttpClient or Guzzle?
BrowserKit includes a concrete client using Symfony’s HttpClient, which is compatible with Laravel’s `Http` facade. You can also configure it to use Guzzle by wrapping it in a custom client. This ensures consistency whether you’re testing or making live requests.
Are there performance concerns when running BrowserKit in CI/CD?
BrowserKit is lightweight (~5MB) and fast for most use cases, but parallel requests can slow down CI pipelines. Use HttpClient’s async features or Laravel Queues to distribute workloads. Cache responses aggressively for repeated tests or scrapes to reduce execution time.
How do I test JavaScript-heavy applications with BrowserKit?
BrowserKit doesn’t execute JavaScript, so it’s unsuitable for SPAs or pages relying on client-side rendering. For these cases, use Symfony Panther (headless Chrome) or Laravel Dusk. If you only need to test static HTML forms or APIs, BrowserKit is a solid choice.
What are the alternatives to BrowserKit for Laravel testing?
For headless browser testing, consider Laravel Dusk (deprecated in favor of PestPHP + Playwright) or Playwright for JavaScript-heavy apps. For pure HTTP testing, Guzzle or Symfony HttpClient alone may suffice. BrowserKit excels for lightweight, server-side HTML interactions without browser overhead.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai