Why Boson? Because it's not an Electron! And much easier than that =)
Also, this repository contains included high level PHP bindings for webview v0.12.0.
use Serafim\Boson\Application;
$app = new Application();
$app->webview->html = <<<'HTML'
<button onclick="foo('HELLO');">Hello</button>
HTML;
$app->webview->bind('foo', function (string $message): void {
var_dump($message);
});
$app->run();- PHP ^8.4
- ext-ffi
| Platform | Technologies |
|---|---|
| Windows | Windows API, WebView2 |
| Linux | GTK, WebKitGTK |
| macOS | Cocoa, WebKit |
Requires Windows 10 or higher.
End-users must have the WebView2 runtime installed on their system for any version of Windows before Windows 11.
Note: A pre-builded version of the bridge already comes with
the portability package in bin/WebView2Loader.dll. No any
additional installation required.
The GTK and WebKitGTK libraries are required. You need to check your package repositories regarding which packages to install.
WebKitGTK 6.0, GTK 4
apt install libgtk-4-1 libwebkitgtk-6.0-4WebKitGTK 4.1, GTK 3, libsoup 3
apt install libgtk-3-0 libwebkit2gtk-4.1-0WebKitGTK 4.0, GTK 3, libsoup 2
apt install libgtk-3-0 libwebkit2gtk-4.0-37WebKitGTK 6.0, GTK 4
dnf install gtk4 webkitgtk6.0WebKitGTK 4.1, GTK 3, libsoup 3
dnf install gtk3 webkit2gtk4.1WebKitGTK 4.0, GTK 3, libsoup 2
dnf install gtk3 webkit2gtk4.0GTK 4
pkg install webkit2-gtk4GTK 3
pkg install webkit2-gtk3It appears that no additional dependencies are required.
To get or update the title, you should change the $title property
$app = new Serafim\Boson\Application();
$app->webview->title = 'New Title';
echo 'Current Title: ' . $app->webview->title;
$app->run();To change the size, use the resize() method.
$app = new Serafim\Boson\Application();
$app->webview->resize(640, 480);
$app->run();To change the max size, use the resize() method.
$app = new Serafim\Boson\Application();
$app->webview->resize(640, 480, \Serafim\Boson\Core\WebViewSizeHint::MaxBounds);
$app->run();To change the min size, use the resize() method.
$app = new Serafim\Boson\Application();
$app->webview->resize(640, 480, \Serafim\Boson\Core\WebViewSizeHint::MinBounds);
$app->run();To set the fixed size, use the resize() method.
$app = new Serafim\Boson\Application();
$app->webview->resize(640, 480, \Serafim\Boson\Core\WebViewSizeHint::Fixed);
$app->run();To set the content, you should use the $html property
$app = new Serafim\Boson\Application();
$app->webview->html = '<button>Do Not Click Me!</button>';
$app->run();Please note that reading this property is NOT possible. If you need to read the contents, use the data retrieval method.
$app = new Serafim\Boson\Application();
$app->webview->request('document.body.innerHTML')
->then(function (string $html) {
var_dump($html);
});
$app->run();You can register a CSS style that will be applied to any page
$app = new Serafim\Boson\Application();
$app->webview->styleBeforeLoad(<<<'CSS'
body {
background: #900;
}
CSS);
$app->run();You can register a JavaScript code that will be applied to any page
$app = new Serafim\Boson\Application();
$app->webview->evalBeforeLoad(<<<'JS'
alert('hello');
JS);
$app->run();You can create a function that can be called directly from WebView
$app = new Serafim\Boson\Application();
$app->webview->bind('foo', function () {
var_dump('Executed!');
});
$app->run();You can execute arbitrary code directly on current WebView
$app = new Serafim\Boson\Application();
$app->webview->eval('document.write("Hello World!")');
$app->run();You can directly get data from WebView context
$app = new Serafim\Boson\Application();
$app->webview->request('document.location')
->then(function (array $data) {
var_dump($data);
});
$app->run();To exit the application, you should call the quit() method
$app = new Serafim\Boson\Application();
$app->webview->html = '<button onclick="quit()">exit</button>';
$app->webview->bind('quit', function () use ($app) {
$app->quit();
});
$app->run();