> 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/get-started/samples/webviewer-cors.md).

# Implement WebViewer Cross-Origin Resource Sharing - CORS

Loading WebViewer's lib from a different domain using CORS.

This sample shows how to serve WebViewer's lib from a different domain. This project implements Cross-Origin Resource Sharing (CORS) as a client server `webviewer-app` that fetches resources from a server `webviewer-lib` in another domain. The dependency reference to `@pdftron/webviewer` exists in both `webviewer-lib\package.json` and `webviewer-app\package.json`.

It is recommended to serve the WebViewer lib on the same domain as the app itself for additional performance and security.

WebViewer provides a slick out-of-the-box responsive UI that enables you to view, annotate and manipulate PDFs and other document types inside any web project.

Click the button below to view the full project in GitHub.

{% tabs %}
{% tab title="TSX" %}
{% code title="App.tsx" lineNumbers="true" %}

```tsx
import React, { useEffect, useRef } from 'react';
import WebViewer from '@pdftron/webviewer';
import './App.css';

function App() {
  const viewer = useRef<HTMLDivElement>(null);

  useEffect(() => {
    WebViewer(
      {
        path: 'http://localhost:8081/lib/',
      },
      viewer.current as HTMLDivElement,
    ).then((instance) => {
      const url = 'https://pdftron.s3.amazonaws.com/downloads/pl/webviewer-demo.pdf';
      instance.UI.loadDocument(url);

      const { documentViewer, Annotations } = instance.Core;
      documentViewer.addEventListener('documentLoaded', () => {
        const annotManager = documentViewer.getAnnotationManager();
        const rectangle = new Annotations.RectangleAnnotation();
        rectangle.PageNumber = 2;
        rectangle.X = 100;
        rectangle.Y = 100;
        rectangle.Width = 250;
        rectangle.Height = 250;
        rectangle.Author = annotManager.getCurrentUser();
        annotManager.addAnnotation(rectangle);
      });
    });

  }, []);

  return (
    <div className="App">
      <div className="webviewer" ref={viewer}></div>
    </div>
  );
}

export default App;

```

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

[View the full sample on GitHub](https://github.com/ApryseSDK/webviewer-samples/tree/main/webviewer-cors)


---

# 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/get-started/samples/webviewer-cors.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.
