Coder Social home page Coder Social logo

webview's Introduction

Linux CI MacOSX CI Windows CI

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, depending on the host OS.

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.

This 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 Examples 3 & 4 for samples 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
macOS Cocoa, WebKit
Linux GTK 3, WebKitGTK
Windows Windows API, WebView2

Pre-requisite

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

Debian-based systems:

  • Packages:
    • Development: apt install libgtk-3-dev libwebkit2gtk-4.0-dev
    • Production: apt install libgtk-3-0 libwebkit2gtk-4.0-37

BSD-based systems:

  • FreeBSD packages: pkg install webkit2-gtk3
  • Execution on BSD-based systems may require adding the wxallowed option (see mount(8)) to your fstab to bypass W^X memory protection for your executable. Please see if it works without disabling this security feature first.

Microsoft Windows:

  • You should have Visual C++ Build tools already as it's a pre-requisite for crystal compiler
  • git clone https://github.com/webview/webview to get WebView sources
  • webview\script\build.bat to compile them (it will download required nuget package)
  • copy webview\dll\x64\webview.lib to <your crystal installation>\lib
  • copy webview\dll\x64\webview.dll to directory with your program

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      webview:
        github: naqvis/webview
  2. Run shards install

Usage

Example 1: Loading URL

require "webview"

wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", "http://crystal-lang.org")
wv.run
wv.destroy

Example 2: Loading HTML

require "webview"

html = <<-HTML
<!DOCTYPE html><html lang="en-US">
<head>
<title>Hello,World!</title>
</head>
<body>
<div class="container">
<header>
	<!-- Logo -->
   <h1>City Gallery</h1>
</header>
<nav>
  <ul>
    <li><a href="/London">London</a></li>
    <li><a href="/Paris">Paris</a></li>
    <li><a href="/Tokyo">Tokyo</a></li>
  </ul>
</nav>
<article>
  <h1>London</h1>
  <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>
</article>
<footer>Copyright &copy; W3Schools.com</footer>
</div>
</body>
</html>
HTML

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

Example 3: Calling Crystal code from JavaScript

require "webview"

html = <<-HTML
<!doctype html>
<html>
  <body>hello</body>
  <script>
    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);
        });
      });
    };
  </script>
</html>
HTML

wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", true)
wv.html = html
wv.bind("noop", Webview::JSProc.new { |a|
  pp "Noop called with arguments: #{a}"
  JSON::Any.new("noop")
})

wv.bind("add", Webview::JSProc.new { |a|
  pp "add called with arguments: #{a}"
  ret = 0_i64
  a.each do |v|
    ret += v.as_i64
  end
  JSON::Any.new(ret)
})


wv.run
wv.destroy

Example 4: Calling Crystal code from JavaScript and executing JavaScript from Crystal

require "webview"

html = <<-HTML
<!DOCTYPE html><html lang="en-US">
<head>
<title>Hello,World!</title>
</head>
<body>
  <button onClick="add(document.body.children.length)">Add</button>
</body>
</html>
HTML


inject = <<-JS
  elem = document.createElement('div');  
  elem.innerHTML = "hello webview %s";
  document.body.appendChild(elem);
JS

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

wv.bind("add", Webview::JSProc.new { |n|
  wv.eval(sprintf(inject, n))
  JSON::Any.new(nil)
})

wv.run
wv.destroy

Example 5: Running your web app in another thread

Thread.new do
  get "/" do
    "hello from kemal"
  end
  Kemal.run
end

wv = Webview.window(640, 480, Webview::SizeHints::NONE, "WebView with local webapp!", "http://localhost:3000")
wv.run
wv.destroy

App Distribution

Distribution of your app is outside the scope of this library but we can give some pointers for you to explore.

macOS Application Bundle

On macOS you would typically create a bundle for your app with an icon and proper metadata.

A minimalistic bundle typically has the following directory structure:

example.app                 bundle
└── Contents
    ├── Info.plist          information property list
    ├── MacOS
    |   └── example         executable
    └── Resources
        └── example.icns    icon

Read more about the structure of bundles at the Apple Developer site.

Tip: The png2icns tool can create icns files from PNG files. See the icnsutils package for Debian-based systems.

Windows Apps

You would typically create a resource script file (*.rc) with information about the app as well as an icon. Since you should have MinGW-w64 readily available then you can compile the file using windres and link it into your program. If you instead use Visual C++ then look into the Windows Resource Compiler.

