<!--
{
  "availability" : [
    "macOS: 15.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WKWebExtensionContext/performCommand(for:)-8btj0",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WKWebExtensionContext(im)performCommandForEvent:"
  },
  "title" : "performCommand(for:)"
}
-->

# performCommand(for:)

Performs the command associated with the given event.

```
func performCommand(for event: NSEvent) -> Bool
```

## Parameters

`event`

The event representing the user input.

## Return Value

Returns `YES` if a command corresponding to the event was found and performed, `NO` otherwise.

## Discussion

This method checks for a command corresponding to the provided event and performs it, if available. The app should use this method to perform any extension commands at an appropriate time in the app’s event handling, like in <doc://com.apple.documentation/documentation/AppKit/NSApplication/sendEvent(_:)> of  <doc://com.apple.documentation/documentation/AppKit/NSApplication> or  <doc://com.apple.documentation/documentation/AppKit/NSWindow/sendEvent(_:)> of  <doc://com.apple.documentation/documentation/AppKit/NSWindow> subclasses.

---

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)