<!--
{
  "availability" : [
    "macOS: 10.4.0 - 10.14.0"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WebScriptObject",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WebScriptObject"
  },
  "title" : "WebScriptObject"
}
-->

# WebScriptObject

A `WebScriptObject` object is an Objective-C wrapper for a scripting object passed to your application from the scripting environment.

```
class WebScriptObject
```

## Overview

You can not create a `WebScriptObject` object directly. You get a window `WebScriptObject` object by sending [`windowScriptObject`](/documentation/WebKit/WebView-swift.class/windowScriptObject) to your `WebView` object.

You can use key-value coding methods—for example, `setValue:forKey:` and `valueForKey:`—to get and set properties of a `WebScriptObject` object. You can also access properties by index using the [`setWebScriptValueAt(_:value:)`](/documentation/WebKit/WebScriptObject/setWebScriptValueAt(_:value:)) and [`webScriptValue(at:)`](/documentation/WebKit/WebScriptObject/webScriptValue(at:)) methods. Use the [`removeWebScriptKey(_:)`](/documentation/WebKit/WebScriptObject/removeWebScriptKey(_:)) method to remove a scripting object property.

Not all properties and methods of a class are exported. Use the <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/setValue(_:forUndefinedKey:)> and <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/value(forUndefinedKey:)> methods to intercept access to properties that are not exported. Similarly, use the <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/invokeUndefinedMethod(fromWebScript:withArguments:)> method to intercept method invocations that are not exported.

If you want access to properties and methods defined in your own classes, use the methods in the WebScripting informal protocol to specify the properties and methods the class should export to WebKit’s JavaScript environment.

Use the [`callWebScriptMethod(_:withArguments:)`](/documentation/WebKit/WebScriptObject/callWebScriptMethod(_:withArguments:)) and [`evaluateWebScript(_:)`](/documentation/WebKit/WebScriptObject/evaluateWebScript(_:)) methods to execute scripts in the scripting environment.

## Topics

### Getting and setting properties

[`jsObject()`](/documentation/WebKit/WebScriptObject/jsObject())

Returns the JavaScript object corresponding to the receiver.

[`removeWebScriptKey(_:)`](/documentation/WebKit/WebScriptObject/removeWebScriptKey(_:))

Removes a property from a scripting environment.

[`webScriptValue(at:)`](/documentation/WebKit/WebScriptObject/webScriptValue(at:))

Returns the value of a property at the specified index.

[`setWebScriptValueAt(_:value:)`](/documentation/WebKit/WebScriptObject/setWebScriptValueAt(_:value:))

Sets the value of a property at the specified index.

### Executing scripts

[`callWebScriptMethod(_:withArguments:)`](/documentation/WebKit/WebScriptObject/callWebScriptMethod(_:withArguments:))

Returns the result of executing a method in the scripting environment.

[`evaluateWebScript(_:)`](/documentation/WebKit/WebScriptObject/evaluateWebScript(_:))

Returns the result of evaluating a script in the scripting environment.

### Raising exceptions

[`throwException(_:)`](/documentation/WebKit/WebScriptObject/throwException(_:))

Raises an exception in the current script execution context.

[`setException(_:)`](/documentation/WebKit/WebScriptObject/setException(_:))

Raises a scripting environment exception in the context of the current object.

### Getting a string representation

[`stringRepresentation()`](/documentation/WebKit/WebScriptObject/stringRepresentation())

Returns a string representation of the receiver.

## See Also

  [WebKit DOM Programming Topics](https://developer.apple.com/library/archive/documentation/AppleApplications/Conceptual/SafariJSProgTopics/index.html#//apple_ref/doc/uid/TP40001483)

  [WebKit Objective-C Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/DisplayWebContent/DisplayWebContent.html#//apple_ref/doc/uid/10000164i)



---

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)