<!--
{
  "availability" : [
    "iOS: 18.4.0 -",
    "iPadOS: 18.4.0 -",
    "macCatalyst: 18.4.0 -",
    "macOS: 15.4.0 -",
    "visionOS: 2.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WKWebExtensionContext/action(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WKWebExtensionContext(im)actionForTab:"
  },
  "title" : "action(for:)"
}
-->

# action(for:)

Retrieves the extension action for a given tab, or the default action if `nil` is passed.

```
func action(for tab: (any WKWebExtensionTab)?) -> WKWebExtension.Action?
```

## Parameters

`tab`

The tab for which to retrieve the extension action, or `nil` to get the default action.

## Discussion

The returned object represents the action specific to the tab when provided; otherwise, it returns the default action. The default action is useful when the context is unrelated to a specific tab. When possible, specify the tab to get the most context-relevant action.

## See Also

[`performAction(for:)`](/documentation/WebKit/WKWebExtensionContext/performAction(for:))

Performs the extension action associated with the specified tab or performs the default action if `nil` is passed.



---

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)