<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WKUserContentController",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WKUserContentController"
  },
  "title" : "WKUserContentController"
}
-->

# WKUserContentController

An object for managing interactions between JavaScript code and your web view, and for filtering content in your web view.

```
@MainActor class WKUserContentController
```

## Overview

A [`WKUserContentController`](/documentation/WebKit/WKUserContentController) object provides a bridge between your app and the JavaScript code running in the web view. Use this object to do the following:

- Inject JavaScript code into webpages running in your web view.
- Install custom JavaScript functions that call through to your app’s native code.
- Specify custom filters to prevent the webpage from loading restricted content.

Create and configure a [`WKUserContentController`](/documentation/WebKit/WKUserContentController) object as part of your overall web view setup. Assign the object to the [`userContentController`](/documentation/WebKit/WKWebViewConfiguration/userContentController) property of your [`WKWebViewConfiguration`](/documentation/WebKit/WKWebViewConfiguration) object before creating your web view.

## Topics

### Adding and Removing Custom Scripts

[`addUserScript(_:)`](/documentation/WebKit/WKUserContentController/addUserScript(_:))

Injects the specified script into the webpage’s content.

[`removeAllUserScripts()`](/documentation/WebKit/WKUserContentController/removeAllUserScripts())

Removes all user scripts from the web view.

[`userScripts`](/documentation/WebKit/WKUserContentController/userScripts)

The user scripts associated with the user content controller.

### Adding and Removing Message Handlers

[`add(_:name:)`](/documentation/WebKit/WKUserContentController/add(_:name:))

Installs a message handler that you can call from your JavaScript code.

[`add(_:contentWorld:name:)`](/documentation/WebKit/WKUserContentController/add(_:contentWorld:name:))

Installs a message handler that you can call from the specified content world in your JavaScript code.

[`addScriptMessageHandler(_:contentWorld:name:)`](/documentation/WebKit/WKUserContentController/addScriptMessageHandler(_:contentWorld:name:))

Installs a message handler that returns a reply to your JavaScript code.

[`removeScriptMessageHandler(forName:)`](/documentation/WebKit/WKUserContentController/removeScriptMessageHandler(forName:))

Uninstalls the custom message handler with the specified name from your JavaScript code.

[`removeScriptMessageHandler(forName:contentWorld:)`](/documentation/WebKit/WKUserContentController/removeScriptMessageHandler(forName:contentWorld:))

Uninstalls a custom message handler from the specified content world in your JavaScript code.

[`removeAllScriptMessageHandlers(from:)`](/documentation/WebKit/WKUserContentController/removeAllScriptMessageHandlers(from:))

Uninstalls all custom message handlers from the specified content world in your JavaScript code.

[`removeAllScriptMessageHandlers()`](/documentation/WebKit/WKUserContentController/removeAllScriptMessageHandlers())

Uninstalls all custom message handlers associated with the user content controller.

[`WKScriptMessageHandler`](/documentation/WebKit/WKScriptMessageHandler)

An interface for receiving messages from JavaScript code running in a webpage.

[`WKScriptMessageHandlerWithReply`](/documentation/WebKit/WKScriptMessageHandlerWithReply)

An interface for responding to messages from JavaScript code running in a webpage.

### Adding and Removing Content Rules

[`add(_:)`](/documentation/WebKit/WKUserContentController/add(_:))

Adds the specified content rule list to the content controller object.

[`remove(_:)`](/documentation/WebKit/WKUserContentController/remove(_:))

Removes the specified rule list from the content controller object.

[`removeAllContentRuleLists()`](/documentation/WebKit/WKUserContentController/removeAllContentRuleLists())

Removes all rules lists from the content controller.

[`WKContentRuleList`](/documentation/WebKit/WKContentRuleList)

A compiled list of rules to apply to web content.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)