WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

[Problem/Bug]: Find::Stop doesn't clear previous search term

Open pushkin- opened this issue 1 year ago • 9 comments

What happened?

I need to detect when a navigation happens in my app and clear the previous search term to prevent PHI/PII from being saved in there on the login screen for instance.

It seems that by default, the Find popup is closed but the contents are preserved. This is consistent with browsers, so this is fine as the default behavior.

But I was hoping that I could call Stop to fully stop/reset the Find session, but it doesn't help. The old search term persists.

Perhaps Stop is already called by WebView2 code on navigations and isn't intended to clear the old search term / reset to the default, but having some way of doing this would be useful. Perhaps a flag I can pass to the Stop function?

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Prerelease (Edge Canary/Dev/Beta)

Runtime Version

134.0.3101.0 canary

SDK Version

1.0.3079.0 prerelease

Framework

Winforms

Operating System

Windows 11

OS Version

23H2 - 22631.4602

Repro steps

can post an example if you'd like

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

pushkin- avatar Jan 28 '25 16:01 pushkin-

@pushkin- Thanks for reaching out. I see this is a default behavior in edge browser as well.Could you please confirm? Also please share the screenshots of the issue...

krbharadwaj avatar Feb 05 '25 06:02 krbharadwaj

@krbharadwaj ok yes, the navigation not clearing the search term happens in Edge too. I called that out in the issue report. My report is specifically asking for a way to clear the search term, which I was hoping we could do with the Stop API, but maybe we need a new API here.

I suppose I could paste some screenshot here later, but it would just be of the Find popup with a search term in it which doesn't seem very helpful. Is there something in particular you're looking for here, or that you need clarification on?

pushkin- avatar Feb 05 '25 15:02 pushkin-

@pushkin- https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2find?view=webview2-winrt-1.0.3079-prerelease#startasync:~:text=Calling%20Start%20without%20altering%20its%20parameters%20will%20behave%20either%20as%20FindNext%20or%20FindPrevious%2C%20depending%20on%20the%20most%20recent%20search%20action%20performed.

According to this you need to alter the search options to make it clear the last searched term..

krbharadwaj avatar Feb 07 '25 07:02 krbharadwaj

@krbharadwaj I already do this.

When Ctrl+F is detected, I do:

var findOptions = coreWebView2.Environment.CreateFindOptions();
findOptions.FindTerm = string.Empty;
coreWebView2.Find.Stop(); // optional call I'm throwing in as a test
coreWebView2.Find.StartAsync(findOptions);

Ctrl+F opens with the old search term.

pushkin- avatar Feb 07 '25 16:02 pushkin-

@pushkin- This seem to be an issue then. Let me check on that and get back!

krbharadwaj avatar Feb 11 '25 12:02 krbharadwaj

Quick observation is that when we make first call with find term as blank in find options, it shows the previously searched item only, but second time same call makes it reset the search term... Assigning it to @chetanpandey1266 to further investigate the issue...

krbharadwaj avatar Feb 17 '25 08:02 krbharadwaj

@krbharadwaj you're just making a double call to: coreWV2.Find.StartAsync(options);

I guess I haven't confirmed if this works or not. I added this code, but the next time I press Ctrl+F to trigger a StartAsync, focus moves somewhere, but the Find popup doesn't display (probably related to one of my other issues); so having trouble testing this workaround

pushkin- avatar Feb 24 '25 16:02 pushkin-

@pushkin- , This is not a workaround, that was just an observation I shared, on which @chetanpandey1266 will follow up now. This seem to be an issue, which we need to address.

krbharadwaj avatar Feb 25 '25 04:02 krbharadwaj

I opened a related issue that documents your observation that the search term is not cleared the first time, but is the second time. That issue focused mostly on the fact that the find popup inherits other windows' search terms. https://github.com/MicrosoftEdge/WebView2Feedback/issues/5158

pushkin- avatar Mar 12 '25 14:03 pushkin-

Wanted to note since I didn't explicitly call this out before, I expect that when Stop() is called and the popup is closed, the next time you open the Find popup, I won't be able to Ctrl+Z back to the older search term.

Currently, I have a workaround to clear the previous search term by passing some spaces as the FindTerm to the StartAsync API's options which replaces what was previously there with spaces. The problem is that you can Ctrl+Z back to the original term.

pushkin- avatar May 13 '25 21:05 pushkin-

Webview2 is essentially a wrapper over edge. The behavior described herein is consistent with edge behavior and hence by design. Stop is not expected to clear the previous search term. Neither will Start preserve place in search. The search restarts from which ever position the user has scrolled too.

The recommended way to specify a new search term is by using FindOptions. Taking this route will ensure that previous state is not preserved even via Ctrl+Z. Closing this as by design.

shrinaths avatar Jul 21 '25 07:07 shrinaths

@shrinaths I am passing a new search term and I can still get old ones via Ctrl+Z. Specifically, I'm setting the term to several spaces to clear the old value.

See gif: I press Ctrl+F, type "a", backspace, "b", backspace, "c", backspace Then I close the popup and reopen it Then I press Ctrl+Z several times. I first see several spaces appear (the search term I used), but then I see the old values of c, b, and a

Image

pushkin- avatar Aug 08 '25 17:08 pushkin-

@shrinaths Can this issue be reopened? As per above, I can still repro the Ctrl+Z issue. Can you take a look?

pushkin- avatar Sep 02 '25 15:09 pushkin-