tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

inspector-panel.md (4995B)


High-Level Inspector Architecture

UI structure

The Inspector panel is a tab in the toolbox. Like all tabs, it's in its own iframe.

The high-level hierarchy looks something like this:

flowchart TD
    Toolbox --> InspectorPanel --> MarkupView & SelectorSearch & HTMLBreadCrumbs & ToolSidebar
    ToolSidebar["ToolSidebar widget(iframes)"] --> RuleView & ComputedView & LayoutView & FontInspector & AnimationInspector

Server dependencies

Panel loading overview

- It uses the WalkerActor for the first time to know the default selected node (which could be a node that was selected before on the same page). - It starts listening to the WalkerActor's "new-root" events to know when to display a new DOM tree (when there's a page navigation). - It creates the breadcrumbs widget, the sidebar widget, the search widget, the markup-view

- When this widget initializes, it loads its sub-iframes (rule-view, ...) - Each of these iframes contain panel that, in turn, listen to inspector events like "new-node-front" to know when to retrieve information about a node (i.e the rule-view will fetch the css rules for a node).

- This panel initializes in its iframe, and gets a reference to the WalkerActor. It uses it to know the DOM tree to display. It knows when nodes change (markup-mutations), and knows what root node to start from. - It only displays the nodes that are supposed to be visible at first (usually html, head, body and direct children of body). - Then, as you expand nodes, it uses the WalkerActor to get more nodes lazily. It only ever knows data about nodes that have already been expanded once in the UI.

Server-side structure

Simplified actor hierarchy

flowchart TD
    InspectorActor --> WalkerActor --> NodeActor
    InspectorActor --> PageStyleActor["PageStyleActor (for rule-view/computed-view)"] --> StyleRuleActor

InspectorActor

This tab-level actor is the one the inspector-panel connects to. It doesn't do much apart from creating and returning the WalkerActor and PageStyleActor.

WalkerActor

- also walks iframes - also finds pseudo-elements ::before and ::after - also finds anonymous content (e.g. in the BrowserToolbox)

NodeActor

- change attributes - scroll into view - get event listeners data - get image data - get unique css selector

Highlighters

One of the important aspects of the inspector is the highlighters. You can find a lot more documentation about highlighters here.

We don't just have 1 highlighter, we have a framework for highlighters: