Skip to content

Commit

Permalink
Base64 encode then url encode html content in LoadHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
Voltstro committed Oct 16, 2024
1 parent 20edd9b commit e9c8f53
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/UnityWebBrowser.Engine.Cef/Shared/Browser/UwbCefClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using Microsoft.Extensions.Logging;
using UnityWebBrowser.Engine.Cef.Shared.Browser.Js;
using UnityWebBrowser.Engine.Cef.Shared.Browser.Messages;
Expand Down Expand Up @@ -289,7 +290,7 @@ public void ProcessMouseScrollEvent(MouseScrollEvent mouseScrollEvent)
/// <param name="url"></param>
public void LoadUrl(string url)
{
browser.GetMainFrame()?.LoadUrl(url);
browser.GetMainFrame()!.LoadUrl(url);
}

/// <summary>
Expand All @@ -305,9 +306,12 @@ public Vector2 GetMouseScrollPosition()
/// Loads HTML content
/// </summary>
/// <param name="html"></param>
public void LoadHtml(string html)
public unsafe void LoadHtml(string html)

Check failure on line 309 in src/UnityWebBrowser.Engine.Cef/Shared/Browser/UwbCefClient.cs

View workflow job for this annotation

GitHub Actions / Build-UWB-Engine-CEF-MacOS-x64

Unsafe code may only appear if compiling with /unsafe

Check failure on line 309 in src/UnityWebBrowser.Engine.Cef/Shared/Browser/UwbCefClient.cs

View workflow job for this annotation

GitHub Actions / Build-UWB-Engine-CEF-MacOS-x64

Unsafe code may only appear if compiling with /unsafe

Check failure on line 309 in src/UnityWebBrowser.Engine.Cef/Shared/Browser/UwbCefClient.cs

View workflow job for this annotation

GitHub Actions / Build-UWB-Engine-CEF-MacOS-arm64

Unsafe code may only appear if compiling with /unsafe

Check failure on line 309 in src/UnityWebBrowser.Engine.Cef/Shared/Browser/UwbCefClient.cs

View workflow job for this annotation

GitHub Actions / Build-UWB-Engine-CEF-MacOS-arm64

Unsafe code may only appear if compiling with /unsafe
{
browser.GetMainFrame()?.LoadUrl($"data:text/html,{html}");
html = CefRuntime.Base64Encode(Encoding.UTF8.GetBytes(html));
html = CefRuntime.UriEncode(html, false);

browser.GetMainFrame()!.LoadUrl($"data:text/html;base64,{html}");
}

/// <summary>
Expand All @@ -316,7 +320,7 @@ public void LoadHtml(string html)
/// <param name="js"></param>
public void ExecuteJs(string js)
{
browser.GetMainFrame()?.ExecuteJavaScript(js, "", 0);
browser.GetMainFrame()!.ExecuteJavaScript(js, "", 0);
}

/// <summary>
Expand Down

0 comments on commit e9c8f53

Please sign in to comment.