# Window handling on iOS safari browser

**URL:** <https://discuss.appium.io/t/window-handling-on-ios-safari-browser/43122>\
**Category:** Issues/Bugs\
**Created:** [July 31, 2024, 8:51am UTC](https://discuss.appium.io/t/window-handling-on-ios-safari-browser/43122 "2024-07-31T08:51:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paluri\_Pravinya](https://discuss.appium.io/user_avatar/discuss.appium.io/paluri_pravinya/32/13094_2.png) [@Paluri\_Pravinya](https://discuss.appium.io/u/Paluri_Pravinya)\
**Post date:** [July 31, 2024, 8:51am UTC](https://discuss.appium.io/t/window-handling-on-ios-safari-browser/43122/1 "2024-07-31T08:51:48Z")

</div>

Hi,  
I am working on mobile web automation using NightwatchJS and appium.  
I need to open a link on safari browser, close the tab and switch back to the previous tab. This is not working on iOS safari. The test script works perfectly on android mobile web, but not on iOS safari browser.  
Could someone please help me in finding solution?  
Thank you!

---

<div class="post-metadata">

**Author:** ![Santiagogb](https://discuss.appium.io/user_avatar/discuss.appium.io/santiagogb/32/13848_2.png) [@Santiagogb](https://discuss.appium.io/u/Santiagogb)\
**Post date:** [December 9, 2024, 12:15pm UTC](https://discuss.appium.io/t/window-handling-on-ios-safari-browser/43122/2 "2024-12-09T12:15:28Z")

</div>

Hi everyone,

I am working on an iOS device, and i need to close the safari window in order to continue over principal app, i´ve tried with switch context, but the window does not close:

 ![image](https://discuss.appium.io/uploads/default/original/2X/2/26222d14792b6126550649a3e7f2820506fa3c2a.jpeg)

I am using appium 2.12, java 17, and XCUITest

Thank you!!!

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [December 9, 2024, 7:50pm UTC](https://discuss.appium.io/t/window-handling-on-ios-safari-browser/43122/3 "2024-12-09T19:50:14Z")

</div>

> [@Santiagogb](#):
>
> in order to continue over principal app

Have you tried activateApp?

[https://appium.github.io/appium.io/docs/en/commands/device/app/activate-app/](https://appium.github.io/appium.io/docs/en/commands/device/app/activate-app/)

Use the bundle id of your application to continue over to principal app.

---

<div class="post-metadata">

**Author:** ![Santiagogb](https://discuss.appium.io/user_avatar/discuss.appium.io/santiagogb/32/13848_2.png) [@Santiagogb](https://discuss.appium.io/u/Santiagogb)\
**Post date:** [December 9, 2024, 8:12pm UTC](https://discuss.appium.io/t/window-handling-on-ios-safari-browser/43122/4 "2024-12-09T20:12:16Z")

</div>

Hi @wreed, thank you for your answer.

finally i used the termiteApp in order to finish the app, and activeApp to start the app again, this implementation works well, however i would like to find a better implementation where i haven’t to close the app.

driver.terminateApp(“com.organization.myApp”);  
driver.activateApp(“com.organization.myApp”);

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [December 9, 2024, 8:59pm UTC](https://discuss.appium.io/t/window-handling-on-ios-safari-browser/43122/5 "2024-12-09T20:59:49Z")

</div>

> [@Santiagogb](#):
>
> i need to close the safari window in order to continue over principal app

> [@Santiagogb](#):
>
> i would like to find a better implementation where i haven’t to close the app

I’m not understanding. You said you needed to close safari, and switch to your app. Now you are saying something different? Can you give some more details? I’m not sure what I’m missing here. Why do you need to terminate your app?

---

<div class="post-metadata">

**Author:** ![Santiagogb](https://discuss.appium.io/user_avatar/discuss.appium.io/santiagogb/32/13848_2.png) [@Santiagogb](https://discuss.appium.io/u/Santiagogb)\
**Post date:** [December 9, 2024, 10:02pm UTC](https://discuss.appium.io/t/window-handling-on-ios-safari-browser/43122/6 "2024-12-09T22:02:10Z")

</div>

> [@Santiagogb](#):
>
> i need to close the safari window in order to continue over principal app

yes exactly I need to close only safari, but when using this line **terminateApp(“com.apple.SafariViewService”)**, it closes the safari process completely with some credentials that I need, (for that reason the main idea is to give the option cancel to the safari window).

> [@wreed](#):
>
> I’m not understanding. You said you needed to close safari, and switch to your app. Now you are saying something different? Can you give some more details? I’m not sure what I’m missing here. Why do you need to terminate your app?

That’s why for now it works closing the app and reopening it, because when doing this process the credentials are saved and the safari window is closed.

```auto
terminateApp(“com.organization.myAPP”); closes the app and the safari window also.

```

```auto
activateApp(“com.organization.myAPP”); Open the app with configured credenciales

```

and if I only use this line: **activateApp(com.organization.MyApp);**, the safari window does not close.

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [December 10, 2024, 4:42am UTC](https://discuss.appium.io/t/window-handling-on-ios-safari-browser/43122/7 "2024-12-10T04:42:34Z")

</div>

Safari bundle id is ‘com.apple.mobilesafari’.

> **[Bundle IDs for native iPhone and iPad apps](https://support.apple.com/guide/deployment/bundle-ids-for-native-iphone-and-ipad-apps-depece748c41/web)**
>
> If you remove an iPhone or iPad app that was preinstalled, you can add that app back using mobile device management and the app’s bundle ID.

---

<div class="post-metadata">

**Author:** ![Santiagogb](https://discuss.appium.io/user_avatar/discuss.appium.io/santiagogb/32/13848_2.png) [@Santiagogb](https://discuss.appium.io/u/Santiagogb)\
**Post date:** [December 11, 2024, 1:25pm UTC](https://discuss.appium.io/t/window-handling-on-ios-safari-browser/43122/8 "2024-12-11T13:25:18Z")

</div>

Thank you for your suggestion @wreed, i just tried with that bundleId, but for any reason the safari window does not close, and it stays there active.

i used this line:

```auto
driver.terminateApp("com.apple.mobilesafari");

```
