-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to programmatically launch WebView2's Find function. #1737
Comments
Hey @RajeshAKumar - I don't think we currently have a way to do this. Would you like me to add this as a scenario on our backlog? |
This can be done via executing a javascript calling |
Want to highlight "all" the words like how Edge/ Edge control does when we use CTRL + F. |
Yes please log this. |
@RajeshAKumar I've added this as a scenario on our backlog - thanks! |
I tried that and it highlights one time, once we click the page, the highlight goes away. |
Proper support for this would be great please. |
@RajeshAKumar you said:
How can I do this with |
Can you explain this via APIs to understand how to use this? |
@RajeshAKumar ? My screen shot is of CHtmlView which is unrelated to WebView2. |
My issue is to solve this via API in WebView2 in WPF. |
I guess I miss-read your original text. |
FYI, I did just try adding this to a custom context menu:
It doesn't work. Nothing shows on screen. When I used the
Is there any updates on this issue? Thank you. |
Hi @champnic ! I have now managed to use
This works fine: My only request is that the Search bar be improved. The |
FWIW, electron also has this kind of feature |
I'd love to have this feature as well. |
As a workaround, I did it by using the Winform SendKeys class .
then, in my click method, I've first passed the focus to the webview2 (browser) element.
not the most elegant way, perhaps. But it works. |
Can't find a way to close the find UI programmatically. |
@jebihug You could probably send an Escape key to dismiss the UI. |
@champnic This is not working. Especially when the browser don't have the focus and when there is many browsers opened and I want to close the find UI of one of them. |
As you can see, it's still in the works. I'm unable to promise you a timeline. |
@victorhuangwq Any new info about the api release? We are now on the end of august... Would be very nice to have... |
I know they have been beavering away at updating the documentation and adjusting the text from staging to release. So, I guess any time now. 😀 I am interested in the official status too.
Sent from Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: ThHeidenreich ***@***.***>
Sent: Monday, August 26, 2024 12:19:59 PM
To: MicrosoftEdge/WebView2Feedback ***@***.***>
Cc: ajtruckle ***@***.***>; Mention ***@***.***>
Subject: Re: [MicrosoftEdge/WebView2Feedback] How to programmatically launch WebView2's Find function. (#1737)
@victorhuangwq<https://github.com/victorhuangwq> Any new info about the api release? We are now on the end of august... Would be very nice to have...
—
Reply to this email directly, view it on GitHub<#1737 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AB45RM6PDNM2F6IJDQOWRF3ZTMFN7AVCNFSM5D643UD2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMZQHE4TMNJTHEYQ>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Ohhhh. Today is the anniversary of this question. 3 years. Almost done man ;) |
@zoobesucher Oh yes! 3 years. Wow! |
@champnic any updates on this? |
Ever since the mass layoffs and subsequent AI hype, I feel like there have not been many resources left dedicated to projects like WebView2 by Microsoft. I just wish they would handle it as free and open source software, so that the people who need this functionality implemented could at least do something about it themselves. I faintly remember the WebView2 team stating intentions to open source it a few years ago. |
Would have been great if it was open source and maintained by the community. |
If it went open source, then none of the things are raised would be looked at. Personally, I have no energy these days for additional things beyond my TODO list, let alone the knowledge.
They must have their reasons fo delaying, so I respect that.
…________________________________
From: Niro ***@***.***>
Sent: 14 October 2024 09:33
To: MicrosoftEdge/WebView2Feedback ***@***.***>
Cc: ajtruckle ***@***.***>; Mention ***@***.***>
Subject: Re: [MicrosoftEdge/WebView2Feedback] How to programmatically launch WebView2's Find function. (#1737)
Would have been great if it was open source and maintained by the community.
@champnic<https://github.com/champnic> any way to make that happen?
—
Reply to this email directly, view it on GitHub<#1737 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AB45RM3DPDBI5XJWA2V3J3DZ3N6TZAVCNFSM5D643UD2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TENBRGA2DGNBWGY3A>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Hey all - This is still being worked on. It ran into some issues during implementation that we have mostly solved at this point. Right now the estimate is that this will be available as a stable API with the version 132 release SDK, which should ship around mid-January. |
I have a solution my friends!!! I have an application made with For this, I need to download this package:
And this is my method:
If you are using WindowsForms, try using SendKeys:
Works like a charm! |
Hi all! The FindOnPage API is now available as an experimental API in 1.0.3079-prerelease. Using this API, your app can programmatically control Find operations, enabling you to:
Please give it a try and let us know if you have any feedback! |
@maxwellmyers |
It's currently only in prerelease SDK, so you would need to use Edge Canary to test the feature. |
cc @pushkin- |
@victorhuangwq But whilst the announcement mentions the APIs I can't see the code snippets. Eg: How to invoke the find windo with specified options. |
Struggling.
wil::com_ptr<ICoreWebView2FindOptions> CWebBrowser::InitializeFindOptions(const std::wstring& findTerm)
{
auto webView2Environment18 = m_pImpl->m_webViewEnvironment.try_query<ICoreWebView2Environment18>();
CHECK_FEATURE_RETURN(webView2Environment18);
// Initialize Find options
wil::com_ptr<ICoreWebView2FindOptions> find_options;
CHECK_FAILURE(webView2Environment18->CreateFindOptions(&find_options));
CHECK_FAILURE(find_options->put_FindTerm(findTerm.c_str()));
return find_options;
}
bool CWebBrowser::ConfigureAndExecuteFind(const std::wstring& findTerm)
{
auto find_options = InitializeFindOptions(findTerm);
if (!find_options)
{
return false;
}
auto webView2Environment29 = m_pImpl->m_webViewEnvironment.try_query<ICoreWebView2Environment29>();
CHECK_FEATURE_RETURN(webView2Environment29);
// Get the Find interface.
wil::com_ptr<ICoreWebView2Find> webView2Find;
CHECK_FAILURE(webView2Environment29->get_Find(&webView2Find));
// By default Find will use the default UI and highlight all matches. If you want different behavior
// you can change the SuppressDefaultDialog and ShouldHighlightAllMatches properties here.
// Start the Find operation with a callback for completion.
CHECK_FAILURE(webView2Find->StartFind(
find_options.get(),
Callback<ICoreWebView2FindOperationCompletedHandler>(
[this](HRESULT result, BOOL status) -> HRESULT
{
if (SUCCEEDED(result))
{
// Optionally update UI elements here upon successful Find operation.
}
else
{
// Handle errors.
}
return S_OK;
}).Get()));
// End user interaction is handled via UI.
return true;
} These are unknown, why?
What step am I missing? I guess I need to change the path to Edge to:
As you can see, I never use pre-release. So lost! |
@victorhuangwq just starting looking. FYI, this doc should be updated to say
|
Possibly relates to @ajtruckle 's comment above, but I copy this statement from the example:
This gives me the error: Not sure what I'm supposed to do here.@ajtruckle not following what the issue is for you. If you can compile but running fails, you might just need to point your app to use the Canary WebView2 by following steps here. So either add a regkey or initialize your webview2 with If compiling doesn't even work, then not sure. Maybe relates to my issue. |
I will try. For me it won’t compile. The new interfaces etc are unknown in the IDE. As if missing headers etc.
Sent from Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: pushkin- ***@***.***>
Sent: Friday, January 24, 2025 10:32:38 PM
To: MicrosoftEdge/WebView2Feedback ***@***.***>
Cc: ajtruckle ***@***.***>; Mention ***@***.***>
Subject: Re: [MicrosoftEdge/WebView2Feedback] How to programmatically launch WebView2's Find function. (#1737)
Possibly relates to @ajtruckle<https://github.com/ajtruckle> 's comment above, but I copy this statement from the example:
var find_options = new CoreWebView2FindOptions
{
FindTerm = findTerm
};
This gives me the error:
E6492A00-EF42-4937-834C-15B61BAA8EED.png (view on web)<https://github.com/user-attachments/assets/a8b54e12-32d8-4483-bc70-4b2e5e67592c>
Not sure what I'm supposed to do here.
@ajtruckle<https://github.com/ajtruckle> not following what the issue is for you. If you can compile but running fails, you might just need to point your app to use the Canary WebView2 by following steps here<https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel?tabs=api#switching-the-channel-search-order-recommended>. So either add a regkey or initialize your webview2 with CoreWebView2EnvironmentOptions.ChannelSearchKind
If compiling doesn't even work, then not sure. Maybe relates to my issue.
—
Reply to this email directly, view it on GitHub<#1737 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AB45RM3KELAQQ6DRRFQKN2D2MK5QNAVCNFSM5D643UD2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TENRRGM2TEMBSGMYQ>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@ajtruckle for me, the interfaces become known when updating my nuget package. If that didn't help, then I'm not sure. I'm using Visual Studio -> Nuget package manager -> update, and it worked fine |
Same here, for Win32.
Sent from Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: pushkin- ***@***.***>
Sent: Friday, January 24, 2025 10:45:11 PM
To: MicrosoftEdge/WebView2Feedback ***@***.***>
Cc: ajtruckle ***@***.***>; Mention ***@***.***>
Subject: Re: [MicrosoftEdge/WebView2Feedback] How to programmatically launch WebView2's Find function. (#1737)
@ajtruckle<https://github.com/ajtruckle> for me, the interfaces become known when updating my nuget package. If that didn't help, then I'm not sure. I'm using Visual Studio -> Nuget package manager -> update, and it worked fine
—
Reply to this email directly, view it on GitHub<#1737 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AB45RM27X4U6BTDYLOIMX2D2MK67PAVCNFSM5D643UD2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TENRRGM2TGNRWGU4Q>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I found the definition for #define CHECK_FEATURE_RETURN(feature) { if (!feature) { FeatureNotAvailable(); return true; } } |
OK, this is all very messy! For starters I had to examine the header files created by the pre-release. And the classes are different:
So this works: wil::com_ptr<ICoreWebView2ExperimentalFindOptions> CWebBrowser::InitializeFindOptions(const std::wstring& findTerm)
{
// Query for the ICoreWebView2Environment18 interface.
auto webView2Environment18 = m_pImpl->m_webViewEnvironment.try_query<ICoreWebView2ExperimentalEnvironment18>();
CHECK_FEATURE_RETURN(webView2Environment18);
// Initialize Find options
wil::com_ptr<ICoreWebView2ExperimentalFindOptions> find_options;
CHECK_FAILURE(webView2Environment18->CreateFindOptions(&find_options));
CHECK_FAILURE(find_options->put_FindTerm(findTerm.c_str()));
return find_options;
} But the And for the other function, I need to use:
But, I can't find an equivalent to ICoreWebView2FindOperationCompletedHandler. Only: ICoreWebView2ExperimentalFindStartCompletedHandler. Whilst compiling, the first macro I referred to bombs out:
So I commented that line out for now. But compiling still fails with the completion lambda:
|
@pushkin- I think I do have same compile error
|
CHECK_FEATURE_RETURN returns true. Yet the function we call it in returns a find options object. Hence we can't use that macro in this context. Not sure how that would work in official sample. |
We have a HTML page in local WPF app using WebView2, but want to highlight occurrences of a search phrase in the page.
WebView2 does a very nice job of showing this when invoked by user.
We want to leverage this function programmatically.
Can you please guide?
AB#36194641
The text was updated successfully, but these errors were encountered: