Skip to content
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

[Problem/Bug]: Problem with some unicode chars when runnin ExecuteJavaScript [Win32] #4310

Closed
lgmarin opened this issue Jan 19, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@lgmarin
Copy link

lgmarin commented Jan 19, 2024

What happened?

I have an application written in C++ that runs a ExecuteJavaScript for a JS funciton of mine that returns a string.

If there is a '<' inside the response, in the C++ side, it will be replaced by \u003C. The problem is, that it seems to happen only (as far as I observed) to this and not to the other HTML symbols (>, &, ...) and even other weird UTF symbols are captured correctly in the C++ side.

Is there something that I'm missing here? So far I'm not sure if it is a encoding problem, because this just happens to this specific symbol.

Thank you!

Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

120.0.2210.133

SDK Version

No response

Framework

Win32

Operating System

Windows 10

OS Version

19045.3930

Repro steps

Create a JS method that returns a string containing a "<" symbol.
Call this method with ExecuteJavaScript().
The Callback will have the response showing "\u003C" in place of the "<". (Other symbols are not affected)

Repros in Edge Browser

Not Applicable

Regression

No, this never worked

Last working version (if regression)

No response

@lgmarin lgmarin added the bug Something isn't working label Jan 19, 2024
@mohdsharez
Copy link

mohdsharez commented Feb 2, 2024

Use regex.unescape on result content it loads data perfectly as a work around.

@david-risney
Copy link
Contributor

If you use ExecuteScriptAsync and examine the result string, that result string is the JSON encoded result of script execution. If script execution returns a string, then the ExecuteScriptAsync result is the JSON encoded string. That means it has starting and ending quotes, special characters will be slash escaped, and it looks like the '<' will also be encoded. If you JSON decode the result you should get the string you expect.

This is described more: https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/javascript#scenario-executescript-json-encoded-results

And if you use ExecuteScriptWithResultAsync(...) you can use TryGetResultAsString which will give you the decoded string value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants