Skip to content

Page.stopLoading neither cancels an in-flight navigation nor stops a streaming document #2765

Open

Description

@lanyue-llk

Environment

  • moli v1.1.23 (aarch64-apple-darwin), moli serve; the code path is unchanged on current main (cbf4d0149f)
  • Reference: Google Chrome 157.0.8103.52 headless

Case 1: stop during a provisional navigation

The server's /home returns <p id=home>home page</p>. Its /slow waits 8 s and then returns <p id=slow>slow page</p>.

  1. Page.navigate /home, then wait 1 s.
  2. Send Page.navigate /slow without awaiting it.
  3. After 1 s, send Page.stopLoading.
  4. Evaluate location.href + " | " + document.body.innerHTML after 10 s.

Expected (Chromium): Page.navigate resolves with errorText: "net::ERR_ABORTED", frameStoppedLoading fires, and the page stays /home | <p id="home">home page</p>.

Actual: stopLoading returns {} and Page.navigate stays pending. Then /slow commits: a second frameNavigated (/slow) and loadEventFired arrive, and the page becomes /slow | <p id="slow">slow page</p>.

Root cause: moli-protocol/src/domains/page/termination.rs:183-195 (PreparedPageStopLoading::prepare) stops only the loaded document's lifecycle and Fetch-paused work. It never cancels the slot's uncommitted navigation. cancel_pending_document_navigation already exists at moli-protocol/src/conn/state/page_slot.rs:724.

Case 2: stop while a document is still streaming

/stream sends <html><body><p id=prefix>committed prefix</p> as a chunk, waits 8 s, then sends <p id=tail>tail</p></body></html>.

Navigate, wait 2 s, send Page.stopLoading, and evaluate document.body.innerHTML immediately and again after 8 s.

Expected (Chromium): both reads give <p id="prefix">committed prefix</p>, and frameStoppedLoading fires.

Actual: immediately after the stop the body is the prefix, but 8 s later it is <p id="prefix">committed prefix</p><p id="tail">tail</p>. No frameStoppedLoading is sent.

Root cause: moli-renderer-v8/src/script_vm/main_document_lifecycle_body.rs:46-64 sets readyState to complete but leaves the streaming parser input open.

Impact

An agent that stops a slow navigation is later navigated away anyway, and the DOM keeps changing after a stop, so post-stop snapshots are not stable. Puppeteer and Playwright clients that use stop to cancel a navigation get neither the abort nor a stable page.

Activity

  1. lanyue-llk commented on Nov 12, 2026

    @lanyue-llk
    ContributorAuthor

    Addendum on commit timing. When a response's headers arrive but its body is held (an application/xml body or an HTTP 500 body), moli resolves Page.navigate and emits frameNavigated as soon as the headers arrive. Chrome keeps the navigation provisional until body bytes arrive, so a Page.stopLoading in that window gives errorText: net::ERR_ABORTED and Network.loadingFailed {canceled:true}, and the page stays on the previous URL. On moli, stopping a held 500 still ends at /err500 | held body, and stopping a held XML body crashes the process (#2796). The fix here should account for commit timing as well as cancellation.

  2. lanyue-llk commented on Nov 12, 2026

    @lanyue-llk
    ContributorAuthor

    One more part of the Chromium stop contract, found while reviewing #2802: Page.stopLoading should also cancel in-flight subresource requests of the stopped document. Chrome ends a pending stylesheet with Network.loadingFailed {errorText:"net::ERR_ABORTED", canceled:true}. In moli the stylesheet keeps loading after the stop and is applied when it arrives.

  3. lanyue-llk commented on Nov 12, 2026

    @lanyue-llk
    ContributorAuthor

    Remaining after #2800 (provisional navigation) and #2817 (streaming input after stop). These came out of the #2817 review; they existed before and are not regressions:

    • Bytes buffered before the stop but not yet tokenized are still parsed when the parser resumes, for example <p>x</p> waiting behind a slow <script src>. This belongs with subresource cancellation on stop (above).
    • Closing the input runs the normal end-of-parse path, so deferred scripts in the committed prefix may still run after a stop. Chrome does not run them (unverified on moli).
    • frameStoppedLoading is still not sent when a committed streaming document is stopped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions