> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/advanced/remote-lib.md).

# Loading WebViewer from another domain

Learn how to share WebViewer library files across different domains for convenience and security. Follow these steps to ensure seamless integration and customization. The Apryse Web SDK streamlines se

It may be necessary to share the WebViewer library files amongst various apps and domains (ex. update convenience or security policy). You can load WebViewer's lib folder from another domain by setting the `path` constructor option to an absolute URL (e.g. `https://otherdomain.com/lib`).

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
// https://myserver.com
WebViewer({
  path: 'https://otherdomain.com/lib',
}, document.getElementById('viewer'))
  .then(instance => {});
```

{% endcode %}
{% endtab %}
{% endtabs %}

When you call an API on the [WebViewer](https://sdk.apryse.com/api/web/WebViewerInstance.html) object, behind the scenes it reaches into the iframe and calls functions in that context. This is fine in a normal scenario where WebViewer and your app are on the same domain. However, the WebViewer library is now hosted on a different domain and the iframe will be pointing to that host domain as its source. When the iframe is on a different domain, then [cross origin script access](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#Cross-origin_script_API_access) applies and WebViewer will no longer be able to call functions inside the iframe due to security limitations.

{% hint style="info" %}
Cross origin issues can occur only if you're using iframe. If you're using [web components instead of iframe](/web/ui-customization/web-component-vs-iframe.md), you'll need to understand [CORS headers on the resources](/web/advanced/cross-origin-workers.md#cross-origin-workers-in-webviewer-webcomponent) for web components.
{% endhint %}

For example, the following will occur:

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
WebViewer(...)
  .then(instance => {
    // instance is undefined!
  });
```

{% endcode %}
{% endtab %}
{% endtabs %}

In this case you have two options to interact with and customize WebViewer.

1. Run your custom code in a [config file](/web/advanced/config-files.md). Config files are loaded and executed inside the iframe so they run in the iframe's context and have no problem accessing the APIs. Make sure to follow [this step](/web/advanced/config-files.md#using-a-config-file-when-the-path-is-on-another-domain) so that the config file is able to be loaded.
2. Use the window [postMessage API](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage/) to communicate between your page and the iframe. For example, you could send a message to the iframe with the value being the URL to the document you want to load. The iframe would handle this message in a config file and call `instance.UI.loadDocument` to load the document from the new URL.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/advanced/remote-lib.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
