TsgcWebView2 exposes a Settings property of type TsgcWebView2Settings that controls browser behavior. These settings can be configured at design time or changed at runtime after initialization.
Set the Settings properties in the Object Inspector. They are applied automatically after the WebView2 environment is initialized.
// These values can also be set in the Object Inspector
sgcWebView21.Settings.ScriptEnabled := True;
sgcWebView21.Settings.DevToolsEnabled := False;
sgcWebView21.Settings.ContextMenuEnabled := False;
sgcWebView21.Settings.ZoomControlEnabled := False;
You can change settings at runtime after the component is initialized. Changes take effect immediately.
procedure TFormMain.sgcWebView21Initialized(Sender: TObject);
begin
// Disable right-click menu and DevTools at runtime
sgcWebView21.Settings.ContextMenuEnabled := False;
sgcWebView21.Settings.DevToolsEnabled := False;
// Disable JavaScript dialogs
sgcWebView21.Settings.DefaultScriptDialogsEnabled := False;
end;
The UserDataFolder property specifies the directory where the browser stores cookies, cache, permissions, and other profile data. Each unique folder creates an isolated browser profile.
// Use a custom data folder for isolated profiles
sgcWebView21.UserDataFolder := 'C:\AppData\MyApp\Profile1';
Set this property before initialization (before the component creates the WebView2 environment). If not set, a default folder is used in the application's temporary directory.
The BrowserExecutableFolder property points to a fixed-version WebView2 Runtime distribution. Use this to ship a specific browser version with your application instead of relying on the system-installed runtime.
// Use a fixed-version runtime bundled with the application
sgcWebView21.BrowserExecutableFolder :=
ExtractFilePath(ParamStr(0)) + 'WebView2Runtime';
Set this property before initialization. If left empty, the component uses the system-installed Evergreen WebView2 Runtime.