---
title: "setWindowState(_:for:completionHandler:)"
framework: webkit
role: symbol
role_heading: Instance Method
path: "webkit/wkwebextensionwindow/setwindowstate(_:for:completionhandler:)"
---

# setWindowState(_:for:completionHandler:)

Called to set the state of the window.

## Declaration

```swift
optional func setWindowState(_ state: WKWebExtension.WindowState, for context: WKWebExtensionContext, completionHandler: @escaping ((any Error)?) -> Void)
```

```swift
optional func setWindowState(_ state: WKWebExtension.WindowState, for context: WKWebExtensionContext) async throws
```

## Parameters

- `state`: The new state of the window.
- `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 The implementation of windowState(for:) is a prerequisite. Without it, this method will not be called.

## See Also

### Related Documentation

- [windowState(for:)](webkit/wkwebextensionwindow/windowstate(for:).md)
