References Getting Started Getting Started Architecture Architecture Application Application Window Window WebView WebView Deployment Deployment Components Components Framework Integrations Framework Integrations Examples Examples Community Community github GitHub github Get Started arrow_up_right
Getting Started Getting Started Architecture Architecture Application Application Window Window WebView WebView Deployment Deployment Components Components Framework Integrations Framework Integrations Examples Examples Community Community

WebView

WebView Configuration Events Schemes API Bindings API Data API Scripts API Web Components API Battery API Network API Security API Getting Started Architecture Application Window WebView Deployment Components Framework Integrations Examples Community

WebView

The WebView class represents a webview in the Boson application. It provides a way to manage html content, including JavaScript scripts, styles, functions, and more.

Main WebView

The Application::$webview property provides convenient access to the WebView instance of the main window.

This is a facade property that internally accesses the webview of the default window inside the window manager.

$app = new Boson\Application();

// Access the main WebView
$webview = $app->webview;

Behavior is similar to the main window:

If you try to access the $webview property after the all windows has been closed, a NoDefaultWindowException will be thrown.

URL Navigation

The WebView::$url property allows you to load custom html content from any address (including real ones from internet).

$webview->url = 'https://bosonphp.com';

When setting the URL, webview attempts to load data from the specified source, but the address may change based on the behavior of the target page (for example, triggering scripts or redirects), so the result displays the real address, and not the one that was set.

$app = new Boson\Application();

$app->webview->url = 'https://github.com/BosonPHP';

// After set the new URL, the navigation has 
// not yet taken place:
//
// string("URL: about:blank\n")
//
echo 'URL: ' . $app->webview->url . "\n";

$app->on(function (WebViewNavigated $e) use ($app): void {
    // The navigation occurs later, for this you 
    // should subscribe to the required event:
    //
    // string("URL: https://github.com/BosonPHP\n")
    //
    echo 'URL: ' . $app->webview->url . "\n";
});

WebView navigation also fires a corresponding event that can be subscribed to using the event system.

HTML Content

The WebView::$html property allows you to load custom html content without navigation to any address.

$webview->html = '<button>Do Not Click Me!</button>';

Direct HTML loading implemented via data: protocol is an insecure context which does NOT allow the implementation of some functionality.

WebView navigation also fires a corresponding event that can be subscribed to using the event system.

State

The WebView::$state property provides access to the current state of the webview.

// Check if the webview is loading
if ($webview->state === Boson\WebView\State::Loading) {
    echo "WebView is currently loading content\n";
}

This property will contain one of the possible values of Boson\WebView\State enum.

enum State
{
    /**
     * Navigation to a new URL.
     */
    case Navigating;

    /**
     * Data is being loaded from the specified URL.
     */
    case Loading;

    /**
     * Readiness for work with document.
     */
    case Ready;
}
github discord telegram Get started Documentation Contribution Guide License Release Notes BOSON PHP © 2025. All Rights Reversed.