Skip to content

fix[ux] :: remove stale WebKit workaround and restore home back behavior#612

Merged
bniladridas merged 1 commit into
mainfrom
fix-gitlab-home-back
May 6, 2026
Merged

fix[ux] :: remove stale WebKit workaround and restore home back behavior#612
bniladridas merged 1 commit into
mainfrom
fix-gitlab-home-back

Conversation

@bniladridas
Copy link
Copy Markdown
Owner

@bniladridas bniladridas commented May 6, 2026

Summary

  • Remove the stale GitLab-specific back-navigation fallback that was introduced for the earlier WebKit issue
  • Restore one-click back to the internal home page for the first site opened from home while preserving normal external-site history behavior
  • Update app-owned injected JavaScript paths to return explicit values and keep the related browser page logic tests aligned with the current behavior

Impact

  • New feature
  • Bug fix
  • Breaking change
  • Build / CI
  • Refactor / cleanup
  • Documentation
  • Tests
  • Performance
  • Security

Related Items

Notes for reviewers

Review Process

  • Self-review

Summary by CodeRabbit

  • Bug Fixes

    • Improved back-button navigation to better determine when to return to the homepage when switching between different sites
    • Enhanced reliability of embedded scripts with consistent execution patterns
    • Expanded cache clearing to include local and session storage
  • Tests

    • Updated back-navigation test coverage

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 6, 2026

⚠️ No Changeset found

Latest commit: 0d0dca9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
browser Ready Ready Preview, Comment May 6, 2026 10:22pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

📝 Walkthrough

Walkthrough

This PR standardizes embedded JavaScript to explicitly return true/false values instead of void, and replaces GitLab-based back-navigation fallback with site-family matching to determine when to return to the homepage.

Changes

Back-Navigation & Script Return Standardization

Layer / File(s) Summary
Data Shape
lib/ux/browser_page.dart
TabData extended with homeLaunchedSiteFamily field to persist the normalized domain key when leaving the homepage.
Core Logic
lib/ux/browser_page.dart
New helpers _siteFamilyKeyForUrl (extracts registrable-like domain suffix) and shouldReturnHomeOnBack (decides forced home-return based on site-family match and internal home URL). Replaces prior GitLab fallback logic in _goBack with site-family comparison.
Script Standardization
assets/legacy_layout_fix.js, lib/features/login_detection.dart, lib/features/webauthn_script.dart
All embedded IIFE scripts now explicitly return true at early-exit and terminal paths instead of void returns, ensuring consistent boolean result semantics.
Navigation Integration
lib/ux/browser_page.dart
_loadUrl now sets homeLaunchedSiteFamily when navigating away from homepage. Pointer-event and bridge injected scripts updated to use try/catch control flow with explicit true/false returns. _clearAllCaches now clears localStorage and sessionStorage via runJavaScript. Added early-return guards in webview callback handlers to prevent work after controller becomes null.
Tests
test/ux/browser_page_logic_test.dart
Replaced "gitlab back fallback" test group with new shouldReturnHomeOnBack assertions covering same-site-family return (true), mismatched site family (false), and non-internal home URL (false).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related issues

  • #596: Back-navigation improvements now use site-family matching instead of GitLab fallback, directly addressing upstream WebKit issue resolution mentioned in the linked issue context.

Possibly related PRs

Suggested labels

patch, test, size/m

Suggested reviewers

  • harper-dev-hq
  • harper-bot-glitch

🐰 A rabbit hopped through the scripts with care,
Making returns explicit, everywhere!
Site families now match the way we roam,
Guiding browsers back to their cozy home. 🏠✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: removing a stale WebKit workaround and restoring home back behavior, which directly aligns with the changeset.
Description check ✅ Passed The description includes the required Summary and Impact sections with clear bullet points and relevant checkboxes marked. It provides context about the WebKit issue resolution and explains the changes comprehensively.
Linked Issues check ✅ Passed The code changes fully address the requirements from issue #611: the app-specific back-navigation fallback has been removed, the site-family tracking has been restored for home back behavior, and JavaScript paths now return explicit values as intended.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the objectives: removing the GitLab fallback, restoring home back navigation with site-family tracking, and updating injected scripts to return explicit values. No extraneous changes are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-gitlab-home-back

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the patch Patch version bump label May 6, 2026
@github-project-automation github-project-automation Bot moved this to Todo in browser May 6, 2026
@github-actions github-actions Bot added test Tests or test infrastructure changes size/m Medium change set labels May 6, 2026
Copy link
Copy Markdown

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

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: 0d0dca903a

