c165f2f788
Agrega 19 issues técnicas documentando funcionalidades implementadas y pendientes. Issues completadas (movidas a dev/issues/completed/): - 001-conversor-web-markdown.md - 002-accessibility-tree.md - 003-gestion-cookies-perfil.md - 004-gestion-extensiones-chrome.md - 005-eliminar-timeouts-innecesarios.md Issues implementadas: - 006-manejo-tabs-ventanas.md - 016-manejo-iframes.md - 017-actions-api.md - 018-file-uploads.md - 019-expected-conditions-mejoradas.md Issues pendientes (media prioridad): - 007-alert-prompt-confirm-handling.md - 008-screenshot-elementos-especificos.md - 009-pdf-generation.md - 010-device-emulation-completo.md - 011-downloads-handling.md Issues pendientes (baja prioridad / avanzado): - 012-browser-contexts-multi-sesion.md - 013-video-recording.md - 014-network-mocking-avanzado.md - 015-geolocation-permissions.md Incluye también dev/NUEVAS_FUNCIONALIDADES.md con resumen completo. Directorio: dev/
110 lines
2.9 KiB
Markdown
110 lines
2.9 KiB
Markdown
# Issue #014: Network Mocking Avanzado
|
|
|
|
**Tipo**: Enhancement
|
|
**Prioridad**: Baja (Avanzado)
|
|
**Estado**: Pendiente
|
|
|
|
## Descripción
|
|
|
|
Implementar sistema avanzado de interceptación y mocking de requests HTTP/HTTPS.
|
|
|
|
## Funcionalidad deseada
|
|
|
|
- Interceptar requests antes de enviar
|
|
- Modificar request (URL, headers, body, method)
|
|
- Mock responses completas
|
|
- Simular latencia de red
|
|
- Simular errores de red
|
|
- Registro de todas las requests
|
|
- Pattern matching avanzado (regex, wildcards)
|
|
- Condicional (solo interceptar si...)
|
|
|
|
## API propuesta
|
|
|
|
```go
|
|
type MockResponse struct {
|
|
Status int
|
|
Headers map[string]string
|
|
Body string
|
|
Delay time.Duration
|
|
}
|
|
|
|
type InterceptorFunc func(req *Request) (*MockResponse, error)
|
|
|
|
type RequestPattern struct {
|
|
URL string // Glob o regex
|
|
Method string // GET, POST, etc.
|
|
Condition func(*Request) bool
|
|
}
|
|
|
|
func (b *Browser) InterceptRequest(ctx context.Context, pattern RequestPattern, handler InterceptorFunc) error
|
|
func (b *Browser) MockResponse(ctx context.Context, pattern string, response *MockResponse) error
|
|
func (b *Browser) AbortRequest(ctx context.Context, pattern string) error
|
|
func (b *Browser) SimulateOffline(ctx context.Context) error
|
|
func (b *Browser) SimulateSlowConnection(ctx context.Context, downloadThroughput, uploadThroughput int) error
|
|
func (b *Browser) GetAllRequests(ctx context.Context) ([]*Request, error)
|
|
```
|
|
|
|
## Uso
|
|
|
|
### Mock API response
|
|
```go
|
|
b.MockResponse(ctx, "**/api/users", &browser.MockResponse{
|
|
Status: 200,
|
|
Headers: map[string]string{
|
|
"Content-Type": "application/json",
|
|
},
|
|
Body: `{"users": [{"id": 1, "name": "Test"}]}`,
|
|
Delay: 100 * time.Millisecond,
|
|
})
|
|
```
|
|
|
|
### Interceptar y modificar
|
|
```go
|
|
b.InterceptRequest(ctx, browser.RequestPattern{
|
|
URL: "**/api/**",
|
|
}, func(req *browser.Request) (*browser.MockResponse, error) {
|
|
// Modificar headers
|
|
req.Headers["Authorization"] = "Bearer fake-token"
|
|
|
|
// Dejar continuar request (nil = no mockear)
|
|
return nil, nil
|
|
})
|
|
```
|
|
|
|
### Simular error de red
|
|
```go
|
|
b.AbortRequest(ctx, "**/slow-endpoint")
|
|
```
|
|
|
|
### Simular conexión lenta
|
|
```go
|
|
b.SimulateSlowConnection(ctx,
|
|
500*1024, // 500 KB/s download
|
|
100*1024, // 100 KB/s upload
|
|
)
|
|
```
|
|
|
|
### Capturar todas las requests
|
|
```go
|
|
requests, _ := b.GetAllRequests(ctx)
|
|
for _, req := range requests {
|
|
log.Printf("%s %s - %d", req.Method, req.URL, req.StatusCode)
|
|
}
|
|
```
|
|
|
|
## CDP Methods
|
|
|
|
- `Fetch.enable` - Habilitar interceptación
|
|
- `Fetch.requestPaused` - Request interceptado
|
|
- `Fetch.continueRequest` - Continuar con cambios
|
|
- `Fetch.fulfillRequest` - Mock response
|
|
- `Fetch.failRequest` - Abortar request
|
|
- `Network.emulateNetworkConditions` - Simular latencia
|
|
|
|
## Referencias
|
|
|
|
- CDP Fetch: https://chromedevtools.github.io/devtools-protocol/tot/Fetch/
|
|
- Playwright route: https://playwright.dev/docs/network
|
|
- Puppeteer interception: https://pptr.dev/guides/request-interception
|