<!--
{
  "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/WKWebExtensionWindow/setWindowState(_:for:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(pl)WKWebExtensionWindow(im)setWindowState:forWebExtensionContext:completionHandler:"
  },
  "title" : "setWindowState(_:for:completionHandler:)"
}
-->

# setWindowState(_:for:completionHandler:)

Called to set the state of the window.

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

## 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

The implementation of [`windowState(for:)`](/documentation/WebKit/WKWebExtensionWindow/windowState(for:)) is a prerequisite.

Without it, this method will not be called.

## See Also

[`windowState(for:)`](/documentation/WebKit/WKWebExtensionWindow/windowState(for:))

Called when the state of the window is needed.



---

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)