A guide to enable cross-site tracking on iOS devices with versions 11 and above
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. 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:
platforms:-deviceName: iPhone 15
osVersion:17realMobile:trueprojectName: BStack Sample Test
buildName: BStack Build Number 1
preventCrossSiteTracking:false
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
In case you want to enable cross-site tracking for testing purpose, you can do so by using BrowserStack’s preventCrossSiteTracking custom capability.
Capability
Description
Expected values
preventCrossSiteTracking
Toggle cross-site tracking on iOS devices.
A string. Default is true.
false if you want to enable cross-site tracking, true otherwise.
The following code snippet shows the usage of the capability 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.
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.
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.importorg.openqa.selenium.By;importorg.openqa.selenium.Platform;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.WebElement;importorg.openqa.selenium.remote.DesiredCapabilities;importorg.openqa.selenium.remote.RemoteWebDriver;importjava.net.URL;publicclassJavaSample{publicstaticfinalString AUTOMATE_USERNAME ="YOUR_USERNAME";publicstaticfinalString AUTOMATE_ACCESS_KEY ="YOUR_ACCESS_KEY";publicstaticfinalString URL ="https://"+ AUTOMATE_USERNAME +":"+ AUTOMATE_ACCESS_KEY +"@hub-cloud.browserstack.com/wd/hub";publicstaticvoidmain(String[] args)throwsException{DesiredCapabilities caps =newDesiredCapabilities();
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 trackingWebDriver driver =newRemoteWebDriver(newURL(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 capabilitiesvar 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 =newwebdriver.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();});
usingSystem;usingSystem.Threading;usingOpenQA.Selenium;usingOpenQA.Selenium.Remote;namespaceSeleniumTest{classProgram{staticvoidMain(string[] args){IWebDriver driver;OpenQA.Selenium.Safari.SafariOptions capability =newOpenQA.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 =newRemoteWebDriver(newUri("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();}}}
<?phprequire_once('vendor/autoload.php');useFacebook\WebDriver\Remote\RemoteWebDriver;useFacebook\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
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.
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)
Did this page help you?
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