Skip to content

jakenvac/SwiftWebview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift Webview

Cross platform webview bindings for swift.

Dependencies

Depending on the target platform, you'll need to install a few things.

macOs

It just works™

Linux

You'll need to install libgtk-3-dev and libwebkit2gtk-4.0-dev or your distros equivalents.

sudo apt install libgtk-3-dev libwebkit2gtk-4.0-dev

Windows

Windows is currently untested & not officially supported. Contributions are welcome here.

Usage

See the generated documentation here.

Basic Usage

import SwiftWebview

// create a new webview
let wv = WebView()
      // navigate to a URL
      .navigate("https://example.com")
      // directly set the HTML
      .setHtml("<h1>Hello World</h1>")
      // set the title of the window
      .setTitle("My Webview Window")
      // set the size of the window
      .setSize(800, 600, .None)
      // inject some javascript into every new page
      .inject("console.log('this happens before window.onload')")
      // asynchronously evaluate some JS in the current page
      .eval("console.log('this was evaled at runtime')")

// run the webview
wv.run()

// destroy the webview once we're done with it
wv.destroy()

Binding functions

let wv = WebView()

let mySwiftFunction: JSCallback = { args in
  return "Hello \(args[0])"
}

wv.bind("boundFunction", mySwiftFunction)
wv.run()
var result = window.boundFunction("World");
console.log(result); // Hello World

About

Multi platform webview implementation for swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages