To implement SeaText AI in a multi-domain SPA without cross-origin blockers, add the SeaText snippet to your SPA's entry point, confirm the script loads asynchronously, ensure your application allows local storage access, and verify the integration by building and serving the app while inspecting the browser Console and Network tabs. This process follows the official SeaText SPA integration guide and works across all your SPA domains from initial deployment.
Prerequisites Before Integration
Before you start, gather the following items to avoid delays:
- A complete list of all domains and subdomains your SPA runs on, including staging and test environments.
- Access to your SPA's entry point file (usually index.html or your framework's main mount file).
- Access to browser developer tools for testing script loading and network requests.
- Confirmation that your SPA permits third-party scripts to read and write local storage.
Step 1: Add the SeaText Script to Your SPA Entry Point
Locate your SPA's entry point. For most projects this is the index.html file in the public or root folder. For framework-specific setups it may be the main TypeScript or JavaScript file where your app mounts (e.g., main.tsx for React, main.js for Vue, index.html in the src folder for Angular). Insert the full SeaText integration snippet inside the <body> tag of this file. The snippet provided by SeaText already includes the async attribute, so the script loads asynchronously and will not block your SPA's initial render.
For React SPAs, add the snippet to public/index.html before your root <div id="root">. For Vue, add it to public/index.html. For Angular, add it to the index.html file in the src folder.
Step 2: Verify Asynchronous Loading and Local Storage Access
After adding the snippet, build and serve your application using the standard commands for your framework (for example npm start, npm run serve, or ng serve). Open your browser's Developer Tools (press F12) and check the Console and Network tabs. Confirm that the SeaText script loads without errors. The script stores a minimal user session ID in local storage; ensure your application's content security policy and browser settings allow this access. If local storage is blocked, SeaText features may not function correctly across domains.
Step 3: Build, Serve, and Inspect the Integration
With the app running, inspect the Console for any JavaScript errors related to SeaText. In the Network tab, filter for requests to SeaText's domain and verify that the script and any subsequent API calls return successful responses. Perform a functionality check: trigger a SeaText feature such as a language switch or translation action and confirm it works as expected. Repeat this verification on each domain and subdomain your SPA uses, including staging environments.
Understanding Cross-Origin Compatibility
Cross-Origin Resource Sharing (CORS) is a browser security mechanism that restricts web pages from making requests to a different domain unless the target domain explicitly allows it via HTTP headers. SeaText's script is served from SeaText's CDN. When your SPA loads the script, the browser checks for appropriate CORS headers. The official SeaText documentation notes that you must ensure the script is compatible and does not face cross-origin issues. Because the snippet loads asynchronously and uses local storage for a session ID, the integration relies on the browser permitting these cross-origin interactions. No additional dashboard configuration is documented in the provided sources.
Common Pitfalls and How to Avoid Them
The most frequent issue is forgetting to add the snippet to the correct entry point, which prevents the script from loading at all. Another common mistake is blocking local storage access for third-party scripts, which stops SeaText from storing its session ID and breaks cross-domain preference tracking. Some developers skip the verification step of building and serving the app, then miss Console errors that indicate script loading failures. Always run the build and serve commands, then inspect both Console and Network tabs before considering the integration complete.
Limitations of This Setup
This integration method covers only SeaText's client-side script and browser-based API calls. If you use SeaText's server-side translation API, you will need to configure CORS on your own server or use a reverse proxy to avoid cross-origin blocks. Additionally, if your SPA uses a service worker that intercepts network requests, you may need to add SeaText's CDN and API endpoints to the service worker's allowed request list. The client-side script stores a minimal session ID in local storage; if your SPA blocks local storage for third-party scripts, you must adjust your content security policy accordingly.
Frequently Asked Questions
Do I need to add a crossorigin attribute to the script tag?
The official SeaText SPA snippet already includes the async attribute. The documentation does not specify a crossorigin attribute. Add the snippet exactly as provided.
How long does it take for the script to become active after deployment?
The script loads asynchronously when the page loads. There is no documented propagation delay for the client-side script itself. Verify by checking the Network tab after a fresh page load.
Can I use wildcards for allowed origins in a dashboard?
The provided sources do not document an allowedOrigins dashboard setting or wildcard configuration. Follow the integration steps in the official SPA guide.
What should I do if I see CORS errors in the Console?
First, confirm the snippet is placed in the correct entry point and that the script loads (check Network tab). Ensure your SPA's content security policy allows scripts from SeaText's domain and permits local storage access. If errors persist, consult SeaText support with details of your domains and the exact error messages.
Does this setup work for SeaText's server-side API?
No. This guide covers the client-side SeaText script only. Server-side API usage requires separate CORS configuration on your backend.
Will the SeaText script affect my SPA's performance?
The script is under 15 KB and loads asynchronously, so it does not block initial render. Translation API calls are cached to reduce repeated network requests.