---
title: "takeSnapshot(using:for:completionHandler:)"
framework: webkit
role: symbol
role_heading: Instance Method
path: "webkit/wkwebextensiontab/takesnapshot(using:for:completionhandler:)"
---

# takeSnapshot(using:for:completionHandler:)

Called to capture a snapshot of the current webpage as an image.

## Declaration

```swift
optional func takeSnapshot(using configuration: WKSnapshotConfiguration, for context: WKWebExtensionContext, completionHandler: @escaping (UIImage?, (any Error)?) -> Void)
```

```swift
optional func snapshot(using configuration: WKSnapshotConfiguration, for context: WKWebExtensionContext) async throws -> UIImage?
```

```swift
optional func takeSnapshot(using configuration: WKSnapshotConfiguration, for context: WKWebExtensionContext, completionHandler: @escaping (NSImage?, (any Error)?) -> Void)
```

```swift
optional func snapshot(using configuration: WKSnapshotConfiguration, for context: WKWebExtensionContext) async throws -> NSImage?
```

## Parameters

- `configuration`: An object that specifies how the snapshot is configured.
- `context`: The context in which the web extension is running.
- `completionHandler`: A block that must be called upon completion. The block takes two arguments: the captured image of the webpage (or nil if capturing failed) and an error, which should be provided if any errors occurred.

## Discussion

Discussion Defaults to capturing the visible area of the tab’s web view if not implemented.
