Cross Site Tracking on iOS Devices

This document guides you to toggle the ‘Cross-Site Tracking’ feature on iOS devices.

Introduction

Cross-site tracking takes place when you browse from one website to another website. You’re often followed by trackers that collect data on where you’ve been and what you’ve done, using scripts, widgets, etc. embedded on the sites you visit.

On iOS devices with iOS versions 11 and above the cross-site tracking is disabled by default. In case you want to enable cross-site tracking for testing purpose, you can do so by using BrowserStack’s browserstack.preventCrossSiteTracking custom capability.

Capability Description Expected values
browserstack.preventCrossSiteTracking Toggle cross-site tracking on iOS devices. A string. Default is true.

false if you want to enable cross-site tracking, true otherwise.

By setting the capability to false, you will basically be toggling the Prevent Cross-Site Tracking Safari setting to Off in the iPhone device. An image of the option in its default setting is shown below:

iPhone Prevent Cross Site Tracking Enabled

Sample code

The following code snippet shows the usage of the capability browserstack.preventCrossSiteTracking set to false which means that tracking would be enabled across sites i.e. cookies set in one site would be available in another site.

// Sample test in Java to run Automate session.
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
public class JavaSample {
	public static final String AUTOMATE_USERNAME = "YOUR_USERNAME";
	public static final String AUTOMATE_ACCESS_KEY = "YOUR_ACCESS_KEY";
	public static final String URL = "https://" + AUTOMATE_USERNAME + ":" + AUTOMATE_ACCESS_KEY + "@hub-cloud.browserstack.com/wd/hub";
	public static void main(String[] args) throws Exception {
		DesiredCapabilities caps = new DesiredCapabilities();
		caps.setCapability("browserName", "iPhone");
		caps.setCapability("device", "iPhone 8 Plus");
		caps.setCapability("realMobile", "true");
		caps.setCapability("os_version", "12");
		caps.setCapability("name", "BStack-[Java] Sample Test"); // Test name
		caps.setCapability("build", "BStack Build Number 1"); // CI/CD job or build name
		caps.setCapability("browserstack.preventCrossSiteTracking", "false"); // This custom capability will enable cross site tracking
		WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
		driver.get("https://alanhogan.github.io/web-experiments/3rd/third-party-cookies.html");
		Thread.Sleep(10000);
		driver.quit();
	}
}
var webdriver = require('selenium-webdriver');
// Input capabilities
var capabilities = {
 'device' : 'iPhone 8 Plus',
 'realMobile' : 'true',
 'os_version' : '12',
 'browserName' : 'iPhone',
 'name': 'BStack-[NodeJS] Sample Test', // Test name
 'build': 'BStack Build Number 1', // CI/CD job or build name
 'browserstack.user' : 'YOUR_USERNAME',
 'browserstack.key' : 'YOUR_ACCESS_KEY',
 'browserstack.preventCrossSiteTracking': 'false' // This custom capability will enable cross site tracking
}
var driver = new webdriver.Builder().usingServer('https://hub-cloud.browserstack.com/wd/hub').
withCapabilities(capabilities).build();
driver.get('https://alanhogan.github.io/web-experiments/3rd/third-party-cookies.html').then(function(){
      driver.quit();
});
using System;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
namespace SeleniumTest
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver;
            OpenQA.Selenium.Safari.SafariOptions capability = new OpenQA.Selenium.Safari.SafariOptions();
            capability.AddAdditionalCapability("browserName", "iPhone");
            capability.AddAdditionalCapability("device", "iPhone 8 Plus");
            capability.AddAdditionalCapability("realMobile", "true");
            capability.AddAdditionalCapability("os_version", "12");
            capability.AddAdditionalCapability("name", "BStack-[C_sharp] Sample Test" ); // Test name
            capability.AddAdditionalCapability("build", "BStack Build Number 1"); // CI/CD job or build name
            capability.AddAdditionalCapability("browserstack.user", "YOUR_USERNAME");
            capability.AddAdditionalCapability("browserstack.key", "YOUR_ACCESS_KEY");
            capability.AddAdditionalCapability("browserstack.preventCrossSiteTracking", "false"); // This custom capability will enable cross site tracking

            driver = new RemoteWebDriver(
              new Uri("https://hub-cloud.browserstack.com/wd/hub/"), capability
            );
            driver.Navigate().GoToUrl("https://alanhogan.github.io/web-experiments/3rd/third-party-cookies.html");
            Thread.Sleep(10000);
            driver.Quit();
        }
    }
}
<?php
  require_once('vendor/autoload.php');
  use Facebook\WebDriver\Remote\RemoteWebDriver;
  use Facebook\WebDriver\WebDriverBy;
  $caps = array(
    "browserName" => "iPhone",
    "device" => "iPhone 8 Plus",
    "realMobile" => "true",
    "os_version" => "12",
    "name" => "BStack-[Php] Sample Test", // Test name
    "build" => "BStack Build Number 1", // CI/CD job or build name
    "browserstack.preventCrossSiteTracking" => 'false' # This custom capability will enable cross site tracking
  );
  $web_driver = RemoteWebDriver::create(
    "https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",
    $caps
  );
  $web_driver->get("https://alanhogan.github.io/web-experiments/3rd/third-party-cookies.html");
  sleep(20)
  $web_driver->quit();
