---
title: "setSelected(_:for:completionHandler:)"
framework: webkit
role: symbol
role_heading: Instance Method
path: "webkit/wkwebextensiontab/setselected(_:for:completionhandler:)"
---

# setSelected(_:for:completionHandler:)

Called to set the selected state of the tab.

## Declaration

```swift
optional func setSelected(_ selected: Bool, for context: WKWebExtensionContext, completionHandler: @escaping ((any Error)?) -> Void)
```

```swift
optional func setSelected(_ selected: Bool, for context: WKWebExtensionContext) async throws
```

## Parameters

- `selected`: A boolean value indicating whether to select the tab.
- `context`: The context in which the web extension is running.
- `completionHandler`: A block that must be called upon completion. It takes a single error argument, which should be provided if any errors occurred.

## Discussion

Discussion This is equivalent to the user command-clicking on the tab to add it to or remove it from a selection. The method should update the tab’s selection state without changing the active tab. No action is performed if not implemented.

## See Also

### Related Documentation

- [isSelected(for:)](webkit/wkwebextensiontab/isselected(for:).md)
