Get your setup working faster. Join our Discord for optimisation tips from elite testers.Join our Discord
Cross-site tracking on iOS devices
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:
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.
// 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.MutableCapabilities;importorg.openqa.selenium.remote.RemoteWebDriver;importjava.net.URL;publicclassJavaSample{publicstaticfinalStringAUTOMATE_USERNAME="YOUR_USERNAME";publicstaticfinalStringAUTOMATE_ACCESS_KEY="YOUR_ACCESS_KEY";publicstaticfinalStringURL="https://"+AUTOMATE_USERNAME+":"+AUTOMATE_ACCESS_KEY+"@hub-cloud.browserstack.com/wd/hub";publicstaticvoidmain(String[]args)throwsException{MutableCapabilitiescapabilities=newMutableCapabilities();HashMap<String,Object>browserstackOptions=newHashMap<String,Object>();browserstackOptions.put("osVersion","14");browserstackOptions.put("deviceName","iPhone 12");browserstackOptions.put("realMobile","true");browserstackOptions.put("projectName","BStack Sample Test");browserstackOptions.put("buildName","BStack Build Number 1");browserstackOptions.put("preventCrossSiteTracking","false");capabilities.setCapability("bstack:options",browserstackOptions);WebDriverdriver=newRemoteWebDriver(newURL(URL),caps);driver.get("https://alanhogan.github.io/web-experiments/3rd/third-party-cookies.html");Thread.Sleep(10000);driver.quit();}}
varwebdriver=require('selenium-webdriver');// Input capabilitiesvarcapabilities={'bstack:options':{"osVersion":"14","deviceName":"iPhone 12","realMobile":"true","projectName":"BStack Sample Test","buildName":"BStack Build Number 1","preventCrossSiteTracking":"false","userName":"YOUR_USERNAME","accessKey":"YOUR_ACCESS_KEY",},"browserName":"safari",}vardriver=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){IWebDriverdriver;SafariOptionscapabilities=newSafariOptions();Dictionary<string,object>browserstackOptions=newDictionary<string,object>();browserstackOptions.Add("osVersion","14");browserstackOptions.Add("deviceName","iPhone 12");browserstackOptions.Add("realMobile","true");browserstackOptions.Add("projectName","BStack Sample Test");browserstackOptions.Add("buildName","BStack Build Number 1");browserstackOptions.Add("preventCrossSiteTracking","false");browserstackOptions.Add("userName","YOUR_USERNAME");browserstackOptions.Add("accessKey","YOUR_ACCESS_KEY");capabilities.AddAdditionalOption("bstack:options",browserstackOptions);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('bstack:options'=>array("osVersion"=>"14","deviceName"=>"iPhone 12","realMobile"=>"true","projectName"=>"BStack Sample Test","buildName"=>"BStack Build Number 1","preventCrossSiteTracking"=>"false",),)$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();?>
fromtimeimportsleepfromseleniumimportwebdriverfromselenium.webdriver.common.keysimportKeysfromselenium.webdriver.common.desired_capabilitiesimportDesiredCapabilitiesdesired_cap={'bstack:options':{"osVersion":"14","deviceName":"iPhone 12","realMobile":"true","projectName":"BStack Sample Test","buildName":"BStack Build Number 1","preventCrossSiteTracking":"false",},}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 capabilitiescapabilities={'bstack:options'=>{"osVersion"=>"14","deviceName"=>"iPhone 12","realMobile"=>"true","projectName"=>"BStack Sample Test","buildName"=>"BStack Build Number 1","preventCrossSiteTracking"=>"false",},}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
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{publicstaticfinalStringAUTOMATE_USERNAME="YOUR_USERNAME";publicstaticfinalStringAUTOMATE_ACCESS_KEY="YOUR_ACCESS_KEY";publicstaticfinalStringURL="https://"+AUTOMATE_USERNAME+":"+AUTOMATE_ACCESS_KEY+"@hub-cloud.browserstack.com/wd/hub";publicstaticvoidmain(String[]args)throwsException{DesiredCapabilitiescaps=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 namecaps.setCapability("build","BStack Build Number 1");// CI/CD job or build namecaps.setCapability("browserstack.preventCrossSiteTracking","false");// This custom capability will enable cross site trackingWebDriverdriver=newRemoteWebDriver(newURL(URL),caps);driver.get("https://alanhogan.github.io/web-experiments/3rd/third-party-cookies.html");Thread.Sleep(10000);driver.quit();}}
varwebdriver=require('selenium-webdriver');// Input capabilitiesvarcapabilities={'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}vardriver=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){IWebDriverdriver;OpenQA.Selenium.Safari.SafariOptionscapability=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 namecapability.AddAdditionalCapability("build","BStack Build Number 1");// CI/CD job or build namecapability.AddAdditionalCapability("browserstack.user","YOUR_USERNAME");capability.AddAdditionalCapability("browserstack.key","YOUR_ACCESS_KEY");capability.AddAdditionalCapability("browserstack.preventCrossSiteTracking","false");// This custom capability will enable cross site trackingdriver=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();?>
fromtimeimportsleepfromseleniumimportwebdriverfromselenium.webdriver.common.keysimportKeysfromselenium.webdriver.common.desired_capabilitiesimportDesiredCapabilitiesdesired_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 capabilitiescaps=Selenium::WebDriver::Remote::Capabilities.newcaps['device']='iPhone 8 Plus'caps['realMobile']='true'caps['os_version']='12'caps['name']='BStack-[Ruby] Sample Test'# Test namecaps['build']='BStack Build Number 1'# CI/CD job or build namecaps['browserstack.preventCrossSiteTracking']='false'# This custom capability will enable cross site trackingdriver=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
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