<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Set cookies for the new WebViewBrowser control in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1157743#M7972</link>
    <description>&lt;P&gt;Thanks for your reply, Gintautas. The solution suggested is ultimately using the event &lt;EM&gt;WebResourceRequested&lt;/EM&gt;. The other event just tells you when &lt;EM&gt;CoreWebView2&lt;/EM&gt; is ready to be used.&lt;/P&gt;&lt;P&gt;I cannot use that solution or other solutions applicable to &lt;EM&gt;WebView2&lt;/EM&gt; because &lt;EM&gt;WebViewBrowser&lt;/EM&gt; is not exposing all &lt;EM&gt;WebView2&lt;/EM&gt;'s properties, methods and events. Neither &lt;EM&gt;CoreWebView2&lt;/EM&gt; nor the event &lt;EM&gt;WebResourceRequested&lt;/EM&gt; are exposed by &lt;EM&gt;WebViewBrowser&lt;/EM&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2022 11:26:30 GMT</pubDate>
    <dc:creator>ljlopez</dc:creator>
    <dc:date>2022-03-25T11:26:30Z</dc:date>
    <item>
      <title>Set cookies for the new WebViewBrowser control</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1157474#M7968</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;Is it possible to set cookies for the new &lt;EM&gt;WebViewBrowser&lt;/EM&gt; control?&lt;/P&gt;&lt;P&gt;Up until now I've been using the &lt;EM&gt;ChromiumWebBrowser&lt;/EM&gt; control and I was able to get the cookie manager by means of either&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Cef.GetGlobalCookieManager()&lt;/LI-CODE&gt;&lt;P&gt;or&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;ChromiumWebBrowser.GetCookieManager()&lt;/LI-CODE&gt;&lt;P&gt;However, as &lt;EM&gt;ChromiumWebBrowser&lt;/EM&gt; has been deprecated, I have just switched to using the &lt;EM&gt;WebViewBrowser&lt;/EM&gt; control instead and I cannot find a way to set the cookies or access the cookie manager. Is there any way to achieve this?&lt;/P&gt;&lt;P&gt;From what I have gathered, &lt;EM&gt;WebView2&lt;/EM&gt; allows to achieve this via its property &lt;EM&gt;CoreWebView2&lt;/EM&gt;. The cookie manager can be accessed directly via the property &lt;EM&gt;CookieManager&lt;/EM&gt;.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;WebView2.CoreWebView2.CookieManager&lt;/LI-CODE&gt;&lt;P&gt;Another option is to capture the event &lt;EM&gt;WebResourceRequested&lt;/EM&gt; and attach a header to the &lt;EM&gt;CoreWebView2WebResourceRequest&lt;/EM&gt; provided by &lt;EM&gt;CoreWebView2WebResourceRequestedEventArgs&lt;/EM&gt;.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;CoreWebView2WebResourceRequestedEventArgs.Request.Headers.SetHeader()&lt;/LI-CODE&gt;&lt;P&gt;If it was currently not possible to set the cookies for the &lt;EM&gt;WebViewBrowser&lt;/EM&gt; control, would the ArcGIS Pro SDK 3.0 expose either &lt;EM&gt;CoreWebView2&lt;/EM&gt; or &lt;EM&gt;CookieManager&lt;/EM&gt;, or perhaps the event &lt;EM&gt;WebResourceRequested&lt;/EM&gt;?&lt;/P&gt;&lt;P&gt;I'm using&amp;nbsp;ArcGIS Pro SDK 2.9.0.32739.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 18:30:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1157474#M7968</guid>
      <dc:creator>ljlopez</dc:creator>
      <dc:date>2022-03-24T18:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Set cookies for the new WebViewBrowser control</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1157686#M7970</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Have you tried this:&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/answers/questions/144386/how-to-set-cookies-to-webview2-control-in-c.html" target="_self"&gt;https://docs.microsoft.com/en-us/answers/questions/144386/how-to-set-cookies-to-webview2-control-in-c.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It uses&amp;nbsp;&lt;SPAN&gt;CoreWebView2Ready event&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 06:40:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1157686#M7970</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2022-03-25T06:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: Set cookies for the new WebViewBrowser control</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1157743#M7972</link>
      <description>&lt;P&gt;Thanks for your reply, Gintautas. The solution suggested is ultimately using the event &lt;EM&gt;WebResourceRequested&lt;/EM&gt;. The other event just tells you when &lt;EM&gt;CoreWebView2&lt;/EM&gt; is ready to be used.&lt;/P&gt;&lt;P&gt;I cannot use that solution or other solutions applicable to &lt;EM&gt;WebView2&lt;/EM&gt; because &lt;EM&gt;WebViewBrowser&lt;/EM&gt; is not exposing all &lt;EM&gt;WebView2&lt;/EM&gt;'s properties, methods and events. Neither &lt;EM&gt;CoreWebView2&lt;/EM&gt; nor the event &lt;EM&gt;WebResourceRequested&lt;/EM&gt; are exposed by &lt;EM&gt;WebViewBrowser&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 11:26:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1157743#M7972</guid>
      <dc:creator>ljlopez</dc:creator>
      <dc:date>2022-03-25T11:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Set cookies for the new WebViewBrowser control</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1157842#M7973</link>
      <description>&lt;P&gt;There is possibility to do that from the code behind. I have tried to test on&amp;nbsp;&lt;EM&gt;WebViewBrowser from ArcGIS community samples but it doesn't work on my computer at all without changes.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Add name and one of events (Initialized or CoreWebView2InitializationCompleted) to&amp;nbsp;frameworkControls:WebViewBrowser:&lt;/EM&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;        &amp;lt;frameworkControls:WebViewBrowser x:Name="webView" Grid.Row="1" Grid.ColumnSpan="3" Source="{Binding SourceUri, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                          Initialized="WebViewBrowser_Initialized" CoreWebView2InitializationCompleted="WebView_CoreWebView2InitializationCompleted"/&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;Then create events methods in code behind and add logic from link:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        private void WebViewBrowser_Initialized(object sender, EventArgs e)
        {
            if(webView.CoreWebView2 != null)
            {
                Debug.WriteLine("not null");
                // Implement logic from link
            }
        }

        private void WebView_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
        {
            if(webView.CoreWebView2 != null)
            {
                Debug.WriteLine("not null");
                // Implement logic from link
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;I don't know which event is right because can't test.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 15:03:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1157842#M7973</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2022-03-25T15:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Set cookies for the new WebViewBrowser control</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1161927#M8008</link>
      <description>&lt;P&gt;can you make sure you have the following assemblies referenced in your addin:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;lt;ArcGIS Pro Install Folder&amp;gt;\bin\Microsoft.Web.WebView2.Core.dll&lt;BR /&gt;&amp;lt;ArcGIS Pro Install Folder&amp;gt;\bin\Microsoft.Web.WebView2.Wpf.dll&lt;/P&gt;&lt;P&gt;Then u should be able to access the webView2.CoreWebView2 property (and, from there, the cookie manager once CoreWebView2 is initialized)&lt;/P&gt;&lt;P&gt;From&amp;nbsp;&lt;A href="https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Framework#webviewbrowser-control" target="_blank"&gt;https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Framework#webviewbrowser-control&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 02:08:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1161927#M8008</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2022-04-07T02:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: Set cookies for the new WebViewBrowser control</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1161950#M8010</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;My ArcGIS Pro Community SDK sample has all references, but it does not show page content.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GintautasKmieliauskas_0-1649308568854.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/38309i9038516BCFAB04E1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GintautasKmieliauskas_0-1649308568854.png" alt="GintautasKmieliauskas_0-1649308568854.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 05:16:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1161950#M8010</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2022-04-07T05:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Set cookies for the new WebViewBrowser control</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1162955#M8017</link>
      <description>&lt;P&gt;Thanks for your reply, Charles. I was already referencing those assemblies but I was wrong about &lt;EM&gt;CoreWebView2&lt;/EM&gt;. &lt;EM&gt;WebViewBrowser&lt;/EM&gt; is indeed exposing &lt;EM&gt;CoreWebView2&lt;/EM&gt;. I was mislead by the fact that that property is missing from the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/index.html#topic74183.html" target="_blank" rel="noopener"&gt;ArcGIS Pro API Reference&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;However, I have tried both approaches described in the original post and none of them work.&lt;/P&gt;&lt;P&gt;The following one doesn't work because the event &lt;EM&gt;WebResourceRequested&lt;/EM&gt; is never raised.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void Browser_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
  browser.CoreWebView2.WebResourceRequested += CoreWebView2_WebResourceRequested;
}

private void CoreWebView2_WebResourceRequested(object sender, CoreWebView2WebResourceRequestedEventArgs e)
{
  e.Request.Headers.SetHeader("Cookie", cookieString);
}&lt;/LI-CODE&gt;&lt;P&gt;And the following one doesn't work either. The destination page displays a login page, suggesting the cookie is not being sent. The problem is not that the cookie is added too late, because if I navigate to the page again I still get the login page.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void Browser_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
  if (HttpCookie.TryParse(cookieString, out HttpCookie httpCookie))
  {
    CoreWebView2Cookie cookie = browser.CoreWebView2.CookieManager.CreateCookie(httpCookie.Name, httpCookie.Value, httpCookie.Domain, httpCookie.Path);
    cookie.IsHttpOnly = httpCookie.HttpOnly;
    cookie.IsSecure = httpCookie.Secure;
    browser.CoreWebView2.CookieManager.AddOrUpdateCookie(cookie);
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 09:51:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1162955#M8017</guid>
      <dc:creator>ljlopez</dc:creator>
      <dc:date>2022-04-11T09:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Set cookies for the new WebViewBrowser control</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1162969#M8018</link>
      <description>&lt;P&gt;I figured out the problem with the last approach. The cookie obtained with&amp;nbsp;HttpCookie.TryParse() had a null domain. The following code works for me:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void Browser_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
  if (HttpCookie.TryParse(cookieString, out HttpCookie httpCookie))
  {
    CoreWebView2Cookie cookie = browser.CoreWebView2.CookieManager.CreateCookie(httpCookie.Name, httpCookie.Value, domain, httpCookie.Path);
    cookie.IsHttpOnly = httpCookie.HttpOnly;
    cookie.IsSecure = httpCookie.Secure;
    browser.CoreWebView2.CookieManager.AddOrUpdateCookie(cookie);
  }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 11 Apr 2022 10:58:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/set-cookies-for-the-new-webviewbrowser-control/m-p/1162969#M8018</guid>
      <dc:creator>ljlopez</dc:creator>
      <dc:date>2022-04-11T10:58:54Z</dc:date>
    </item>
  </channel>
</rss>