The directory structure could look like this:

my-project/
├── icons/
|   ├── application.ico
|   └── window.ico
├── basic.cc
└── resources.rc

resources.rc:

100 ICON "icons\\application.ico"
32512 ICON "icons\\window.ico"

Note: The ID of the icon resource to be used for the window must be 32512 (IDI_APPLICATION).

Limitations

Browser Features

Since a browser engine is not a full web browser it may not support every feature you may expect from a browser. If you find that a feature does not work as expected then please consult with the browser engine's documentation and open an issue on webview library if you think that the library should support it.

For example, the webview library does not attempt to support user interaction features like alert(), confirm() and prompt() and other non-essential features like console.log().

Contributing

  1. Fork it (https://github.com/naqvis/webview/fork)
  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

Contributors

webview's People

Contributors

brandondrew avatar konovod avatar lancecarlson avatar naqvis avatar robinsloan avatar sourceweaver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

webview's Issues

Failed postinstall of webview on make

When running shards install, this error is being returned:

Failed postinstall of webview on make:
g++ -c -o ext/webview.o -DWEBVIEW_GTK=1 `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0` -std=c++11 ext/webview.cc
Package gtk+-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-3.0' found
Package webkit2gtk-4.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `webkit2gtk-4.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'webkit2gtk-4.0' found
In file included from ext/webview.cc:2:
ext/webview.h:418:10: fatal error: JavaScriptCore/JavaScript.h: No such file or directory
  418 | #include <JavaScriptCore/JavaScript.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:23: ext/webview.o] Error 1

Details
Crystal 1.2.2 [6529d725a] (2021-11-10)
Ubuntu 20.04 64bit
libwebkit2gtk-4.0-37 (which provides webkit2gtk 2.34.1) installed

Edit
libjavascriptcoregtk-4.0-18 is also installed, from the beginning

Important
On Ubuntu 20.04, the package libwebkit2gtk-4.0 doesn't exists anymore, and was replaced by libwebkit2gtk-4.0-37

Problem installing Webview Shard on Mac

Problem installing Webview for Crystal on Mac (shard)

  • OS: MacOS darwin/arm64
  • Version: Monterey 12.0.1 (Mac mini M1 chip)
  • Crystal 1.3.2 (2022-01-18)
  • LLVM: 13.0.0

When running shards install, I get the following error message:

of webview: make Failed postinstall of webview on make: c++ -c -o ext/webview.o -DWEBVIEW_COCOA=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=1 -std=c++11 ext/webview.cc In file included from ext/webview.cc:2: ext/webview.h:576:10: error: no matching function for call to 'objc_msgSend' return objc_msgSend("NSString"_cls, "stringWithUTF8String:"_sel, s); ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:576:10: error: cannot initialize return object of type 'id' (aka 'objc_object *') with an rvalue of type 'void' return objc_msgSend("NSString"_cls, "stringWithUTF8String:"_sel, s); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ext/webview.h:583:14: error: no matching function for call to 'objc_msgSend' id app = objc_msgSend("NSApplication"_cls, "sharedApplication"_sel); ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:583:8: error: cannot initialize a variable of type 'id' (aka 'objc_object *') with an rvalue of type 'void' id app = objc_msgSend("NSApplication"_cls, "sharedApplication"_sel); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ext/webview.h:584:5: error: no matching function for call to 'objc_msgSend' objc_msgSend(app, "setActivationPolicy:"_sel, ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:598:27: error: no matching function for call to 'objc_msgSend' objc_msgSend(msg, "body"_sel), "UTF8String"_sel)); ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:597:51: error: no matching function for call to 'objc_msgSend' w->on_message((const char *)objc_msgSend( ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:603:21: error: no matching function for call to 'objc_msgSend' auto delegate = objc_msgSend((id)cls, "new"_sel); ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:610:18: error: no matching function for call to 'objc_msgSend' m_window = objc_msgSend("NSWindow"_cls, "alloc"_sel); ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:610:18: error: assigning to 'id' (aka 'objc_object *') from incompatible type 'void' m_window = objc_msgSend("NSWindow"_cls, "alloc"_sel); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ext/webview.h:611:18: error: no matching function for call to 'objc_msgSend' m_window = objc_msgSend( ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 6 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:611:18: error: assigning to 'id' (aka 'objc_object *') from incompatible type 'void' m_window = objc_msgSend( ^~~~~~~~~~~~~ ext/webview.h:619:19: error: no matching function for call to 'objc_msgSend' auto config = objc_msgSend("WKWebViewConfiguration"_cls, "new"_sel); ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:621:17: error: no matching function for call to 'objc_msgSend' m_webview = objc_msgSend("WKWebView"_cls, "alloc"_sel); ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 2 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:621:17: error: assigning to 'id' (aka 'objc_object *') from incompatible type 'void' m_webview = objc_msgSend("WKWebView"_cls, "alloc"_sel); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ext/webview.h:625:20: error: no matching function for call to 'objc_msgSend' objc_msgSend("NSNumber"_cls, "numberWithBool:"_sel, 1), ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:639:5: error: no matching function for call to 'objc_msgSend' objc_msgSend(m_window, "setContentView:"_sel, m_webview); ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:640:5: error: no matching function for call to 'objc_msgSend' objc_msgSend(m_window, "makeKeyAndOrderFront:"_sel, nullptr); ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ In file included from ext/webview.cc:2: ext/webview.h:646:5: error: no matching function for call to 'objc_msgSend' objc_msgSend("NSApp"_cls, "terminate:"_sel, nullptr); ^~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/message.h:63:1: note: candidate function not viable: requires 0 arguments, but 3 were provided objc_msgSend(void /* id self, SEL op, ... */ ) ^ fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated. make: *** [ext/webview.o] Error 1

Full screen (chromeless)

Can we get webview to go full screen? From the issue below, it seems the SetFullScreen method was removed. But is there an alternative you know of?

webview/webview#458

I'd love to use this library, but my app needs to support kiosk mode.

[Contribution] How to use Crystal / WebView bindings without console :

#hide_console.cr
hide_console.cr

Source :

https://forum.crystal-lang.org/t/compilation-switch-to-avoid-the-debug-console-under-windows/5356/6

#Usage:

require "../webview"
require "./hide_console"

def runApp()
    wv = Webview.window(1500, 1000, Webview::SizeHints::NONE, "Hello WebView", "http://crystal-lang.org")
    wv.run
    wv.destroy
end

runApp()

#Code :

{% if flag? :windows %}
  module Crystal::System::FileDescriptor
    def self.from_stdio(fd)
      console_handle = false
      handle = LibC._get_osfhandle(fd)
      if handle != -1 && handle != -2
        handle = LibC::HANDLE.new(handle)
        # TODO: use `out old_mode` after implementing interpreter out closured var
        old_mode = uninitialized LibC::DWORD
        if LibC.GetConsoleMode(handle, pointerof(old_mode)) != 0
          console_handle = true
          if fd == 1 || fd == 2 # STDOUT or STDERR
            if LibC.SetConsoleMode(handle, old_mode | LibC::ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0
              at_exit { LibC.SetConsoleMode(handle, old_mode) }
            end
          end
        end
      end

      io = IO::FileDescriptor.new(fd, blocking: true)
      # Set sync or flush_on_newline as described in STDOUT and STDERR docs.
      # See https://crystal-lang.org/api/toplevel.html#STDERR
      if console_handle
        io.sync = true
      else
        io.flush_on_newline = true
      end
      io
    end
  end

  @[Link(ldflags: "/ENTRY:wWinMainCRTStartup")]
  @[Link(ldflags: "/SUBSYSTEM:WINDOWS")]
  lib LibCrystalMain
  end

  lib LibC
    fun CommandLineToArgvW(lpCmdLine : LPWSTR, pNumArgs : Int*) : LPWSTR*
    fun LocalFree(hMem : Void*) : Void*
  end

  fun wWinMain(
    hInstance : Void*,
    hPrevInstance : Void*,
    pCmdLine : LibC::LPWSTR,
    nCmdShow : LibC::Int
  ) : LibC::Int
    argv = LibC.CommandLineToArgvW(pCmdLine, out argc)
    wmain(argc, argv)
    ensure
      LibC.LocalFree(argv) if argv
  end
{% end %}

Problem installing Webview for Crystal on Windows : WebView2.h: No such file or directory

Installing webview (0.2.1)
Postinstall of webview: make
Failed postinstall of webview on make:
make[1]: Entering directory 'C:/Users/serge/Documents/vue-tests/vue-tests-nomodules/crystapp/lib/webview'
g++ -c -o ext/webview.o -std=c++11 ext/webview.cc
make[1]: Leaving directory 'C:/Users/serge/Documents/vue-tests/vue-tests-nomodules/crystapp/lib/webview'
In file included from ext/webview.cc:2:
ext/webview.h:1047:10: fatal error: WebView2.h: No such file or directory
 1047 | #include "WebView2.h"
      |          ^~~~~~~~~~~~
compilation terminated.
make[1]: *** [Makefile:23: ext/webview.o] Error 1
make: *** [makefile:6: init] Error 1

Webview run method hangs / isn't recognized by Crystal's fiber scheduler

I based this code snippet on something I found on the web and figured this should work, but it doesn't quite.

It starts the kemal server and runs the webview, but when you try to go to http://localhost/ it hangs. This seems to be because wv.run is a c method call and blocks and is not recognized by Crystal's scheduler so the Fiber isn't doing what it needs to do.

Thoughts?

require "kemal"
require "webview"

# ============
# Settings
# ============

# App params
IP     = "127.0.0.1"
PORT   = 3000
WIDTH  =  800
HEIGHT =  600
TITLE  = "My new app"

# Kemal.config.env = "production"

# TODO: Write documentation for `WebviewTest`
module WebviewTest
  VERSION = "0.1.0"

  # TODO: Put your code here
  def self.run
    # ======
    # Server
    # ======

    spawn do
      Kemal.config.port = (ENV["PORT"]? || PORT).to_i
      Kemal.config.host_binding = ENV["HOST_BINDING"]? || "#{IP}"
      # =======
      # Actions
      # =======

      get "/" do
        "hello world"
      end

      Kemal.run
    end

    spawn do
      wv = Webview.window(WIDTH, HEIGHT, Webview::SizeHints::NONE,
        "#{TITLE}",
        "http://#{IP}:#{PORT}/")

      wv.run
      wv.destroy
    end

    Fiber.yield
  end
end

WebviewTest.run

Build on Ubuntu 22.04 failed

I have no idea what's going on - an incompatible version of webkit? Do you need another debug output? Send me the commands.

If I try to compile this:

require "webview"

wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", "http://crystal-lang.org")
wv.run
wv.destroy

following error occurs:

➤  crystal build hello.cr
/usr/bin/ld: /home/pf/Work/Crystal/tests/webview-test/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::gtk_webkit_engine(bool, void*)::{lambda(_WebKitUserContentManager*, _WebKitJavascriptResult*, void*)#2}::operator()(_WebKitUserContentManager*, _WebKitJavascriptResult*, void*) const':
webview.cc:(.text._ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_[_ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_]+0x3e): undefined reference to `webkit_javascript_result_get_js_value'
/usr/bin/ld: webview.cc:(.text._ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_[_ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_]+0x4e): undefined reference to `jsc_value_to_string'
/usr/bin/ld: webview.cc:(.text._ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_[_ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_]+0xb4): undefined reference to `g_free'
/usr/bin/ld: /home/pf/Work/Crystal/tests/webview-test/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::gtk_webkit_engine(bool, void*)':
webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x4e): undefined reference to `gtk_init_check'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x71): undefined reference to `gtk_window_new'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x9d): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0xc5): undefined reference to `g_signal_connect_data'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0xca): undefined reference to `webkit_web_view_new'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0xd7): undefined reference to `webkit_web_view_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0xed): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0xf5): undefined reference to `webkit_web_view_get_user_content_manager'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x131): undefined reference to `g_signal_connect_data'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x147): undefined reference to `webkit_user_content_manager_register_script_message_handler'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x19d): undefined reference to `gtk_widget_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1b3): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1bb): undefined reference to `gtk_container_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1d1): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1dc): undefined reference to `gtk_container_add'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1e1): undefined reference to `gtk_widget_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1f7): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1ff): undefined reference to `gtk_widget_grab_focus'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x204): undefined reference to `webkit_web_view_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x21a): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x222): undefined reference to `webkit_web_view_get_settings'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x237): undefined reference to `webkit_settings_set_javascript_can_access_clipboard'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x24e): undefined reference to `webkit_settings_set_enable_write_console_messages_to_stdout'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x25f): undefined reference to `webkit_settings_set_enable_developer_extras'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x26f): undefined reference to `gtk_widget_show_all'
/usr/bin/ld: /home/pf/Work/Crystal/tests/webview-test/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::run()':
webview.cc:(.text._ZN7webview17gtk_webkit_engine3runEv[_ZN7webview17gtk_webkit_engine3runEv]+0x11): undefined reference to `gtk_main'
/usr/bin/ld: /home/pf/Work/Crystal/tests/webview-test/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::terminate()':
webview.cc:(.text._ZN7webview17gtk_webkit_engine9terminateEv[_ZN7webview17gtk_webkit_engine9terminateEv]+0x11): undefined reference to `gtk_main_quit'
/usr/bin/ld: /home/pf/Work/Crystal/tests/webview-test/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::dispatch(std::function<void ()>)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine8dispatchESt8functionIFvvEE[_ZN7webview17gtk_webkit_engine8dispatchESt8functionIFvvEE]+0x6c): undefined reference to `g_idle_add_full'
/usr/bin/ld: /home/pf/Work/Crystal/tests/webview-test/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::set_title(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x25): undefined reference to `gtk_window_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x3b): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x46): undefined reference to `gtk_window_set_title'
/usr/bin/ld: /home/pf/Work/Crystal/tests/webview-test/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::set_size(int, int, int)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x34): undefined reference to `gtk_window_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x4a): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x54): undefined reference to `gtk_window_set_resizable'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x5f): undefined reference to `gtk_window_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x75): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x88): undefined reference to `gtk_window_resize'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0xab): undefined reference to `gtk_widget_set_size_request'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0xdf): undefined reference to `gtk_window_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0xf5): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x10e): undefined reference to `gtk_window_set_geometry_hints'
/usr/bin/ld: /home/pf/Work/Crystal/tests/webview-test/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::navigate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x25): undefined reference to `webkit_web_view_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x3b): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x46): undefined reference to `webkit_web_view_load_uri'
/usr/bin/ld: /home/pf/Work/Crystal/tests/webview-test/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x15): undefined reference to `webkit_web_view_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x2b): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x33): undefined reference to `webkit_web_view_get_user_content_manager'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x60): undefined reference to `webkit_user_script_new'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x72): undefined reference to `webkit_user_content_manager_add_script'
/usr/bin/ld: /home/pf/Work/Crystal/tests/webview-test/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x25): undefined reference to `webkit_web_view_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x3b): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x56): undefined reference to `webkit_web_view_run_javascript'
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o /home/pf/Work/Crystal/tests/webview-test/hello  -rdynamic -L/usr/bin/../lib/crystal `command -v pkg-config > /dev/null && pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0` /home/pf/Work/Crystal/tests/webview-test/lib/webview/src/../ext/libwebview.a -lstdc++ -lm -lgc -lpthread -levent -lrt -lpthread -ldl`
Ubuntu: 22.04.1 LTS (Jammy Jellyfish)
Crystal: 1.6.0
libwebkit: libwebkit2gtk-4.0-37 (also libwebkit2gtk-4.0-dev is installed)

