Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ AngleSharp.Browser adds a fully usable (visible) browser based on top of the Ang

- `src/AngleSharp.Browser` (NuGet package): the UI-agnostic `BrowserEngine` (navigation, painting, input). Everything configurable lives in `BrowserOptions`. All DOM work is serialized and runs on AngleSharp's event loop, as AngleSharp is not thread-safe.
- Frames: `BrowserEngine.PrepareFrameAsync` lays out on the event loop (the first frame of a document only what is in view, `PrepareViewportFrame`, the next one the whole page); `BrowserFrame.Rasterize` (raw RGBA, overscan above/below the viewport) runs on any thread, so `BrowserView` pipelines layout and raster. Each frame's hit-test map answers cursor/link lookups without the DOM; scroll-only frames reuse the last display list unless the page has fixed/sticky boxes.
- Page scrolling is smooth and runs ahead of the DOM (`ScrollPosition` vs `ScrollTop`); the view shifts the last frame meanwhile and draws an overlay scrollbar. While a script keeps the page busy, `PrepareFrameAsync` repositions the last frame (DOM-free, like a compositor) instead of waiting for the event loop. A frame after document mutations only (not resources, time or hover: `_needsFullLayout`) asks `IDomHarness.UpdateFrame()` first, which keeps or patches the last frame when the changes are confined to boxes that can be laid out on their own (out-of-flow boxes, flex and grid items, or in-flow blocks staying the same from outside). Until a page has a measured extent, scrolling is not clamped to it (the next frame clamps). A root with `overflow: hidden` can't be scrolled by the user, but keeps its position.
- Page scrolling is smooth and runs ahead of the DOM (`ScrollPosition` vs `ScrollTop`); the view shifts the last frame meanwhile and draws an overlay scrollbar. While a script keeps the page busy, `PrepareFrameAsync` repositions the last frame (DOM-free, like a compositor) instead of waiting for the event loop. A frame after document mutations only (not resources, time or hover: `_needsFullLayout`) asks `IDomHarness.UpdateFrame()` first, which keeps or patches the last frame when the changes are confined to boxes that can be laid out on their own (out-of-flow boxes, flex and grid items, or in-flow blocks staying the same from outside). Until a page has a measured extent, scrolling is not clamped to it (the next frame clamps). A frame that animates asks for the next one as a mutation (`TryReuseLastFrame` advances the clock first), so the harness paints animated transforms/opacity/filters anew without a layout; frames with sticky boxes are repositioned with the boxes stuck anew (Renderer `StickyFrame`). A root with `overflow: hidden` can't be scrolled by the user, but keeps its position.
- Text selection is opt-in (`BrowserOptions.IsTextSelectionEnabled`, Vision turns it on): the engine forwards presses (after an uncanceled `mousedown`), drags and Ctrl+A to the harness of the document pressed in (`BrowserEngine.Selection.cs`), which paints the selection without a layout; the I-beam over text comes from `RenderedFrame.HasTextAt` (DOM-free). Vision's own panels select too (controls have `user-select: none`). Animated images (GIFs) pick their frame when rasterized; `ScheduleImageFrame` asks for a frame once one in view changes, which reuses the last frame (`RenderedFrame.GetTimeToNextImageFrame`).
- Windows: one `BrowserEngine` (browsing context, history) per window. `WindowRequested` (target=_blank, Ctrl+click) lets the host open one via `CreateWindow()`, which shares the profile data (one synchronized cookie provider, storage and cache factories) but gets its own HTTP handler; unhandled, the page navigates in place.
- Iframes: the document of each one has its own browsing context and harness (with a viewport of the iframe's size); the page's layout leaves a `DrawSubframeCommand`, and the nested frame is prepared right after it, so layouts don't nest. The page's hit-test map delegates to the nested one, and `BrowserEngine.Subframes.cs` routes pointer coordinates, hover, focus, wheel and links. All contexts of an engine share one event loop (`FrameEventLoop` scopes cancelling), as the DOM isn't thread-safe. Script isolation is enforced at the boundary in AngleSharp.Js (`OriginPolicy`, `CrossOriginWindow`): C# code here, like the renderer, sees every document, so anything acting for a script in a frame has to act in that frame's document (see `RunScript`, `FollowHyperlink`).
- `src/AngleSharp.Browser.Avalonia` (NuGet package): `BrowserView` displays frames and forwards input; with just a `Source` it creates and owns an engine while attached. Inside of this namespace `Avalonia` means the namespace itself, so `using` directives for the Avalonia framework stay above the namespace declaration.
- Audio: `MediaHost` (one per engine) registers `AudioResourceService` as AngleSharp's `IResourceService<IAudioInfo>`; it reads the whole response, picks an `IAudioCodec` by the data's first bytes (`AudioCodecs`: WAV, NLayer, NVorbis, Concentus) and gives the element an `AudioPlayback` (its `IMediaController`). A playing one opens an `IAudioStream` of `BrowserOptions.AudioOutput` (`SilentAudioOutput` by default), which pulls the samples, so the media's clock is what was pulled; it raises its events on the event loop, and AngleSharp's element fires those of its own state (play, pause, volumechange). Audible media needs a user activation (a press or a key, reset per document) unless `IsAutoplayAllowed`; `SyncActiveDocument` stops the media of documents that were left. The Renderer paints `audio[controls]` (its time and timeline as a command painted when rasterized, so `GetTimeToNextImageFrame` also covers playing media); `BrowserEngine.Media.cs` acts on presses on them (hit tested by the Renderer's `GetMediaControlAt`), and `MediaHost.Changed` lays out a frame when a media changes otherwise (play, pause, seek, volume), but only while a document shows `audio[controls]` (`SyncMediaChanges`): a page playing sounds without them (e.g. a game) keeps its frame. Vision's `Audio/OpenAlAudioOutput` (Silk.NET.OpenAL, one device for all windows) is where the audio is heard.
- Site information: `BrowserEngine.Site.cs` finds the page's icon while syncing the document and records the certificate of each host in the HTTP handler's validation callback (unless the host set its own), keeping the platform's verdict.
- `src/Vision`: the sample app (Avalonia), not packaged. Its icon lives in `Assets/` (`vision.ico` for Windows/Linux, `vision.png` with the macOS margins, `vision.icns`); on macOS a window's icon is the Dock icon, so the page's icon only shows in the address bar there, while other platforms also show it in the title bar. `App` hosts the windows and the user's `Models/BrowserSettings` (JSON in the app data directory), which apply to windows opened after saving.
- `src/Vision`: the sample app (Avalonia), not packaged. Its icon lives in `Assets/` (`vision.ico` for Windows/Linux, `vision.png` with the macOS margins, `vision.icns`, each size rendered from the vector design in `Pages/logo.svg`, which the about page shows); on macOS a window's icon is the Dock icon, so the page's icon only shows in the address bar there, while other platforms also show it in the title bar. `App` hosts the windows and the user's `Models/BrowserSettings` (JSON in the app data directory), which apply to windows opened after saving.
- Vision's address bar suggests the addresses of `Models/UrlHistory` (`history.json` in the profile directory, in memory for in-memory profiles, shared by the windows of a profile): the most visited first, equally visited ones by their similarity to the typed text (Levenshtein). Its own pages are also served at `vision:` addresses (`Pages/VisionPages`, registered via `BrowserOptions.SchemeHandlers` per window): the window's engine loads the page's source and the `HtmlPage` is attached to its document afterwards; an unknown name shows the list of pages (`VisionPages.Available`, add new pages there). `vision:start` (the default start page) shows the most visited addresses of the window's `UrlHistory`; `vision:requester` sends requests through the engine's `IRequester` services directly (not the loader), so it adds the cookies itself; its saved requests are `Models/SavedRequests` (`requests.json` in the profile directory, shared by the windows of a profile like the history), listed in a sheet the menu button (top left) opens and saved via a dialog from the button below the response. Holding the back/forward button (or a right-click) opens a menu of the history entries in that direction (`BrowserEngine.History`, `GoAsync`). In tests, `DoClick` dispatches after the current `InvokeAsync` callback, so wait between clicks that depend on each other.
- Vision's own UI beyond the toolbar (diagnostics tab, settings, about) is HTML/CSS in `Pages/` (embedded resources), shown by a `BrowserView` with a scripting-free engine. `HtmlPage` subclasses wire the DOM with .NET event handlers via `BrowserEngine.InvokeAsync`; don't add JavaScript there. `BrowserEngine.Diagnostics` collects the current page's requests, errors, console output and frame timings. The side panel of a window shows one page at a time, the diagnostics or the inspector, which share its width (a third of the window, unless the user resized it); `InspectorPage` builds its views on the event loop of the inspected engine and only looks at expanded rows, so its refreshes stay cheap.
- `src/AngleSharp.Browser.Tests`: NUnit tests driving the engine headlessly. `src/AngleSharp.Browser.Avalonia.Tests`: NUnit tests of the control and of Vision's panels using Avalonia's headless platform with real Skia rendering. Don't use `Assert.ThrowsAsync` with the engine (it blocks and hangs); use an awaited try/catch.
- `build/`: the Fallout build, run via `build.sh`/`build.ps1`, `.github/workflows/ci.yml` calls it. The version comes from the top of `CHANGELOG.md`; a push to `main` publishes a release, one to `devel` a pre-release.
- `docs/`: the documentation, published through the doclet in `src/AngleSharp.Browser.Docs`. Keep it in sync with the public API.
- `BrowserEngine` patches a few upstream gaps (User-Agent header, `noscript` style, text documents never completing, timer delays clamped because a zero-delay `setInterval` never yields before AngleSharp 1.9.0, `label.control` not finding wrapped controls, event listener errors reported by an `ErrorEvent` without a type, and `NavigationHistory` reaching the protected `Document.DocumentUri` setter by reflection, as `pushState` has to change the document's address, pointer events being plain `MouseEvent`s as the `PointerEvent` of AngleSharp is not published yet, and `LegacyKeyboardEvent.Code` as it knows the key's code by itself from then on); remove them once fixed upstream.
- `BrowserEngine` patches a few upstream gaps (User-Agent header, `noscript` style, text documents never completing, timer delays clamped because a zero-delay `setInterval` never yields before AngleSharp 1.9.0, `label.control` not finding wrapped controls, event listener errors reported by an `ErrorEvent` without a type, and `NavigationHistory` reaching the protected `Document.DocumentUri` setter by reflection, as `pushState` has to change the document's address, and `LegacyKeyboardEvent.Code` as it knows the key's code by itself from then on); remove them once fixed upstream.

## Most Important Commands

Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# 0.2.0

Released on Wednesday, November 18 2026.

- Fixed `BrowserView` not passing a modifier key pressed on its own (Control, Shift, Alt, Meta) to the page, e.g. a game firing on Control
- Fixed callers of the engine (e.g. awaiting `PrepareFrameAsync` and rasterizing the frame without a synchronization context) continuing on the event loop, which held up the scripts of the page
- Fixed the pointer not firing `mouseenter`/`mouseleave` (and `pointerenter`/`pointerleave`) and its events having no `relatedTarget`
- Fixed the pointer events of the mouse having no `pointerType`, so that scripts took the mouse for touch (e.g. SmartMenus not opening menus on hover)
- Fixed scripts reading `event` outside of a listener failing, e.g. the carousels of smapiot.com (AngleSharp.Js 1.2.2)
- Fixed pages scrolling a script finds the position of an element on (e.g. smapiot.com) freezing (AngleSharp.Renderer 0.11.4)
- Fixed media changing (e.g. a game playing a sound effect, which rewinds and plays an `audio` element) laying out the whole page, which stalled the frames (e.g. whenever Mario jumps in the Mario 5 demo of demo-full.piral.io); only a page showing `audio controls` is laid out anew
- Improved frames of CSS animations and transitions of the transform, opacity or filter of boxes, and scrolling pages with sticky boxes: the last frame is painted anew instead of the page being laid out (smapiot.com scrolls with about 4 ms instead of 400 ms per frame, AngleSharp.Renderer 0.11.4)
- Added `BrowserOptions.IsTextSelectionEnabled` for selecting the text of pages with the pointer (a double press selects a word, a triple one a paragraph, Shift extends) and Control+A, `PointerDownAsync` with the click count, and `CopySelectionAsync` for the clipboard; `BrowserView` passes the click count and copies with Control+C
- Added animated images (e.g. GIFs), whose frames are shown in turn without a layout of the page
- Added the text cursor over text that can be selected, unless the page asks for another cursor
- Added selecting text to the windows and the panels of `Vision`
- Added `BrowserOptions.SchemeHandlers` for custom URL schemes answered by the host
- Added audio: `audio` elements and `new Audio()` play WAV, MP3, Ogg Vorbis and Ogg Opus (managed decoders, `BrowserOptions.AudioCodecs`) on the host's `BrowserOptions.AudioOutput` (silently without one), audible media once the user interacted with the page (`BrowserOptions.IsAutoplayAllowed`), and stop once their document is left (AngleSharp 1.10.4, AngleSharp.Js 1.2.3); `audio controls` shows a player (play/pause, time, timeline, mute) that the pointer operates, and whose time goes on without a layout of the page (AngleSharp.Renderer 0.11.4); Vision plays the audio on the default device via OpenAL Soft
- Added suggestions of previously visited addresses to the address bar of `Vision`, the most popular first
- Added the `vision:` scheme to `Vision`, showing its own pages (e.g., `vision:settings`) or a list of them
- Added the start page `vision:start` to `Vision` (its new default start page), with the most visited pages, demos and Vision's own pages
- Added `BrowserEngine.History` (the entries with their titles) and `BrowserEngine.GoAsync` for jumping several entries; holding the back or forward button of `Vision` (or right-clicking it) shows the entries to jump to
- Added the requester `vision:requester` to `Vision`, which sends HTTP requests with the requesters of the window and shows their responses, and keeps requests saved under a name per profile (saved from a dialog, listed in a sheet opened from the top-left corner)

# 0.1.0

Released on Monday, November 9 2026.
Expand Down
4 changes: 3 additions & 1 deletion docs/general/02-Engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ The `BrowserEngine` represents a browsing context with its history, i.e., what a
| `LoadHtmlAsync(html, address)` | Shows the given markup, optionally pretending it came from the given address. |
| `ReloadAsync()` | Loads the current address again. |
| `GoBackAsync()`, `GoForwardAsync()` | Moves through the history. |
| `GoAsync(delta)` | Jumps several entries back (negative) or forward. |
| `History` | A copy of the entries (address and title) and the index of the current one; `Back` and `Forward` list the entries before and after it, the closest first. |
| `Url`, `Title`, `IsLoading` | The state of the current page. |
| `CanGoBack`, `CanGoForward` | If there is something to go to. |

The address goes through `BrowserEngine.NormalizeAddress`, so what a user enters in an address bar works: `example.org` turns into `https://example.org`, while rooted paths of existing files turn into `file:` addresses.
The address goes through `BrowserEngine.NormalizeAddress`, so what a user enters in an address bar works: `example.org` turns into `https://example.org`, while rooted paths of existing files turn into `file:` addresses. Addresses of the custom schemes of the engine (`BrowserOptions.SchemeHandlers`) stay as they are.

`Url` shows where the engine is going as soon as a navigation starts, like in any browser. A failed navigation does not throw: it raises `Error`, is recorded in the diagnostics, and shows an error page instead.

Expand Down
2 changes: 2 additions & 0 deletions docs/general/03-Rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ if (frame is not null)

Preparing a frame also refreshes what the engine knows for hit testing. The cursor and links are then looked up without touching the DOM, which keeps pointer moves responsive on busy pages.

Animated images (GIFs and WebPs of several frames) play on their own: when one in view shows its next frame, the engine raises `Invalidated`, and the next frame is the last one rasterized again, without a layout. An image plays from the moment it is first painted and as often as it tells, which is forever for most GIFs.

The first frame of a page shows up early: only what is in the viewport is styled and laid out for it. The engine asks for the next frame right away (it raises `Invalidated`), which lays out the whole page. Until then, the page below the viewport is blank, and the scroll position is not limited to the height of the page.

## Overscan and Scrolling
Expand Down
21 changes: 21 additions & 0 deletions docs/general/04-Input.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All positions are in CSS pixels relative to the viewport.
| `MovePointer(x, y)` | Moves the pointer without waiting. Moves are coalesced, which is what a UI should use. |
| `MovePointerAsync(x, y)` | Moves the pointer and waits until the hover state has been updated. |
| `PointerDownAsync(x, y, modifiers)` | Presses the primary button. |
| `PointerDownAsync(x, y, clickCount, modifiers)` | Presses the primary button for the given time in a row, e.g., 2 for a double click. |
| `PointerUpAsync(x, y, modifiers)` | Releases the primary button. |
| `ClickAsync(x, y, modifiers)` | Presses and releases the primary button. |
| `HoveredLink`, `Cursor` | The link below the pointer and the `BrowserCursor` a host should display. |
Expand All @@ -32,6 +33,26 @@ Holding Control while clicking a link requests a new window, as does a link with
await engine.ClickAsync(40, 390, InputModifiers.Control);
```

## Selecting Text

With `BrowserOptions.IsTextSelectionEnabled`, the text of a page can be selected as in a browser. It is off by default, as the layouts then also record where their text comes from.

- Pressing the button and moving the pointer with it held selects the text in between; with Shift, a press extends the selection.
- A second press in a row (`clickCount` 2) selects a word, a third one the paragraph.
- Control+A (or Cmd+A) selects all text of the page, unless a text field has the focus.
- Over text that can be selected, `Cursor` is `BrowserCursor.Text`, unless the page asks for another cursor.
- A page can cancel `mousedown` or `selectstart`, and `user-select: none` keeps text from being selected. Scripts see the selection through `getSelection()`.

`CopySelectionAsync` fires `copy` and returns the selected text for the clipboard, or an empty text if nothing is selected or the page canceled the event:

```cs
var engine = new BrowserEngine(new BrowserOptions { IsTextSelectionEnabled = true });
await engine.LoadHtmlAsync("<p>Hello world</p>");
await engine.PointerDownAsync(30, 20, 2);
await engine.PointerUpAsync(30, 20);
Console.WriteLine(await engine.CopySelectionAsync());
```

## Keyboard

Keys are named by their DOM key value, e.g., `"a"`, `"Enter"`, `"Backspace"`, `"Tab"`, or `"ArrowDown"`. Keys and text are separate on purpose, just like in most UI frameworks:
Expand Down
Loading
Loading