Click or drag to resize

WebBrowserExtensionsExecuteScriptAsyncWhenPageLoaded Method

Version 102.0.100
Execute Javascript code in the context of this Browsers Main Frame. This extension method uses the LoadingStateChanged event. As the method name implies, the script will be executed asynchronously, and the method therefore returns before the script has actually been executed.

Namespace:  CefSharp
Assembly:  CefSharp (in CefSharp.dll) Version: (
public static void ExecuteScriptAsyncWhenPageLoaded(
	this IChromiumWebBrowserBase webBrowser,
	string script,
	bool oneTime = true


Type: CefSharpIChromiumWebBrowserBase
The ChromiumWebBrowser instance this method extends.
Type: SystemString
The Javascript code that should be executed.
oneTime (Optional)
Type: SystemBoolean
(Optional) The script will only be executed on first page load, subsequent page loads will be ignored.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IChromiumWebBrowserBase. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Best effort is made to make sure the script is executed, there are likely a few edge cases where the script won't be executed, if you suspect your script isn't being executed, then try executing in the LoadingStateChanged event handler to confirm that it does indeed get executed.
See Also