# nightwatchjs/nightwatch-inspector architecture

> Architecture diagram of the GitHub repository nightwatchjs/nightwatch-inspector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nightwatchjs/nightwatch-inspector
- Repository: https://github.com/nightwatchjs/nightwatch-inspector

## Overview

Nightwatch Inspector is a Chrome developer tool for finding CSS selectors on a webpage and, in Nightwatch debug mode, trying Nightwatch commands from its DevTools panel. The principal workflow is to enable Explore Mode, inspect or click a page element, generate a selector, and review, copy, or highlight it in the selector history. A separate command-testing branch connects the panel to the local Nightwatch server. The graph includes documented features whose implementation was not sampled; dashed, uncited links mark relationships that the available excerpts do not verify.

Main entry points: [`src/content/index.js`](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/content/index.js) (Page interactions), [`src/panel/js/websocket.js`](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/websocket.js) (Server connection), [`src/panel/js/index.js`](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/index.js) (Panel coordination), [`src/background.js`](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/background.js) (Message routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_page["Page inspection"]
  node_content["Page interactions<br/>[index.js]"]
  node_selector["Selector generation"]
  node_tooltip["Selector tooltip<br/>[tooltip.js]"]
  node_elementhighlight["Element highlighting<br/>[index.js]"]
end

subgraph group_bridge["Extension bridge"]
  node_background["Message routing<br/>[background.js]"]
  node_devtools["DevTools panel entry"]
end

subgraph group_panel["Inspector panel"]
  node_panelentry["Panel coordination<br/>[index.js]"]
  node_explore["Explore Mode<br/>[exploreMode.js]"]
  node_history["Selector history<br/>[selectorHistory.js]"]
  node_selectorcopy["Selector copying<br/>[selectorHistory.js]"]
  node_panelui["Inspector interface<br/>[index.html]"]
end

subgraph group_commands["Command testing"]
  node_suggestions["Command suggestions<br/>[suggestion.js]"]
  node_commandtry["Command execution UI"]
  node_websocket["Server connection<br/>[websocket.js]"]
end

node_developer(("Developer"))
node_webpage["Inspected webpage"]
node_nightwatch["Nightwatch server"]

node_developer -->|"opens inspector"| node_devtools
node_devtools -->|"creates panel"| node_panelui
node_developer -->|"starts exploration"| node_explore
node_explore -.->|"requests mode"| node_background
node_background -->|"routes messages"| node_content
node_webpage -->|"provides interactions"| node_content
node_content -->|"generates selector"| node_selector
node_content -.->|"updates tooltip"| node_tooltip
node_content -->|"sends selector"| node_background
node_history -->|"requests highlight"| node_content
node_developer -->|"copies selector"| node_selectorcopy
node_developer -->|"tries command"| node_commandtry
node_commandtry -.->|"submits command"| node_websocket
node_websocket -->|"connects over WebSocket"| node_nightwatch
node_nightwatch -->|"returns results"| node_websocket
node_websocket -.->|"provides command list"| node_suggestions
node_websocket -->|"records commands"| node_history
node_panelentry -.->|"coordinates history"| node_history
node_panelentry -.->|"coordinates exploration"| node_explore
node_panelentry -.->|"coordinates commands"| node_commandtry

click node_content "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/content/index.js"
click node_selector "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/content/generateSelector.js"
click node_tooltip "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/content/tooltip.js"
click node_background "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/background.js"
click node_devtools "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/nightwatchInspector.js"
click node_panelentry "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/index.js"
click node_explore "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/exploreMode.js"
click node_history "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/selectorHistory.js"
click node_suggestions "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/suggestion.js"
click node_commandtry "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/tryNightwatchCommands.js"
click node_websocket "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/websocket.js"
click node_selectorcopy "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/selectorHistory.js"
click node_elementhighlight "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/content/index.js"
click node_panelui "https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/index.html"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_content,node_selector,node_tooltip,node_elementhighlight toneBlue
class node_background,node_devtools toneAmber
class node_panelentry,node_explore,node_history,node_selectorcopy,node_panelui,node_nightwatch toneMint
class node_suggestions,node_commandtry,node_websocket toneRose
class node_developer,node_webpage toneIndigo
```

## Components

### Page inspection

- [Page interactions](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/content/index.js): `src/content/index.js`
- [Selector generation](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/content/generateSelector.js): `src/content/generateSelector.js`
- [Selector tooltip](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/content/tooltip.js): `src/content/tooltip.js`
- [Element highlighting](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/content/index.js): `src/content/index.js`

### Extension bridge

- [Message routing](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/background.js): `src/background.js`
- [DevTools panel entry](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/nightwatchInspector.js): `src/nightwatchInspector.js`

### Inspector panel

- [Panel coordination](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/index.js): `src/panel/js/index.js`
- [Explore Mode](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/exploreMode.js): `src/panel/js/exploreMode.js`
- [Selector history](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/selectorHistory.js): `src/panel/js/selectorHistory.js`
- [Selector copying](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/selectorHistory.js): `src/panel/js/selectorHistory.js`
- [Inspector interface](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/index.html): `src/panel/index.html`

### Command testing

- [Command suggestions](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/suggestion.js): `src/panel/js/suggestion.js`
- [Command execution UI](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/tryNightwatchCommands.js): `src/panel/js/tryNightwatchCommands.js`
- [Server connection](https://github.com/nightwatchjs/nightwatch-inspector/blob/main/src/panel/js/websocket.js): `src/panel/js/websocket.js`

### Other components

- **Developer**
- **Inspected webpage**
- **Nightwatch server**

## Connections

- Developer → DevTools panel entry: opens inspector (evidence: `README.md`)
- DevTools panel entry → Inspector interface: creates panel (evidence: `src/nightwatchInspector.js`)
- Developer → Explore Mode: starts exploration (evidence: `README.md`)
- Explore Mode → Message routing: requests mode
- Message routing → Page interactions: routes messages (evidence: `src/background.js`)
- Inspected webpage → Page interactions: provides interactions (evidence: `src/content/index.js`)
- Page interactions → Selector generation: generates selector (evidence: `src/content/index.js`)
- Page interactions → Selector tooltip: updates tooltip
- Page interactions → Message routing: sends selector (evidence: `src/content/index.js`)
- Selector history → Page interactions: requests highlight (evidence: `src/panel/js/selectorHistory.js`)
- Developer → Selector copying: copies selector (evidence: `README.md`)
- Developer → Command execution UI: tries command (evidence: `README.md`)
- Command execution UI → Server connection: submits command
- Server connection → Nightwatch server: connects over WebSocket (evidence: `src/panel/js/websocket.js`)
- Nightwatch server → Server connection: returns results (evidence: `src/panel/js/websocket.js`)
- Server connection → Command suggestions: provides command list
- Server connection → Selector history: records commands (evidence: `src/panel/js/websocket.js`)
- Panel coordination → Selector history: coordinates history
- Panel coordination → Explore Mode: coordinates exploration
- Panel coordination → Command execution UI: coordinates commands
