MicrosoftEdge / MicrosoftEdge/WebView2Feedback
How to add authorization token in the request header for URI obtained using add_NewWindowRequested()
@JosephJin0815 is already working on this.
Since Jul 18, 2023.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
I am exploring use of WebView2 for our application.
I have gone through WebView2 Concepts and managed to load a URL in our application.
When when a hyperlink is clicked, I'm not able to pass authentication request to the URI in new window (not self-hosted).
webview->add_NewWindowRequested(
Callback<ICoreWebView2NewWindowRequestedEventHandler>(
[](ICoreWebView2* sender, ICoreWebView2NewWindowRequestedEventArgs* args)
{
wil::com_ptr deferral;
args->GetDeferral(&deferral);
deferral->Complete();
return S_OK;
}).Get(), nullptr);
The above code launches a popup window and loads the page. But it shows credential popup on top of it.
I have tried using add_WebResourceRequested() after considering the workaround in Unable to get callbacks via add_WebResourceRequested for WebView2 created via add_NewWindowRequested. But I am not getting callback for the newly requested URI (mostly because webView instance is still pointing to base URI).
The environment is created as
LPCWSTR profileDir = L".web_view_profile";
CreateDirectory(profileDir, NULL);
// Browser Setting
auto envOptions = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
envOptions->put_AdditionalBrowserArguments(L"--ignore-certificate-errors --ignore-urlfetcher-cert-requests --pull-to-refresh=false");
envOptions->put_AllowSingleSignOnUsingOSPrimaryAccount(false);
envOptions->put_ExclusiveUserDataFolderAccess(false);
CreateCoreWebView2EnvironmentWithOptions(nullptr, profileDir, envOptions.Get(),
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
[token](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {
ICoreWebView2WebResourceRequest* request = nullptr;
reinterpret_cast<ICoreWebView2Environment12*>(env)->CreateWebResourceRequest(url, L"GET", NULL, NULL, &request);
wil::com_ptr<ICoreWebView2HttpRequestHeaders> headers;
request->get_Headers(&headers);
headers->SetHeader(L"Authorization", token);
}
// Creating Controller with parent hWnd
Please let me know how I can avoid showing the credential popup window again and again for the URI loaded in new window.
Version of WebView2: 1.0.1823.32
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.