Skip to content

Swift framework to interact with JavaScript through WebAssembly.

License

Notifications You must be signed in to change notification settings

swiftwasm/JavaScriptKit

Folders and files

NameName
Last commit message
Last commit date
Mar 23, 2025
Mar 27, 2025
Mar 23, 2025
Mar 26, 2025
Mar 27, 2025
Mar 27, 2025
Mar 27, 2025
Mar 24, 2025
Aug 19, 2024
May 12, 2022
Mar 17, 2025
Sep 24, 2020
Sep 24, 2020
Aug 14, 2022
Mar 23, 2025
Jul 11, 2024
Mar 15, 2025
May 6, 2020
Mar 24, 2025
Mar 23, 2025
Mar 19, 2025
Mar 24, 2025
Mar 24, 2025

Repository files navigation

JavaScriptKit

Run unit tests

Swift framework to interact with JavaScript through WebAssembly.

Quick Start

Check out the Hello World tutorial for a step-by-step guide to getting started.

Overview

JavaScriptKit provides a seamless way to interact with JavaScript from Swift code when compiled to WebAssembly. It allows Swift developers to:

  • Access JavaScript objects and functions
  • Create closures that can be called from JavaScript
  • Convert between Swift and JavaScript data types
  • Use JavaScript promises with Swift's async/await
  • Work with multi-threading
import JavaScriptKit

// Access global JavaScript objects
let document = JSObject.global.document

// Create and manipulate DOM elements
var div = document.createElement("div")
div.innerText = "Hello from Swift!"
_ = document.body.appendChild(div)

// Handle events with Swift closures
var button = document.createElement("button")
button.innerText = "Click me"
button.onclick = .object(JSClosure { _ in
    JSObject.global.alert!("Button clicked!")
    return .undefined
})
_ = document.body.appendChild(button)

Check out the examples for more detailed usage.

Contributing

Contributions are welcome! See CONTRIBUTING.md for details on how to contribute to the project.

Sponsoring

Become a gold or platinum sponsor and contact maintainers to add your logo on our README on Github with a link to your site.

Sponsor this project