In webview2, setting source property to Uri for navigating.
Let's say First URL is opened in webview2 then navigated to another URL. With the back button on Right-click context menu, able to navigate to the first page.
From google search, found there is no direct way to disable back and forward as of now.
In the normal system forms browser, performed an approach like below which is working
added a bool variable(like IsMyNavigationCall), setting it to true whenever just before navigating to some URL Added a check in NavigationStarted event and if it's false(when navigation triggered from actions like back) cancelling the request and resetting the bool variable.
In Webview2, it's not working. The problem is navigation is not cancelled even after setting CoreWebView2NavigationStartingEventArgs.cancel to true.
Is there any way or kind of hack to prevent navigation between the back and forward?
History.replacewhen navigating, then there will be only one page in the history, which of course makes it impossible to got back/forward,Location.replaceis better: developer.mozilla.org/en-US/docs/Web/API/Location/replacewebView.CoreWebView2.Navigate("https://www.google.com");toawait webView.ExecuteScriptAsync("window.location.replace('https://www.google.com')");