Question : How do you specify the path to a local web page (html file) to be displayed (served by) Webview

I tried:

require "webview"

# wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", "http://127.0.0.1:3000", true)
wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", "mint/dist/index.html")
wv.run
wv.destroy

wv.bind("myAlert", Webview::JSProc.new { 
  pp "My Alert !"
  JSON::Any.new("My Alert")
})

I tried with absolute path, then with:
"mint/dist/index.html"
and then with:
"./mint/dist/index.html"
and
"../mint/dist/index.html"

But it didn't work.

Closing a window exits the whole application

When I close a window (via GUI) my application terminates.

When I use your example (only added the p-lines for foo bar baz):

require "webview"
wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", "http://crystal-lang.org")
p :foo
wv.run
p :bar
wv.destroy
p :baz

I only reach up to :foo. There is nothing looking suspicious, meaning no errors or unexpected messages.

This happens on macOS 10.14 (if it's OS related).

Error in shard.yml

On a new project, after creating shard.ymlwith:

dependencies:
  webview:
    github: naqvis/webview

and running shards install, this error is returned:

Error in shard.yml: missing required attribute: name at line 4, column 1

  2.   webview:
  3.     github: naqvis/webview
     ^

Resolving dependencies

Details:
Crystal 1.2.2 [6529d725a] (2021-11-10)
Ubuntu 20.04 64bit
libwebkit2gtk-4.0-37 (which provides webkit2gtk 2.34.1) installed

The example using an URL does not seem to work (displays a blank page instead if the correct web page)

I used the example "as is".

The example :

require "webview"

wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", "http://crystal-lang.org")
wv.run
wv.destroy

My data:

Crystal 1.6.0 (2022-10-06)

LLVM: 14.0.6
Default target: aarch64-apple-darwin22.1.0

Chip: M1
OS: Mac OS Ventura 13.0.1

The shards install output:

sergehulne@Serges-Mac-mini browser % shards install                
Resolving dependencies
Fetching https://github.com/naqvis/webview.git
Using webview (0.2.0)

The app:

Capture d’écran 2022-12-18 à 15 31 29

WebKit2 enable webgl

Trying out your webview shard with the following code but alas
webgl is not enabled by default. I see there is a setting in WebKit
to enable webgl but not in lib.cr.

require "webview"

html = <<-HTML
<!DOCTYPE html>
<html>
  <canvas id = "mycanvas" width = "600" height = "200"></canvas>
  <div id="textview">
    <p>Shader code</p>
  </div>

  <script>
    var canvas = document.getElementById('mycanvas');
    var gl = canvas.getContext('experimental-webgl');
    gl.clearColor(1,0,0,1);
    gl.clear(gl.COLOR_BUFFER_BIT);

  </script>
</html>
HTML

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

C Compiler error

Environment
Ubuntu 20.04 64bit
Crystal 1.2.2 [6529d725a] (2021-11-10)

Installed pre-requisites
sudo apt install pkg-config build-essential libgtk-3-dev libwebkit2gtk-4.0-dev


To execute the first example on readme, on a void directory, I created both shard.yml and a crystal file url.cr with:

shard.yml

name: webview-test
version: 0.1.0
dependencies:
  webview:
    github: naqvis/webview

url.cr

require "webview"

wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", "http://crystal-lang.org")
wv.run
wv.destroy

And shards install goes well:

Resolving dependencies
Fetching https://github.com/naqvis/webview.git
Installing webview (0.1.4)
Postinstall of webview: make
Writing shard.lock

The C compiler error

But when trying to run the example with crystal run url.cr, I get:

Final error

Error: execution of command failed with code: 1: `cc "${@}" -o /home/coghi/.cache/crystal/crystal-run-url.tmp  -rdynamic -L/usr/bin/../lib/crystal `command -v pkg-config > /dev/null && pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0` /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a -lstdc++ -lpcre -lm -lgc -lpthread -levent -lrt -ldl`

Long error:

Open here:

/usr/bin/ld: /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::gtk_webkit_engine(bool, void*)::{lambda(_WebKitUserContentManager*, _WebKitJavascriptResult*, void*)#2}::operator()(_WebKitUserContentManager*, _WebKitJavascriptResult*, void*) const':
webview.cc:(.text._ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_[_ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_]+0x3c): undefined reference to `webkit_javascript_result_get_js_value'
/usr/bin/ld: webview.cc:(.text._ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_[_ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_]+0x4c): undefined reference to `jsc_value_to_string'
/usr/bin/ld: webview.cc:(.text._ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_[_ZZN7webview17gtk_webkit_engineC4EbPvENKUlP25_WebKitUserContentManagerP23_WebKitJavascriptResultS1_E0_clES3_S5_S1_]+0xb1): undefined reference to `g_free'
/usr/bin/ld: /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::gtk_webkit_engine(bool, void*)':
webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x4e): undefined reference to `gtk_init_check'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x71): undefined reference to `gtk_window_new'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x9d): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0xc2): undefined reference to `g_signal_connect_data'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0xc7): undefined reference to `webkit_web_view_new'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0xd4): undefined reference to `webkit_web_view_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0xea): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0xf2): undefined reference to `webkit_web_view_get_user_content_manager'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x12e): undefined reference to `g_signal_connect_data'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x141): undefined reference to `webkit_user_content_manager_register_script_message_handler'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x194): undefined reference to `gtk_widget_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1aa): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1b2): undefined reference to `gtk_container_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1c8): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1d3): undefined reference to `gtk_container_add'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1d8): undefined reference to `gtk_widget_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1ee): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x1f6): undefined reference to `gtk_widget_grab_focus'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x201): undefined reference to `webkit_web_view_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x217): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x21f): undefined reference to `webkit_web_view_get_settings'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x234): undefined reference to `webkit_settings_set_enable_write_console_messages_to_stdout'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x245): undefined reference to `webkit_settings_set_enable_developer_extras'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engineC2EbPv[_ZN7webview17gtk_webkit_engineC5EbPv]+0x255): undefined reference to `gtk_widget_show_all'
/usr/bin/ld: /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::run()':
webview.cc:(.text._ZN7webview17gtk_webkit_engine3runEv[_ZN7webview17gtk_webkit_engine3runEv]+0x11): undefined reference to `gtk_main'
/usr/bin/ld: /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::terminate()':
webview.cc:(.text._ZN7webview17gtk_webkit_engine9terminateEv[_ZN7webview17gtk_webkit_engine9terminateEv]+0x11): undefined reference to `gtk_main_quit'
/usr/bin/ld: /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::dispatch(std::function<void ()>)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine8dispatchESt8functionIFvvEE[_ZN7webview17gtk_webkit_engine8dispatchESt8functionIFvvEE]+0x6c): undefined reference to `g_idle_add_full'
/usr/bin/ld: /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::set_title(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x25): undefined reference to `gtk_window_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x3b): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine9set_titleENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x46): undefined reference to `gtk_window_set_title'
/usr/bin/ld: /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::set_size(int, int, int)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x34): undefined reference to `gtk_window_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x4a): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x54): undefined reference to `gtk_window_set_resizable'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x5f): undefined reference to `gtk_window_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x75): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x88): undefined reference to `gtk_window_resize'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0xab): undefined reference to `gtk_widget_set_size_request'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0xdf): undefined reference to `gtk_window_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0xf5): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8set_sizeEiii[_ZN7webview17gtk_webkit_engine8set_sizeEiii]+0x10e): undefined reference to `gtk_window_set_geometry_hints'
/usr/bin/ld: /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::navigate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x25): undefined reference to `webkit_web_view_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x3b): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine8navigateENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x46): undefined reference to `webkit_web_view_load_uri'
/usr/bin/ld: /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x15): undefined reference to `webkit_web_view_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x2b): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x33): undefined reference to `webkit_web_view_get_user_content_manager'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x60): undefined reference to `webkit_user_script_new'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4initENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x72): undefined reference to `webkit_user_content_manager_add_script'
/usr/bin/ld: /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a(webview.o): in function `webview::gtk_webkit_engine::eval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
webview.cc:(.text._ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x25): undefined reference to `webkit_web_view_get_type'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x3b): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: webview.cc:(.text._ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN7webview17gtk_webkit_engine4evalENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x56): undefined reference to `webkit_web_view_run_javascript'
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o /home/coghi/.cache/crystal/crystal-run-url.tmp  -rdynamic -L/usr/bin/../lib/crystal `command -v pkg-config > /dev/null && pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0` /home/coghi/Projetos/webview-tests/lib/webview/src/../ext/libwebview.a -lstdc++ -lpcre -lm -lgc -lpthread -levent -lrt -ldl`

change for linux: compilation

I made changes to the file
to fork AS400JPLPC

Makefile for Linux

UNAME := $(shell uname)

ifeq ($(UNAME), Darwin)
CFLAGS = -DWEBVIEW_COCOA=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=1
endif


ifeq ($(UNAME), Linux)
CFLAGS = -DWEBVIEW_GTK=1 `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0`
endif

CFLAGS += -std=c++17  
cpp_file := ext/webview.cc
obj_file := $(cpp_file:.cc=.o)

.PHONY: all
all: $(obj_file)

ifeq ($(UNAME), Linux)
	ar rcs ext/libwebview.a ext/webview.o
endif

%.o: %.cc
	$(CXX) -c -o $@ $(CFLAGS) $<

.PHONY: clean
clean:
			rm -f $(obj_file)

src / lib.cr

module Webview
   # formule invalide for Linux 
   #@[Link(ldflags: "-L#{__DIR__}/../ext -lwebview.o -lc++")]
  
  {% if flag?(:darwin) %}
    # ?? tester ou prendre celui de linux 
    @[Link(ldflags: "-L#{__DIR__}/../ext -lwebview.o -lc++")]
    @[Link(framework: "WebKit")]
  {% elsif flag?(:linux) %}
    #------------------------------- tester ok -lc++ invalide  flag -L .../ext -lwebview.o invalide
    @[Link(ldflags: "#{__DIR__}/../ext/libwebview.a -lstdc++")]
    @[Link(ldflags: "`command -v pkg-config > /dev/null && pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0`")]
  
  {% elsif flag?(:windows) %}
    # Windows requires special linker flags for GUI apps.
    @[Link(ldflags: "-L#{__DIR__}/../ext -lwebview.o -lc++")]
    @[Link(ldflags: "-lole32 -lcomctl32 -loleaut32 -luuid -lgdi32 -H windowsgui")]
  {% else %}
    raise "Platform not supported"
  {% end %}
  lib LibWebView
    alias T = Void*

    # Creates a new webview instance. If debug is non-zero - developer tools will
    # be enabled (if the platform supports them). Window parameter can be a
    # pointer to the native window handle. If it's non-null - then child WebView
    # is embedded into the given parent window. Otherwise a new window is created.
    # Depending on the platform, a GtkWindow, NSWindow or HWND pointer can be
    # passed here.
    fun create = webview_create(debug : LibC::Int, window : Void*) : T
    # Destroys a webview and closes the native window.
    fun destroy = webview_destroy(w : T)
    # Runs the main loop until it's terminated. After this function exits - you
    # must destroy the webview.
    fun run = webview_run(w : T)
    # Stops the main loop. It is safe to call this function from another other
    # background thread.
    fun terminate = webview_terminate(w : T)
    # Posts a function to be executed on the main thread. You normally do not need
    # to call this function, unless you want to tweak the native window.
    fun dispatch = webview_dispatch(w : T, fn : (T, Void* -> Void), arg : Void*)
    # Returns a native window handle pointer. When using GTK backend the pointer
    # is GtkWindow pointer, when using Cocoa backend the pointer is NSWindow
    # pointer, when using Win32 backend the pointer is HWND pointer.
    fun get_window = webview_get_window(w : T) : Void*
    # Updates the title of the native window. Must be called from the UI thread.
    fun set_title = webview_set_title(w : T, title : LibC::Char*)
    # Updates native window size. See WEBVIEW_HINT constants.
    fun set_size = webview_set_size(w : T, width : LibC::Int, height : LibC::Int, hints : LibC::Int)
    # Navigates webview to the given URL. URL may be a data URI, i.e.
    # "data:text/text,<html>...</html>". It is often ok not to url-encode it
    # properly, webview will re-encode it for you.
    fun navigate = webview_navigate(w : T, url : LibC::Char*)

    # Injects JavaScript code at the initialization of the new page. Every time
    # the webview will open a the new page - this initialization code will be
    # executed. It is guaranteed that code is executed before window.onload.
    fun init = webview_init(w : T, js : LibC::Char*)
    # Evaluates arbitrary JavaScript code. Evaluation happens asynchronously, also
    # the result of the expression is ignored. Use RPC bindings if you want to
    # receive notifications about the results of the evaluation.
    fun eval = webview_eval(w : T, js : LibC::Char*)
    # Binds a native C callback so that it will appear under the given name as a
    # global JavaScript function. Internally it uses webview_init(). Callback
    # receives a request string and a user-provided argument pointer. Request
    # string is a JSON array of all the arguments passed to the JavaScript
    # function.
    fun bind = webview_bind(w : T, name : LibC::Char*, fn : (LibC::Char*, LibC::Char*, Void* -> Void), arg : Void*)
    # Allows to return a value from the native binding. Original request pointer
    # must be provided to help internal RPC engine match requests with responses.
    # If status is zero - result is expected to be a valid JSON result value.
    # If status is not zero - result is an error JSON object.
    fun webview_return(w : T, seq : LibC::Char*, status : LibC::Int, result : LibC::Char*)
  end
end

Makfile and src/lib.cr I requested modifications to the original for me it's OK
what is not tested is for mac

Creating GitHub Actions for building the examples

👋 @naqvis.

Other similar bindings (e.g. ImGui, SMFL etc.) generally have their examples in an examples directory and they automate the build of those examples with GH Actions. I think this is useful for two reasons: first, a user can clone the repository and run the examples without any copy/pasting. Second, these actions will essentially be recipes that users can refer to when they need information on how to build the examples for their specific environments.

If you agree, I can send a PR for a build manifest that would run for Linux/Win/Mac. I can make the build work for Linux but I'm not sure on how to build for Windows and Mac. I've read in #4 that this library has been tested for all these platforms. Maybe you could share any scripts etc. you had for building on Win & Mac and I will translate it to a build manifest.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.