---
title: "openTab(with:makeActiveIfPossible:completionHandler:)"
framework: safariservices
role: symbol
role_heading: Instance Method
path: "safariservices/sfsafariwindow/opentab(with:makeactiveifpossible:completionhandler:)"
---

# openTab(with:makeActiveIfPossible:completionHandler:)

Opens a tab at the end of the tab bar.

## Declaration

```swift
func openTab(with url: URL, makeActiveIfPossible activateTab: Bool, completionHandler: (@Sendable (SFSafariTab?) -> Void)? = nil)
```

```swift
func openTab(with url: URL, makeActiveIfPossible activateTab: Bool) async -> SFSafariTab?
```

## Parameters

- `url`: The URL to navigate to.
- `activateTab`: doc://com.apple.documentation/documentation/Swift/true to make the tab active; otherwise doc://com.apple.documentation/documentation/Swift/false.
- `completionHandler`: A block called after the tab is opened.

## Discussion

Discussion important: You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration: func openTab(with url: URL, makeActiveIfPossible activateTab: Bool) async -> SFSafariTab? For information about concurrency and asynchronous code in Swift, see Calling Objective-C APIs Asynchronously. If the extension cannot access the URL, no tab is opened.

## See Also

### Working with Tabs

- [getActiveTab(completionHandler:)](safariservices/sfsafariwindow/getactivetab(completionhandler:).md)
