MicrosoftEdge / MicrosoftEdge/WebView2Feedback

CanGoBack/Forward return false until WebView is interacted with

Open
#4,335 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

What happened?

Problem:
In some scenarios, CanGoBack / CanGoForward don't reflect the true state, even though HistoryChanged events fire normally.

Details:
I have a UWP app with a WebView2 on the entire page. The app can accept deep links that are forwarded to the web app and handled internally as react-router navigations, so there are valid flows where the user might not interact with the app at all before the webapp changes the history backstack.

Workaround:
To get around this, I trigger some js script execution when the DOM is loaded and the issue is resolved

            webView.CoreWebView2.DOMContentLoaded += async (sender, event) =>
            {
                await webView.CoreWebView2.ExecuteScriptAsync("1");
            };
Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

unknown

SDK Version

1.0.2210.55

Framework

WinUI2/UWP

Operating System

Xbox

OS Version

Xbox Series S 10.0.25398.2923

Repro steps

Create a WebView pointing to a local React App with route { path: "/redirect_test/:c", Component: TestRedirect },
Launch the app and wait for redirects to happen.
Property CanGoBack will always return false.

react component to test with:

const TestRedirect = () => {
  const { c } = useParams();
  const navigate = useNavigate();
  useEffect(() => {
    const timer = setTimeout(() => {
        navigate(`../${1 + parseInt(c)}`, { relative: 'path' })
    }, 2000);
    return () => {
      clearTimeout(timer);
    }
  }, [c]);
  return <Text>Redirecting... #{c}</Text>
};
Repros in Edge Browser

Not Applicable

Regression

Don't know

Last working version (if regression)

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the local React app and its /redirect_test/:c route, then reproduce the delayed navigations in the UWP WebView2 app. Compare CanGoBack and CanGoForward with the HistoryChanged events before and after DOMContentLoaded and the ExecuteScriptAsync workaround; done means the properties reflect the history state without user interaction.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.