?>
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
desired_cap = {
 'browserName': 'iPhone',
 'device': 'iPhone 8 Plus',
 'realMobile': 'true',
 'os_version': '12',
 'name': 'BStack-[Python] Sample Test', # Test name
 'build': 'BStack Build Number 1', # CI/CD job or build name
 'browserstack.preventCrossSiteTracking': 'false' # This custom capability will enable cross site tracking
}
driver = webdriver.Remote(
        command_executor='https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub',
        desired_capabilities=desired_cap
    )
driver.get('https://alanhogan.github.io/web-experiments/3rd/third-party-cookies.html')
sleep(20)
driver.quit()
require 'rubygems'
require 'selenium-webdriver'
# Input capabilities
caps = Selenium::WebDriver::Remote::Capabilities.new
caps['device'] = 'iPhone 8 Plus'
caps['realMobile'] = 'true'
caps['os_version'] = '12'
caps['name'] = 'BStack-[Ruby] Sample Test' # Test name
caps['build'] = 'BStack Build Number 1' # CI/CD job or build name
caps['browserstack.preventCrossSiteTracking'] = 'false' # This custom capability will enable cross site tracking
driver = Selenium::WebDriver.for(:remote,
  :url => "https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",
  :desired_capabilities => caps)
driver.navigate.to "https://alanhogan.github.io/web-experiments/3rd/third-party-cookies.html"
sleep(20)
driver.quit
use Selenium::Remote::Driver;
# Input capabilities
my $extraCaps = {
  'browserName' => 'iPhone',
  'device' => 'iPhone 8 Plus',
  'realMobile' => 'true',
  'os_version' => '12',
  'name' => 'BStack-[Perl] Sample Test', # Test name
  'build' => 'BStack Build Number 1', # CI/CD job or build name
  'browserstack.preventCrossSiteTracking' => 'false' # This custom capability will enable cross site tracking
};
my $login = "YOUR_USERNAME";
my $key = "YOUR_ACCESS_KEY";
my $host = "$login:$key\@hub-cloud.browserstack.com";
my $driver = new Selenium::Remote::Driver('remote_server_addr' => $host,
  'port' => '80', 'extra_capabilities' => $extraCaps);
$driver->get('https://alanhogan.github.io/web-experiments/3rd/third-party-cookies.html');
$driver->quit();

You should now be able to toggle the ‘Prevent Cross-Site Tracking’ option on iOS device settings. If you need any further help, feel free to contact Support team.

Important: This capability will NOT allow interacting with 3rd party iFrames in iOS Safari which is blocked due to CORS. This is a restriction from Apple and there are no workarounds currently. (See GitHub issue)

We're sorry to hear that. Please share your feedback so we can do better






Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better






Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to automation expert