Skip to content

Commit

Permalink
Add support for running JS code
Browse files Browse the repository at this point in the history
  • Loading branch information
krzys-h committed Sep 27, 2018
1 parent b328904 commit 4ca6cef
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
26 changes: 25 additions & 1 deletion GMWebExtension/GMWebExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ public void Dispose()
public static double __webextension_native_init()
{
var settings = new CefSettings();
settings.SetOffScreenRenderingBestPerformanceArgs();
//settings.SetOffScreenRenderingBestPerformanceArgs();
settings.CefCommandLineArgs.Add("autoplay-policy", "no-user-gesture-required");
settings.CefCommandLineArgs.Remove("mute-audio");
foreach (var a in settings.CefCommandLineArgs)
Debug.WriteLine(a.Key + "=" + a.Value);
Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
return 1;
}
Expand Down Expand Up @@ -280,5 +282,27 @@ public static double browser_resize(double browserIdDouble, double w, double h)

return 1;
}

[DllExport(CallingConvention.Cdecl)]
public static double browser_js(double browserIdDouble, string js)
{
int browserId = (int)browserIdDouble; // this is so stupid, GML...
if (browserId < 0 || browserId >= browsers.Count || browsers[browserId] == null)
return 0;

browsers[browserId].browser.ExecuteScriptAsync(js);

return 1;
}

[DllExport(CallingConvention.Cdecl)]
public static double browser_is_initialized(double browserIdDouble)
{
int browserId = (int)browserIdDouble; // this is so stupid, GML...
if (browserId < 0 || browserId >= browsers.Count || browsers[browserId] == null)
return 0;

return browsers[browserId].browser.IsBrowserInitialized ? 1 : 0;
}
}
}
25 changes: 24 additions & 1 deletion Project5.gmx/extensions/GMWebBrowser.extension.gmx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<name>GMWebBrowser</name>
<version>1.0.0</version>
<packageID></packageID>
<ProductID>ACBD3CFF4E539AD869A0E8E3B4B022DD</ProductID>
<ProductID></ProductID>
<date>26/09/18</date>
<license>Free to use, also for commercial games.</license>
<description></description>
Expand Down Expand Up @@ -160,6 +160,29 @@
<arg>2</arg>
</args>
</function>
<function>
<name>browser_js</name>
<externalName>browser_js</externalName>
<kind>12</kind>
<help>browser_js(browserId, code)</help>
<returnType>2</returnType>
<argCount>2</argCount>
<args>
<arg>2</arg>
<arg>1</arg>
</args>
</function>
<function>
<name>browser_is_initialized</name>
<externalName>browser_is_initialized</externalName>
<kind>12</kind>
<help></help>
<returnType>2</returnType>
<argCount>1</argCount>
<args>
<arg>2</arg>
</args>
</function>
</functions>
<constants>
<constant>
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ browser_load(browser_id, url)
browser_load_html(browser_id, html)
browser_resize(browser_id, width, height)
browser_draw(browser_id, x, y)
browser_is_initialized(browser_id)
browser_js(browser_id, js)

// In the Social async event (this is what all extensions are supposed to use apparently and I hate it):
var event_id = async_load[? "id"];
Expand Down

0 comments on commit 4ca6cef

Please sign in to comment.