---
title: Wait for origin sync
slug: web-experimentation/api/aaiV-wait-for-origin-sync
docTags: 
createdAt: 2026-08-05T20:56:13.000Z
---

Use the `waitForOriginSync` API to make Optimizely Web Experimentation wait for cross-origin data and sync before activating the snippet. When using this API, the visitor's ID is set based on existing data, if any, from the specified origins, so that a single visitor keeps the same visitor ID, and relevant data, when moving back and forth across schemes or domains or top-level domains (TLDs).

Because this makes the snippet wait for cross-domain data for up to one second, it could cause a "flash" (if the page renders and an experiment activates afterward, causing the snippet to apply visual changes). Because of this, you should not use this API on pages that have above-the-fold visual experiments. Learn more about [cross-origin targeting](docId\:D4cK9MtLwo5SilACqb_sh).

Web Experimentation uses an iframe to [persist localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage) from one website "origin" to another. Thus anything that prevents the [iframe](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) from loading or initializing causes `waitForOriginSync` to timeout and not emit the `originsSynced` event. The following are are three known ways this can happen:

1. The [origin setting](docId\:D4cK9MtLwo5SilACqb_sh) in your optimizely.com account is set incorrectly.
2. The user's browser blocks all iframes or iframes specifically from `*.cdn.optimizely.com`.
3. The browser's privacy settings prevent setting or retrieving `localStorage` keys from iframe origins.

Some browsers block cross-origin iframe `localStorage` if "third-party cookies" are disabled. When a browser does this, the Web Experimentation iframe does not function when a user is on your website (because in this situation, the Web Experimentation iframe is from a separate website, for example, a "third-party" origin).

### Syntax

```javascript
window["optimizely"].push(waitForOriginSync);
```

### Parameters

| Parameter and type                          | Child attribute                                | Description                                                                                                                                                                                                                                                                                                                                                                                                |
| ------------------------------------------- | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **waitForOriginSync** *WaitForOriginObject* | N/A                                            | An object with the `type` field set to `waitForOriginSync`. The other fields are the function arguments. Required.                                                                                                                                                                                                                                                                                         |
| **type** *string*                           | Child attribute of type `WaitForOriginObject`. | The argument indicating that you're using the `waitForOriginSync` function. Required.                                                                                                                                                                                                                                                                                                                      |
| **canonicalOrigins** *array\[string]*       | Child attribute of type `WaitForOriginObject`. | An array of origins from which data should be received before Web Experimentation activates. These origins should be listed in priority order, with the highest-priority origin first. Web Experimentation waits for data from all listed origins (using substring match) before activating. Origins match if any of the `canonicalOrigins` you specify are present as a substring anywhere in the origin. |

### Example call

```javascript
window["optimizely"].push({
  "type": "waitForOriginSync",
  "canonicalOrigins": ["optimizely.com", "developers.optimizely.com"]
});
```
