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

# WKContentWorld

An object that defines a scope of execution for JavaScript code, and which you use to prevent conflicts between different scripts.

```
@MainActor class WKContentWorld
```

## Overview

Use a [`WKContentWorld`](/documentation/WebKit/WKContentWorld) object as a namespace to separate your app’s web environment from the environment of individual webpages or scripts you execute. Content worlds help prevent issues that occur when two scripts modify environment variables in conflicting ways. Executing a script in its own content world effectively gives it a separate copy of the environment variables to modify. You might use this support in the following scenarios:

- You have complex script logic to bridge your web content to your app, but your web content has complex script libraries of its own. In that scenario, use one content world for your app-specific scripts and a separate content world for your content-specific scripts.
- You implement a web browser that supports JavaScript extensions. In that scenario, create a unique content world for each extension to prevent conflicts between the extensions.

A [`WKContentWorld`](/documentation/WebKit/WKContentWorld) object is a namespace and doesn’t persist data outside of the current web view or webpage. If you use the same content world in two [`WKWebView`](/documentation/WebKit/WKWebView) objects, variables in one web view’s content world don’t appear in the other web view. Similarly, when the user or your app navigates to a new webpage, variables from the previous page are gone, even if both pages share the same content world.

Use the methods and properties of this class to fetch the content world you need. [`WKContentWorld`](/documentation/WebKit/WKContentWorld) provides a default content world for your app and a content world for the current web page. You can also create new content worlds. For example, you might create a custom content world for each JavaScript extension you manage. Specify the content world object when configuring or executing scripts associated with your content.

> Note:
> The content world doesn’t apply to the current document or DOM of a webpage. Changes you make to the DOM are visible to all script code, regardless of content world. The content world affects only references to other JavaScript variables.

## Topics

### Getting the Default Content World

[`defaultClient`](/documentation/WebKit/WKContentWorld/defaultClient)

The default world for clients.

### Getting the Namespace for the Current Page

[`page`](/documentation/WebKit/WKContentWorld/page)

The content world for the current webpage’s content.

### Retrieving a Custom Content World

[`world(name:)`](/documentation/WebKit/WKContentWorld/world(name:))

Returns the custom content world with the specified name.

[`name`](/documentation/WebKit/WKContentWorld/name)

The name of a custom content world.



---

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)