Shard Detail

webview v0.1.4

Crystal bindings to the zserge's tiny cross-platform Webview library.
crystal-language crystal-lang webview crystal-bindings crystal shard webview-library

Install & Use

Add the following code to your project's shard.yml under:

dependencies to use in production
- OR -
development_dependencies to use in development

  github: naqvis/webview


Crystal Webview

Crystal language bindings for zserge's Webview which is an excellent cross-platform single header webview library for C/C++ using Gtk, Cocoa or MSHTML/Edge repectively.

Webview relys on default rendering engine of host Operating System, thus binaries generated with this Shard will be much more leaner as compared to Electron which bundles Chromium with each distribution.

Shard Supports Two-way bindings between Crystal and JavaScript. You can invoke JS code via Webview::Webview#eval and calling Crystal code from JS is done via WebView::Webview#bind (refer to Example 3 for sample on how to invoke Crystal functions from JS)

Webview supported platforms and the engines you can expect to render your application content are as follows:

Operating System Browser Engine Used
OSX Cocoa/WebKit
Linux Gtk-webkit2
Windows MSHTML or EdgeHTML


If you're planning on targeting Linux you must ensure that Webkit2gtk is already installed and available for discovery via the pkg-config command.


  1. Add the dependency to your shard.yml:

        github: naqvis/webview
  2. Run shards install


Example 1: Loading URL

require "webview"

wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", "")

Example 2: Loading HTML

require "webview"

html = <<-HTML
data:text/html,<!DOCTYPE html><html lang="en-US">
<div class="container">
	<!-- Logo -->
   <h1>City Gallery</h1>
    <li><a href="/London">London</a></li>
    <li><a href="/Paris">Paris</a></li>
    <li><a href="/Tokyo">Tokyo</a></li>
  <img src="pic_mountain.jpg" alt="Mountain View" style="width:304px;height:228px;">
  <p>London is the capital city of England. It is the most populous city in the  United Kingdom, with a metropolitan area of over 13 million inhabitants.</p>
  <p>Standing on the River Thames, London has been a major settlement for two millennia, its history going back to its founding by the Romans, who named it Londinium.</p>
<footer>Copyright &copy;</footer>

wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", html)

Example 3: Calling Crystal code from JavaScript

require "webview"

html = <<-HTML
data:text/html,<!doctype html>
    window.onload = function() {
      document.body.innerText = "Javascript calling Crystal code";
      noop().then(function(res) {
        console.log('noop res', res);
        add(1, 2).then(function(res) {
          console.log('add res', res);

wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", html, true)

wv.bind("noop", { |a|
  pp "Noop called with arguments: #{a}""noop")

wv.bind("add", { |a|
  pp "add called with arguments: #{a}"
  ret = 0_i64
  a.each do |v|
    ret += v.as_i64


  1. Fork it (
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request