CORS issue with i18n .json file

WebViewer Version: 11.9.0

Do you have an issue with a specific file(s)? No
Can you reproduce using one of our samples or online demos? No
Are you using the WebViewer server? No
Does the issue only happen on certain browsers? No
Is your issue related to a front-end framework? No
Is your issue related to annotations? No

Please give a brief summary of your issue:
This is basically a repeat of this question: CORS error during initialization of WebViewer - translation file

Please describe your issue and provide steps to reproduce it:
Our application is failing in a test environment to load the translation-en.json i18n file. The file is being loaded correctly and is accessible directly through our static asset server (I can plug the URL from the failed network request into my browser and view the .json file without issue) and works locally. The pre-flight OPTIONS request is rejected with a 403. The only unique wrinkle in our application is that we are loading this from a config file.

We’re not even using this internationalization file in our deployment of the application as we have a custom UI. As a workaround, is there a way to avoid loading this file altogether?


I’m answering the last questions your support person asked before this resolved

1. Could you share the snippet of code used to initialize WebViewer in your application? Are you setting the language?
The language is not being set.

return WebViewer(
    {
      licenseKey: currentConfig.APRYSE_LICENSE_KEY,
      path: path,
      config: configPath,
      custom: JSON.stringify(custom),
    },
    viewer,
  ).then(() => tearDownFunction)

2. How is CORS configured on your localhost server where the module federated component is hosted? How are the headers being set for Access-Control-Allow-Origin?

I am able to run this locally using a minimal server on port 3001 with the main app running on localhost:3000 and using the standard cors package express middleware

const express = require("express");
const cors = require("cors");
const app = express();
app.use(cors());
app.use("/webviewer", express.static(path.join(__dirname, "assets", "webviewer")));

running the app locally this doesn’t give me any problems and the access control origin header is "*" for both local and hosted app.

3. If possible, please provide the headers from the network request for the translation-en.json or whichever language file.

:authority [application-url]
:method OPTIONS
:path /[...]/uat/webviewer/v1/ui/i18n/translation-en.json
:scheme https
accept */*
accept-encoding gzip, deflate, br, zstd
accept-language en-US,en;q=0.9
access-control-request-headers x-requested-with
access-control-request-method GET
cache-control no-cache
origin https://[application-url].com
pragma no-cache
priority u=1, i
referer https://[application-url].com/
sec-fetch-dest empty
sec-fetch-mode cors
sec-fetch-site cross-site
user-agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36

4. Any specific console error messages being displayed?
Access to XMLHttpRequest at 'https://[static-server-url]/webviewer/v1/ui/i18n/translation-en.json' from origin '[application url]' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

Hello @sam.codrington ,

Thank you for posting on our forum.

If you have not already, please see our FAQ here regarding CORS support for WebViewer: https://docs.apryse.com/web/faq/cors-support

Additionally, you mentioned using a custom UI, however you seem to be using the WebViewer constructor. If building your own UI, you can render the DocumentViewer class without the UI, thus avoiding requests for the translation-en.json file. See our guide here for more information: https://docs.apryse.com/web/guides/core

For example, in our Flipbook demo here, which uses custom UI, you can see there is no request made for translation-en.json: https://sdk.apryse.com/samples/web/samples/advanced/flipbook/

Let us know if these solutions work for you!

Best Regards,
Jacob Romano Carlsen
Web Development Support Engineer
Apryse Software Inc.

Hi Jacob,

The non-UI solution sounds promising but how do I initialize the page without using the WebViewer constructor if I’m running the instance from a config javascript file. The docs that you linked don’t mention that use case specifically and the config docs (Config Files for JavaScript PDF Viewer | Apryse documentation) don’t mention how to either.

Hello @sam.codrington ,

What kind of code is in your config docs currently, and what is the current use case of your external config file? Feel free to also provide your current config file.

When initializing a documentViewer via our guide on Custom UI, the Core namespace becomes available to the window. In other words, APIs can be called directly in the same file without the need of an external config file.

See the source code for the flipbook demo previously provided for examples on https://sdk.apryse.com/samples/web/samples/advanced/flipbook/flipbook.js

Best Regards,
Jacob Romano Carlsen
Web Development Support Engineer
Apryse Software Inc.

Hi there,

We’ve discovered you have an undocumented property that can be passed to the initializer which prevents the loading of i18n files (see Load i18n labels from options · Issue #564 · ApryseSDK/webviewer-ui · GitHub) it would be nice if that were documented/formally supported. However we’ve discovered if you add this property, the VIEWER_LOADED event is never fired from the application. Could this bug be fixed, this would resolve our issue.

Hello @sam.codrington ,

Thank you for the update.

We were able to confirm the disableI18n does function, but does not appear in our API docs or types file. We’ve raised this issue of documentation to our backlog for our Product team to investigate further.

That said, when testing the option in the constructor, I found that the viewerLoaded event was still being successfully triggered at the same time there was no request for the translation files:

For context, I tested using Version 11.9 of our sample builds here: https://docs.apryse.com/web/guides/download

Are you able to reproduce the viewerLoaded not being triggered in one of these samples (both Version 11.9 and our latest release Version 11.12)? If so, feel free to provide the sample code used and any additional findings and we can investigate further.

Best Regards,
Jacob Romano Carlsen
Web Development Support Engineer
Apryse Software Inc.