Skip to content

fix: keep committed document referrer after aborted navigation on macOS - #4468

Open
EnesKartal wants to merge 1 commit into
b-editor:mainfrom
EnesKartal:fix/issue-4428
Open

EnesKartal wants to merge 1 commit into
b-editor:mainfrom
EnesKartal:fix/issue-4428

Conversation

@EnesKartal

@EnesKartal EnesKartal commented Nov 20, 2026 •

Copy link
Copy Markdown

Root cause

When a navigation is stopped or fails, SettleAbortedPageNavigation sets _pageDownloadReferrerUncertain and DocumentReferrer falls back to BlankPage, dropping Referer and cookies for subsequent downloads from the displayed page.

On macOS, MacOSBrowserDownloadHandler reports every main-frame commit via OnNativeNavigationCommitted, so WebBrowserTabViewModel.CommittedUri accurately tracks the surviving document (including failures after commit and uncommitted initial tabs).

Fix

  • When navigation commits are reported (MacOSBrowserDownloadHandler attached, or
    eportsNavigationCommits: true in tests), DocumentReferrer resolves uncertain page referrers to _viewModel?.CommittedUri instead of BlankPage, while keeping the attempted address in CurrentUri.
  • Platforms without commit reporting (Windows, Linux) keep the conservative BlankPage fallback.

Tests

  • Added DownloadsAfterAbortedNavigationKeepCommittedPageMetadataWhenCommitsAreReported covering stopped navigation, failure before commit, failure after commit, and uncommitted stopped navigation (4/4 passing).

Fixes #4428

Summary by CodeRabbit

  • Bug Fixes
    • Downloads now use the correct page context after navigation is stopped or fails, preserving the committed page’s referrer and cookies. If no page has finished loading, downloads no longer inherit context from an earlier page. This improves download behavior across supported platforms.

@EnesKartal
EnesKartal requested a review from yuto-trd as a code owner November 20, 2026 15:35
Copilot AI balanced review requested due to automatic review settings November 20, 2026 15:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

When navigation stops or fails, the view uses the committed URI as the download referrer on platforms that report navigation commits. Tests cover download referrer and cookie expectations across stopped and failed navigation scenarios.

Changes: Download referrer after aborted navigation

Layer / File(s) Summary
Configure commit reporting
src/Beutl.Editor.Components/WebBrowserTab/Views/WebBrowserTabView.axaml.cs, tests/Beutl.HeadlessUITests/WebBrowserDownloadTests.cs
The view constructor accepts an optional navigation-commit reporting setting and stores it. The test helper forwards the setting.
Select referrer after aborted navigation
src/Beutl.Editor.Components/WebBrowserTab/Views/WebBrowserTabView.Navigation.cs, tests/Beutl.HeadlessUITests/WebBrowserDownloadTests.cs
When the download referrer is uncertain, the view uses the committed URI on commit-reporting platforms and BlankPage otherwise. Tests cover stopped and failed navigation before and after a commit.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 46f30

Downloads after a stopped or failed navigation on macOS now keep the displayed page's referrer and cookies, while the address bar still shows the attempted address. Other platforms keep the existing fallback. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names a macOS-specific fix: keeping the committed document referrer for downloads after an aborted navigation. The raw summary says DocumentReferrer uses the committed URI when the referrer …
Linked Issues check Passed Issue #4428 requires that, on platforms that report commits, downloads from the displayed page keep that page's Referer and cookies after a stop or failure, while the conservative fallback stays where…
Out of Scope Changes check Passed The described changes are limited to the referrer resolution in WebBrowserTabView.Navigation.cs (DocumentReferrer and ReportsNavigationCommits), an optional reportsNavigationCommits constructor parame…
Full details: Title check

Explanation

The title names a macOS-specific fix: keeping the committed document referrer for downloads after an aborted navigation. The raw summary says DocumentReferrer uses the committed URI when the referrer is uncertain on platforms that report navigation commits, which matches the title. The title is specific and tied to the main change. It does not cover the test additions or the constructor parameter, which is acceptable.

Full details: Linked Issues check

Explanation

Issue #4428 requires that, on platforms that report commits, downloads from the displayed page keep that page's Referer and cookies after a stop or failure, while the conservative fallback stays where the surviving document is unknown. At head, WebBrowserTabView.Navigation.cs defines DocumentReferrer so that, when _pageDownloadReferrerUncertain is set, it returns _viewModel?.CommittedUri if ReportsNavigationCommits is true, and BlankPage otherwise. ReportsNavigationCommits is true when _reportsNavigationCommits is set or when _nativeBrowserHandler is MacOSBrowserDownloadHandler. This covers the macOS commit path (OnNativeNavigationCommitted calls CommitNavigation). SettleAbortedPageNavigation is reached from CompleteNavigation (failure) and TryInterceptMediaNavigation (media interception), so the stop, provisional failure, failure-after-commit, and media paths all use the same resolution. CurrentUri is still used for the address bar, as the issue requires. Windows and Linux keep BlankPage. The new test is described as covering the four cases (4/4 passing), but I did not read the test file and did not run it, so that result is author-reported. The cookie part is not checked in code: I did not read the cookie-attaching logic, and the claim rests on DocumentReferrer being the shared source for the download request.

Full details: Out of Scope Changes check

Explanation

The described changes are limited to the referrer resolution in WebBrowserTabView.Navigation.cs (DocumentReferrer and ReportsNavigationCommits), an optional reportsNavigationCommits constructor parameter in WebBrowserTabView.axaml.cs for tests, and a headless test for aborted-navigation downloads. All of these support the #4428 objective. The PR objectives mention #2378 items as out of scope; the reviewed changes do not touch those items as far as the evidence shows. The whole-PR diff tool was unavailable, so the file list comes from the supplied summary, and the changed hunks were checked only through the file read of the Navigation file at head.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b11953ee-a16d-4dd6-abae-b4bc5b589099
Commits

Reviewing files that changed from the base of the PR and between a00966d and 46f30d8.

Files selected for processing: 3

  • src/Beutl.Editor.Components/WebBrowserTab/Views/WebBrowserTabView.Navigation.cs
  • src/Beutl.Editor.Components/WebBrowserTab/Views/WebBrowserTabView.axaml.cs
  • tests/Beutl.HeadlessUITests/WebBrowserDownloadTests.cs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (1) · Last reviewed commit: "fix: keep committed document referrer af..." · Reviewed by Greptile

@yuto-trd

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T21:13:40.900492Z 46f30d8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 46f30d8182

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

private Uri? DocumentReferrer => (_openerPageCommitted ? null : _openerNavigation?.Referrer)
?? (_pageDownloadReferrerUncertain ? WebBrowserTabViewModel.BlankPage : _viewModel?.CurrentUri);
?? (_pageDownloadReferrerUncertain
? (ReportsNavigationCommits ? _viewModel?.CommittedUri : WebBrowserTabViewModel.BlankPage)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve native-download retry metadata for typed addresses

On macOS, if a typed URL on site B returns a native download while site A is committed, OnNativeDownloadRequested calls SettleAbortedPageNavigation and queues the response before clearing _pageDownloadReferrerUncertain. This fallback therefore causes BrowserProfile.AddDownload to store A as the download's referrer, even with NoReferrer, instead of the previous null metadata. OnRetryHistoryClick reuses that origin, and BrowserSessionCookies.CreateContainer filters cookies against A, so an authenticated download from B can succeed initially but fail on retry because B's session cookie is omitted. Preserve the native response's direct-navigation metadata while restoring the committed origin for subsequent page links.

Useful? React with 👍 / 👎.

@yuto-trd

Copy link
Copy Markdown
Member

@EnesKartal Thanks for your work on this PR! Could you please address the Codex review feedback?

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.82%. Comparing base (a00966d) to head (46f30d8).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4468   +/-   ##
=======================================
  Coverage   82.81%   82.82%           
=======================================
  Files        3320     3320           
  Lines      296780   296785    +5     
  Branches    37963    37964    +1     
=======================================
+ Hits       245791   245817   +26     
+ Misses      39003    38990   -13     
+ Partials    11986    11978    -8     
Files with missing lines Coverage Δ
...ebBrowserTab/Views/WebBrowserTabView.Navigation.cs 75.24% <100.00%> (+0.24%) ⬆️
...nts/WebBrowserTab/Views/WebBrowserTabView.axaml.cs 77.60% <100.00%> (+0.09%) ⬆️

... and 17 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a00966d...46f30d8. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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.

Downloads from the displayed page send no Referer or cookies after a stopped or failed navigation

3 participants