dakshraman/laravel-browser-guard
Composer 安装命令:
composer require dakshraman/laravel-browser-guard
包简介
A Laravel package to discourage right-click, shortcut keys, and casual DevTools access in the browser.
README 文档
README
A Laravel package that discourages:
- right click / context menu
- selected shortcut keys like
F12,Ctrl+Shift+I,Ctrl+Shift+J,Ctrl+Shift+C,Ctrl+U - casual DevTools opening through simple browser-side detection
Important note
This package does not provide real security. Anything running in the browser can be bypassed by a determined user. Use it only as a UI deterrent, not as a protection layer for sensitive data.
Requirements
- PHP 8.1+
- Laravel 10, 11, 12, or 13
Installation
composer require dakshraman/laravel-browser-guard php artisan browser-guard:install
The install command will publish config and assets, then walk you through configuration interactively:
Which guards would you like to enable?
Block right-click / context menu? (yes/no) [yes]:
> yes
Block keyboard shortcuts (F12, Ctrl+U, etc.)? (yes/no) [yes]:
> yes
Detect DevTools opening? (yes/no) [yes]:
> yes
How should Browser Guard run?
[global] - Script loads on every page with @browserGuardScripts
[middleware]- Script loads only on routes using browser.guard middleware
Select mode [global]:
[0] global
[1] middleware
> 0
Show alert when a guard is triggered? (yes/no) [yes]:
> yes
Alert message [This action is disabled on this page.]:
>
What should happen when DevTools is detected?
DevTools action [alert]:
[0] alert
[1] redirect
[2] blank
> 0
Configuration saved to config/browser-guard.php
Skip interactive prompts
For CI or scripted installs, use --skip-config:
php artisan browser-guard:install --skip-config
Manual publish
php artisan vendor:publish --tag=browser-guard-config php artisan vendor:publish --tag=browser-guard-assets
Add the script to your layout
In your main Blade layout, just before </body>:
@browserGuardScripts
Usage modes
1. Global mode
'mode' => 'global',
The script will load wherever @browserGuardScripts exists.
2. Middleware mode
'mode' => 'middleware',
Then apply the middleware only to routes you want to protect:
Route::middleware('browser.guard')->group(function () { Route::get('/protected-page', function () { return view('welcome'); }); });
The middleware also sets no-cache headers to prevent browser caching of protected pages.
Configuration
// Master switch 'enabled' => true, // Mode: 'global' or 'middleware' 'mode' => 'global', // Guards 'block_right_click' => true, 'block_shortcuts' => true, 'detect_devtools' => true, // Alert UI 'show_alert' => true, 'alert_message' => 'This action is disabled on this page.', // DevTools handling: 'alert' | 'redirect' | 'blank' 'devtools_action' => 'alert', 'devtools_message' => 'Developer tools detected. This page is protected.', 'devtools_redirect_url' => '/', 'devtools_check_interval' => 1000, 'devtools_threshold' => 160,
Custom shortcuts
'shortcuts' => [ ['key' => 'F12'], ['ctrl' => true, 'shift' => true, 'key' => 'I'], ['ctrl' => true, 'shift' => true, 'key' => 'J'], ['ctrl' => true, 'shift' => true, 'key' => 'C'], ['ctrl' => true, 'key' => 'U'], ],
Excluding paths
'except_paths' => [ 'admin/api/*', 'health-check', ],
Testing
composer test
File structure
browser-guard/
├── composer.json
├── config/
│ └── browser-guard.php
├── resources/
│ ├── js/
│ │ └── browser-guard.js
│ └── views/
│ └── script.blade.php
└── src/
├── BrowserGuardServiceProvider.php
├── Commands/
│ └── InstallBrowserGuardCommand.php
└── Middleware/
└── BrowserGuardMiddleware.php
License
MIT
dakshraman/laravel-browser-guard 适用场景与选型建议
dakshraman/laravel-browser-guard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「browser」 「laravel」 「shortcuts」 「guard」 「Devtools」 「right-click」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dakshraman/laravel-browser-guard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dakshraman/laravel-browser-guard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dakshraman/laravel-browser-guard 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Give your JS App some Backbone with Models, Views, Collections, and Events.
Add customisable Shortcut-Links to the Control Panel Sidebar
Instrument headless chrome/chromium instances from php5.6
Selenium4 (WebDriver) driver for Mink framework
Clusteer is a Puppeteer wrapper written for PHP, with the super-power of parallelizing pages across multiple browser instances.
Standalone replacement for php's native get_browser() function
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 39
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-22