ℹ️ 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".

Comment thread lib/ux/browser_page.dart
homeLaunchedSiteFamily: activeTab.homeLaunchedSiteFamily,
);
final canGoBack = await activeTab.webViewController?.canGoBack() ?? false;
if (shouldReturnHome) {
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 Prefer WebView history before returning home

When the first page opened from home later accumulates same-site WebView history (for example, opening GitLab from home and then following a link to another GitLab page), homeLaunchedSiteFamily still matches the current URL, so this branch runs before the canGoBack branch. That nulls the controller and shows the internal home page instead of calling goBack(), preventing users from stepping back within the site they are browsing. Consider only taking the home shortcut when the WebView cannot go back or when the current entry is known to be the initial page loaded from home.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This is a fair point. I think that broader Back-navigation policy may be better handled separately so this PR can stay focused on removing the stale WebKit workaround and restoring the original path without expanding scope.

Comment thread lib/ux/browser_page.dart
if (!siteKey.contains('.')) return siteKey;
final parts = siteKey.split('.');
if (parts.length < 2) return siteKey;
return '${parts[parts.length - 2]}.${parts[parts.length - 1]}';
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 Avoid collapsing public-suffix domains

For hosts under multi-label public suffixes, this takes only the last two labels, so unrelated domains such as amazon.co.uk and bbc.co.uk both become co.uk. If a user opens one .co.uk site from home and then navigates to another, shouldReturnHomeOnBack treats the second site as the original launched site family and sends Back to home instead of preserving normal WebView history. Use the full host or a public-suffix-aware registrable-domain parser here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Also fair. A correct fix here likely needs a broader host-matching approach, so I think it is safer to track that separately rather than fold a larger domain-matching change into this cleanup PR.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/ux/browser_page.dart`:
- Around line 195-201: _siteFamilyKeyForUrl currently assumes the last two
labels are the site-family which collapses distinct registrable domains (e.g.
foo.github.io and bar.github.io or a.co.uk and b.co.uk); update
_siteFamilyKeyForUrl to compute a public-suffix/registrable-domain-aware key
instead of blindly returning the last two labels by using a public suffix list
library (e.g., a Dart publicsuffix package) to derive the registrable domain
from the output of _siteKeyForUrl and return that registrable domain; if you
cannot add the PSL dependency immediately, change the function to fall back to
returning the full host (i.e., the siteKey) rather than the last-two-label
heuristic so shouldReturnHomeOnBack() preserves real WebView history until a
proper PSL-based implementation is added.
- Around line 5883-5885: The per-tab local/session storage clear can throw and
currently lives inside a try that aborts the whole loop; modify the
reset/clear-caches loop so each call to
tab.webViewController?.runJavaScript('localStorage.clear();
sessionStorage.clear(); true;') is wrapped in its own try/catch (or await with
.catchError) to swallow storage-origin errors and allow the loop to continue
across all tabs, and ensure _navigationCacheIndex.clear() is always executed
after the loop (not skipped by a thrown error). Reference tab.webViewController
and _navigationCacheIndex.clear() when making these changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c8fea43-5e14-4c0e-a2e6-d9885608334d

📥 Commits

Reviewing files that changed from the base of the PR and between 32398ce and 0d0dca9.

📒 Files selected for processing (5)
  • assets/legacy_layout_fix.js
  • lib/features/login_detection.dart
  • lib/features/webauthn_script.dart
  • lib/ux/browser_page.dart
  • test/ux/browser_page_logic_test.dart

Comment thread lib/ux/browser_page.dart
Comment on lines +195 to +201
String? _siteFamilyKeyForUrl(String? rawUrl) {
final siteKey = _siteKeyForUrl(rawUrl);
if (siteKey == null || siteKey.isEmpty) return null;
if (!siteKey.contains('.')) return siteKey;
final parts = siteKey.split('.');
if (parts.length < 2) return siteKey;
return '${parts[parts.length - 2]}.${parts[parts.length - 1]}';
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot May 6, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make the site-family key public-suffix aware.

This helper currently treats the last two labels as the "family", so unrelated sites like foo.github.io / bar.github.io or a.co.uk / b.co.uk collapse to the same key. That makes shouldReturnHomeOnBack() send users straight home and skip real WebView history for valid cross-site navigations, which is the opposite of the intended fallback behavior. Please use a registrable-domain/public-suffix-aware key here, or fall back to full-host matching until that exists.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/ux/browser_page.dart` around lines 195 - 201, _siteFamilyKeyForUrl
currently assumes the last two labels are the site-family which collapses
distinct registrable domains (e.g. foo.github.io and bar.github.io or a.co.uk
and b.co.uk); update _siteFamilyKeyForUrl to compute a
public-suffix/registrable-domain-aware key instead of blindly returning the last
two labels by using a public suffix list library (e.g., a Dart publicsuffix
package) to derive the registrable domain from the output of _siteKeyForUrl and
return that registrable domain; if you cannot add the PSL dependency
immediately, change the function to fall back to returning the full host (i.e.,
the siteKey) rather than the last-two-label heuristic so
shouldReturnHomeOnBack() preserves real WebView history until a proper PSL-based
implementation is added.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fair point. This overlaps with the earlier host-matching concern, and I think a correct fix likely needs a broader approach, so it seems safer to track separately rather than expand the scope of this cleanup PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@bniladridas Sounds good—agree it’s safer to track this separately and keep #612 focused.

If you’d like, I can open a follow-up GitHub issue with the draft below and assign it to you. Prefer that?

  • Title
    Make site-family key public-suffix (eTLD+1) aware for home-back heuristic

  • Background
    In lib/ux/browser_page.dart, _siteFamilyKeyForUrl currently uses a last-two-label heuristic. This collapses unrelated hosts under the same public suffix (e.g., foo.github.io vs bar.github.io, a.co.uk vs b.co.uk), which can cause shouldReturnHomeOnBack(...) to skip real WebView history and jump home.

  • Impact
    Cross-site navigations under multi-label public suffixes may be falsely treated as the “same site family,” leading to premature home returns.

  • Proposal

    • Replace _siteFamilyKeyForUrl with a registrable-domain (PSL/eTLD+1) aware computation.
    • If PSL data/library isn’t available, fall back to full-host matching (not last-two-labels) to avoid false positives.
    • Keep behavior unchanged when homeUrl != defaultHomepageUrl.
  • Tests (test/ux/browser_page_logic_test.dart)

    • foo.github.io vs bar.github.io → different families → shouldReturnHomeOnBack = false
    • a.co.uk vs b.co.uk → different families → false
    • sub.example.com vs api.example.com → same registrable domain → true
    • defaultHomepageUrl gating remains respected.
  • Acceptance criteria

    • PSL-aware key derivation with safe fallback.
    • Updated unit tests reflecting the above.
    • Brief inline doc/TODO near _siteFamilyKeyForUrl explaining the PSL dependency/fallback.

Reply “yes” and I’ll open the issue and link back to this PR and comment; I can also drop a TODO next to _siteFamilyKeyForUrl once the issue number exists. If you’d rather handle it yourself, no problem—I’ll stand by.


✏️ Learnings added
Learnt from: bniladridas
Repo: bniladridas/browser PR: 612
File: lib/ux/browser_page.dart:195-201
Timestamp: 2026-05-06T22:36:19.455Z
Learning: Repository: browser. In lib/ux/browser_page.dart, _siteFamilyKeyForUrl should be replaced with a public-suffix (eTLD+1) aware implementation. Current last-two-label heuristic can collapse unrelated hosts (e.g., *.github.io, *.co.uk). Team chose to defer and track as a separate follow-up issue from PR `#612`.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment thread lib/ux/browser_page.dart
Comment on lines +5883 to +5885
await tab.webViewController?.runJavaScript(
'localStorage.clear(); sessionStorage.clear(); true;',
);
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot May 6, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Keep cache clearing best-effort across all tabs.

localStorage / sessionStorage access can throw on opaque, sandboxed, or file: origins. Because this runs inside the outer try, one failing tab aborts the rest of the loop and also skips _navigationCacheIndex.clear(), so "Clear caches" can silently leave data behind. Catch these storage errors per tab/per storage access instead of failing the whole reset.

Suggested hardening
-        await tab.webViewController?.runJavaScript(
-          'localStorage.clear(); sessionStorage.clear(); true;',
-        );
+        await tab.webViewController?.runJavaScript(r'''
+          (() => {
+            try { localStorage.clear(); } catch (_) {}
+            try { sessionStorage.clear(); } catch (_) {}
+            return true;
+          })();
+        ''');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/ux/browser_page.dart` around lines 5883 - 5885, The per-tab local/session
storage clear can throw and currently lives inside a try that aborts the whole
loop; modify the reset/clear-caches loop so each call to
tab.webViewController?.runJavaScript('localStorage.clear();
sessionStorage.clear(); true;') is wrapped in its own try/catch (or await with
.catchError) to swallow storage-origin errors and allow the loop to continue
across all tabs, and ensure _navigationCacheIndex.clear() is always executed
after the loop (not skipped by a thrown error). Reference tab.webViewController
and _navigationCacheIndex.clear() when making these changes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Also fair. This looks like a useful hardening change, but it is separate from the stale WebKit workaround cleanup in this PR, so I think it is better tracked on its own rather than folded into the current scope.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@bniladridas Sounds good to keep this hardening separate. I can open a follow-up GitHub issue and link back here. Want me to file it and assign it to you?

Proposed issue

  • Title: Harden _clearAllCaches to swallow per-tab storage-origin errors and always clear navigation cache
  • Why: localStorage/sessionStorage access (and runJavaScript itself) can fail on opaque/sandboxed/file: origins or disposed controllers. Today a single failure can abort the loop and skip _navigationCacheIndex.clear(), leaving data behind.
  • Scope of fix:
    • Wrap per-tab cache/storage clears in try/catch so one tab can’t abort the loop.
    • Use an IIFE that guards each storage clear.
    • Ensure navigation-cache clearing runs after the loop regardless of per-tab failures.
  • Sketch:
for (final tab in tabs) {
  try {
    await tab.webViewController?.clearCache();
  } catch (_) {}
  try {
    await tab.webViewController?.runJavaScript(r'''
      (() => {
        try { localStorage.clear(); } catch (_) {}
        try { sessionStorage.clear(); } catch (_) {}
        return true;
      })();
    ''');
  } catch (_) {} // swallow per-tab errors
}
// then always:
_navigationCacheIndex.clear();
// ...persisted index removals, etc.

If you’d like, I’ll open the issue now with this content and link to PR #612 and this comment thread.

(づ。◕‿‿◕。)づ 🐇

@bniladridas
Copy link
Copy Markdown
Owner Author

Thanks for the review comments. The navigation-policy and host-matching concerns raised in the inline threads look valid, but they also broaden the scope beyond the stale WebKit workaround cleanup this PR is intended to handle. I have replied inline and I think the safer path is to track those items separately so we can review them as focused follow-up changes rather than mix them into this cleanup. The cache-clearing hardening comment also looks useful, but it is likewise separate from the main purpose of this PR.

@bniladridas bniladridas merged commit d5e6e45 into main May 6, 2026
20 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in browser May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Patch version bump size/m Medium change set test Tests or test infrastructure changes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Issue 596 appears resolved upstream in WebKit

2 participants