Skip to content

Refactor web viewer into modular components and hooks#574

Closed
mehmetozguldev wants to merge 1 commit intomasterfrom
claude/athas-browser-feature-0CLCi
Closed

Refactor web viewer into modular components and hooks#574
mehmetozguldev wants to merge 1 commit intomasterfrom
claude/athas-browser-feature-0CLCi

Conversation

@mehmetozguldev
Copy link
Member

@mehmetozguldev mehmetozguldev commented Mar 12, 2026

Description

This PR significantly refactors the web viewer component by extracting logic into reusable hooks, custom stores, and separate UI components. The changes improve code organization, maintainability, and enable new features like browsing history, bookmarks, and responsive device preview modes.

Key Changes

  • Extracted Custom Hooks:

    • useWebviewLifecycle: Manages webview creation, destruction, and lifecycle events
    • useWebViewerNavigation: Handles URL navigation, history management, and back/forward functionality
    • useWebViewerShortcuts: Centralizes keyboard shortcuts and zoom event handling
  • New Zustand Store:

    • useWebViewerStore: Manages browsing history, bookmarks, device presets, search engine preferences, and responsive mode settings
    • Persists data to localStorage for cross-session availability
  • Component Extraction:

    • Toolbar: Extracted navigation controls, URL input, zoom controls, and utility buttons
    • DeviceToolbar: New component for responsive device preview with preset selection and custom dimensions
    • HistoryPanel: New dropdown panel showing browsing history with search and date grouping
    • NewTabPage: New landing page for new tabs with search, recent sites, and bookmarks
  • Utility Functions:

    • normalizeUrl: Standardizes URL input with protocol detection
    • getSecurityInfo: Returns security status (HTTPS, localhost, etc.) with appropriate icons
    • extractHostname: Extracts hostname from URLs for display purposes
  • Type Definitions:

    • Added HistoryEntry, Bookmark, DevicePreset, and WebViewerNavigationState types
  • AI Integration:

    • Extended ACP UI intents to support navigate_web_viewer, go_back_web_viewer, go_forward_web_viewer, and set_viewport actions
    • Added event listeners for AI-dispatched navigation and bookmark operations
  • Settings:

    • Added Web Viewer settings tab for configuring default home page, search engine, and default zoom level

Benefits

  • Reduced main component complexity from ~500 lines to ~150 lines
  • Improved testability through isolated hooks and utilities
  • Enabled new features (history, bookmarks, device preview) without cluttering main component
  • Better separation of concerns between UI, state management, and business logic
  • Persistent user preferences and browsing history

Related Issues

Closes #

Checklist

… integration

Refactor the 630-line monolithic web-viewer component into a proper feature module
with dedicated hooks, stores, utils, types, and constants. Add persisted browsing
history and bookmarks via Zustand store, a new tab page with search bar and recent
sites, a browsing history panel with search and date grouping, responsive device
preview with preset device dimensions, extended ACP protocol for AI-driven browser
control, and a settings tab for configuring search engine, home page, and zoom level.

https://claude.ai/code/session_01HEcZfBGVdoKJVNoMCM6eXc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants