Skip to content

ExecuteScriptAsync doesn't return fetch PromiseResult #2295

Closed
@ninoxscutulata

Description

@ninoxscutulata

Version
SDK: 1.0.1189-prerelease
Runtime: 99.0.1150.36
Framework: WInForms
OS: Win10

Repro Steps

string resp1 = await webView.CoreWebView2.ExecuteScriptAsync("async function abc () { let response = await fetch('https://www.yahoo.com/tdv2_fp/api/resource/WeatherLocationService.favoriteLocation?lang=en-US&region=US&site=fp&ssl=1&crumb=N2/kCEJVXBm&returnMeta=true'); let text = await response.json();  return text;} await abc();");
string resp2 = await webView.CoreWebView2.ExecuteScriptAsync("async function abc () { let response = await fetch('https://www.yahoo.com/tdv2_fp/api/resource/WeatherLocationService.favoriteLocation?lang=en-US&region=US&site=fp&ssl=1&crumb=N2/kCEJVXBm&returnMeta=true'); let text = await response.json();  return text;} abc();");
      
Debug.WriteLine(resp1); // "null"
Debug.WriteLine(resp2); // "{}"
      
  // expected response
  // {"data":[],"meta":{}}

In the real Chrome or Edge WebBrowser Devtools Console or chrome webdriver, this script works fine.
But it doesn't work in WebView2.

I think that webview2 should also return a string response because I get a successful string response using a different kind of webdriver, but this is just my guess.

Maybe I don't know how to use it
Is there a way to return the response contents using fetch in webview2?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions