提交qiming-dev-inject

This commit is contained in:
Codex
2026-06-01 12:53:19 +08:00
parent 96af3b324b
commit 9e9486b7c2
76 changed files with 6397 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env*.local
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts

View File

@@ -0,0 +1,32 @@
# Next.js App Router 测试项目
这是一个用于测试 dev-inject 框架感知注入功能的 Next.js App Router 项目。
## 安装依赖
```bash
npm install
```
## 启动开发服务器
```bash
npm run dev
```
项目将在 http://localhost:3000 运行。
## 测试步骤
1. 启动项目:`npm run dev`
2. 使用 dev-inject 注入监控脚本
3. 点击页面上的按钮触发各种错误
4. 在浏览器控制台运行 DevMonitor 命令查看监控信息
## DevMonitor 命令
- `DevMonitor.showPanel()` - 显示监控面板
- `DevMonitor.getStats()` - 获取统计信息
- `DevMonitor.clearErrors()` - 清除错误记录
- `window.__DEV_INJECT__` - 检查注入状态

View File

@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

View File

@@ -0,0 +1,32 @@
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import './globals.css'
const inter = Inter({ subsets: ['latin'] })
export const metadata: Metadata = {
title: 'Next.js App Test - dev-inject',
description: '测试 dev-inject 框架感知注入功能',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<head>
{/* DEV-INJECT-START */}
{process.env.NODE_ENV === 'development' && (
<script dangerouslySetInnerHTML={{
__html: "(function() {\n const remote = \"https://testagent.xspaceagi.com/sdk/dev-monitor.js\";\n const separator = remote.includes('?') ? '&' : '?';\n const script = document.createElement('script');\n script.src = remote + separator + 't=' + Date.now();\n script.dataset.id = 'dev-inject-monitor-script';\n script.defer = true;\n // 防止重复注入\n if (!document.querySelector('[data-id=\"dev-inject-monitor-script\"]')) {\n document.head.appendChild(script);\n }\n })();"
}} />
)}
{/* DEV-INJECT-END */}
</head>
<body className={inter.className}>{children}</body>
</html>
)
}

View File

@@ -0,0 +1,85 @@
'use client'
import { useState } from 'react'
export default function Home() {
const [errors, setErrors] = useState<string[]>([]);
const triggerError = () => {
try {
throw new Error('测试错误 - Next.js App Router');
} catch (error) {
setErrors(prev => [...prev, (error as Error).message]);
}
};
const triggerAsyncError = () => {
Promise.reject(new Error('异步错误测试 - Next.js App'));
};
const clearErrors = () => {
setErrors([]);
};
return (
<main className="min-h-screen bg-gradient-to-br from-blue-500 to-purple-600 text-white">
<div className="container mx-auto px-4 py-8">
<header className="text-center mb-12">
<h1 className="text-4xl font-bold mb-4">🟢 Next.js App Router Test</h1>
<p className="text-xl opacity-90"> dev-inject </p>
</header>
<div className="max-w-2xl mx-auto">
<div className="bg-white/10 backdrop-blur-md rounded-xl p-6 mb-6">
<h2 className="text-2xl font-semibold mb-4">🚀 </h2>
<div className="flex flex-wrap gap-3 justify-center">
<button
onClick={triggerError}
className="px-6 py-3 bg-red-500 hover:bg-red-600 rounded-lg font-medium transition-colors"
>
</button>
<button
onClick={triggerAsyncError}
className="px-6 py-3 bg-red-500 hover:bg-red-600 rounded-lg font-medium transition-colors"
>
</button>
<button
onClick={clearErrors}
className="px-6 py-3 bg-gray-600 hover:bg-gray-700 rounded-lg font-medium transition-colors"
>
</button>
</div>
</div>
<div className="bg-white/10 backdrop-blur-md rounded-xl p-6 mb-6">
<h2 className="text-2xl font-semibold mb-4">📊 </h2>
{errors.length === 0 ? (
<p className="text-gray-300 italic"></p>
) : (
<div className="space-y-2">
{errors.map((error, index) => (
<div key={index} className="bg-red-500/20 border-l-4 border-red-500 p-3 rounded font-mono text-sm">
{error}
</div>
))}
</div>
)}
</div>
<div className="bg-white/10 backdrop-blur-md rounded-xl p-6">
<h2 className="text-2xl font-semibold mb-4">🔧 DevMonitor </h2>
<p className="mb-3"></p>
<ul className="space-y-1 text-left max-w-md mx-auto">
<li><code className="bg-black/20 px-2 py-1 rounded">DevMonitor.showPanel()</code> - </li>
<li><code className="bg-black/20 px-2 py-1 rounded">DevMonitor.getStats()</code> - </li>
<li><code className="bg-black/20 px-2 py-1 rounded">window.__DEV_INJECT__</code> - </li>
</ul>
</div>
</div>
</div>
</main>
)
}

View File

@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
module.exports = nextConfig

View File

@@ -0,0 +1,25 @@
{
"name": "next-app-test",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"react": "^18",
"react-dom": "^18",
"next": "14.0.0"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10.0.1",
"postcss": "^8",
"tailwindcss": "^3.3.0"
}
}

View File

@@ -0,0 +1,7 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

View File

@@ -0,0 +1,12 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}',
],
theme: {
extend: {},
},
plugins: [],
}

View File

@@ -0,0 +1,28 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}