Black OHIF page on Orthanc: CORS issue?

Hello everyone,

I recently migrated my Orthanc setup from an Ubuntu server to a new RHEL9 server, and I’m encountering issues with the OHIF plugin. Here’s a breakdown of my setup and the problem:

  • I’ve deployed Orthanc in a Docker container, and it’s functioning properly.
  • When I open a study in OHIF, I only see a blank black screen with the OHIF favicon. The study does not load.
  • Checking the browser console, I see the following errors:

When I access the manifest.json file directly, the file looks like this:

{
    "name": "OHIF Viewer",
    "short_name": "Viewer",
    "description": "OHIF Viewer",
    "dir": "auto",
    "lang": "en-US",
    "orientation": "any",
    "icons": [
        {
            "src": "/assets/android-chrome-36x36.png",
            "sizes": "36x36",
            "type": "image/png"
        },
        {
            "src": "/assets/android-chrome-48x48.png",
            "sizes": "48x48",
            "type": "image/png"
        },
        {
            "src": "/assets/android-chrome-72x72.png",
            "sizes": "72x72",
            "type": "image/png"
        },
        {
            "src": "/assets/android-chrome-96x96.png",
            "sizes": "96x96",
            "type": "image/png"
        },
        {
            "src": "/assets/android-chrome-144x144.png",
            "sizes": "144x144",
            "type": "image/png"
        },
        {
            "src": "/assets/android-chrome-192x192.png",
            "sizes": "192x192",
            "type": "image/png"
        },
        {
            "src": "/assets/android-chrome-256x256.png",
            "sizes": "256x256",
            "type": "image/png"
        },
        {
            "src": "/assets/android-chrome-384x384.png",
            "sizes": "384x384",
            "type": "image/png"
        },
        {
            "src": "/assets/android-chrome-512x512.png",
            "sizes": "512x512",
            "type": "image/png"
        }
    ],
    "start_url": "./index.html",
    "background_color": "#000000",
    "display": "standalone",
    "theme_color": "#20a5d6"
}

Previously, I had a similar issue when setting up OHIF on my old Ubuntu server. It showed a black page, but I don’t recall if the errors in the console were the same. Eventually, I figured the issue was CORS-related and fixed it. I suspect the issue is related to CORS, but I’m not entirely sure.

Current Server Setup

  • Web server: Nginx, RHEL 9, Orthanc: orthancteam/orthanc Docker (mainline), OHIF plugin (mainline). The server has a valid SSL CA certificate.
  • CORS Headers: I’m using the same CORS headers from OHIF and Orthanc documentation & forums. Please see below for the nginx config.

Here’s my OHIF-related config in Orthanc:

"OHIF" : {
"RouterBasename": "/ohif/",
"UserConfiguration" : "/etc/orthanc/ohif.js"
},

And my ohif.js is:

window.config = {
  useSharedArrayBuffer: false,
  extensions: [],
  modes: [],
  whiteLabeling: {
    createStyleComponentFn: function (React) {
      return React.createElement('style', {}, `
        flex {
          display: none!important;
        }
      `);
    },
  },
  Orthanc: {
    Servers: [
      {
        name: 'Orthanc',
        wadoUriRoot: '/orthanc/wado',
        qidoRoot: '/orthanc/dicom-web',
        wadoRoot: '/orthanc/dicom-web',
        qidoSupportsIncludeField: true,
        supportsReject: true,
        imageRendering: 'wadors',
        thumbnailRendering: 'wadors',
        enableStudyLazyLoad: true,
      },
    ],
  },
  cornerstoneExtensionConfig: {
    disableEditing: true,
  },
  ui: {
    showMeasurementTable: false,
    measurementTable: {
      showRelabel: false,
      showDelete: false,
    },
  },
};

Here’s my orthanc.conf file for Nginx:

server {
    listen 443 ssl http2;
    server_name casebank.swmed.edu;

    ssl_certificate /etc/nginx/ssl/ssl.pem;
    ssl_certificate_key /etc/nginx/ssl/ssl.key;

    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout 10m;
    ssl_prefer_server_ciphers on;

       set $cors '';
              if ($http_origin ~ '^https?://(localhost|www\.swmed\.edu|casebank\.swmed\.edu)') {
            set $cors 'true';
               }

    location / {
        if ($cors = 'true') {
        add_header 'Access-Control-Allow-Origin' "$http_origin" always;
        add_header 'Cross-Origin-Opener-Policy' "$http_origin";
        add_header Cross-Origin-Embedder-Policy require-corp;
        add_header 'Access-Control-Allow-Credentials' 'true' always;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
        add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always; 
        proxy_pass http://127.0.0.1:8042/;
        rewrite /orthanc(.*) $1 break;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

What I Tried

  1. Disabling sharedArrayBuffer in both ohif.js and orthanc.json (one at a time).
  • Doing this results in a 502 error instead of the black screen.
  1. These CORS headers:
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' 'https://casebank.swmed.edu' always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
            add_header 'Access-Control-Allow-Credentials' 'true' always;
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;
        }
        add_header Cross-Origin-Embedder-Policy require-corp;
        add_header Cross-Origin-Opener-Policy same-origin;
        proxy_pass http://127.0.0.1:8042/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        add_header 'Access-Control-Allow-Origin' 'https://casebank.swmed.edu' always;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
        add_header 'Access-Control-Allow-Credentials' 'true' always;

I would greatly appreciate any guidance or suggestions to troubleshoot and resolve this issue.
Cheers!

we removed SAB, please pull

Can you check the latest OHIF viewer, which now includes Cornerstone 3D 2.0?

Here are the migration guides:

Try OHIF locally: OHIF Viewer
Try Cornerstone3D 2.0 locally: https://www.cornerstonejs.org/live-examples/local.html

1 Like

Hi Alireza, thank you for your response.
I updated to the latest release of OHIF plugin and the issue is now resolved. However, I am facing another problem.
I have some ultrasound exams that OHIF and Orthanc’s Stone webviewer show normally, but when I crop the images using Sante (to remove patient identifiers), OHIF fails to show the images and I see this error:

On the console, I see this:

app.bundle.6656ed5….js:3192 
 RangeError: Invalid number of values for array setter (origin)
    at publicAPI.<computed> [as setOrigin] (app.bundle.6656ed549…96854f2.js:83064:19)
    at StackViewport.createVTKImageData (app.bundle.6656ed549…896854f2.js:3176:19)
    at StackViewport._createVTKImageData (app.bundle.6656ed549…896854f2.js:3182:36)
    at StackViewport._updateActorToDisplayImageId (app.bundle.6656ed549…896854f2.js:3512:14)
    at StackViewport.successCallback (app.bundle.6656ed549…896854f2.js:3387:14)
    at app.bundle.6656ed549…96854f2.js:22092:27
    at ProgressiveIterator.forEach (app.bundle.6656ed549…96854f2.js:23645:27)
app.bundle.6656ed5….js:21331 
 error in event listener of type:  IMAGE_LOAD_ERROR TypeError: handler is not a function
    at CornerstoneEventTarget.imageLoadFailedHandler (1185.bundle.ec6a7153…4fa339268.js:5835:5)
    at CornerstoneEventTarget.dispatchEvent (app.bundle.6656ed549…96854f2.js:21328:26)
    at triggerEvent (app.bundle.6656ed549…96854f2.js:28214:16)
    at StackViewport.errorCallback (app.bundle.6656ed549…896854f2.js:3402:40)
    at errorCallback (app.bundle.6656ed549…96854f2.js:22071:27)
    at ProgressiveIterator.forEach (app.bundle.6656ed549…96854f2.js:23654:25)
app.bundle.6656ed5….js:21331 
 error in event listener of type:  IMAGE_LOAD_ERROR TypeError: handler is not a function
    at CornerstoneEventTarget.imageLoadFailedHandler (1185.bundle.ec6a7153…4fa339268.js:5835:5)
    at CornerstoneEventTarget.dispatchEvent (app.bundle.6656ed549…96854f2.js:21328:26)
    at triggerEvent (app.bundle.6656ed549…96854f2.js:28214:16)
    at StackViewport.errorCallback (app.bundle.6656ed549…896854f2.js:3402:40)
    at app.bundle.6656ed549…96854f2.js:22106:35
    at <anonymous>

I can load the same images on Stone Webviewer, as well as local versions of OHIF and Cornerstone3D using the links you had kindly provided.

Images are fully anonymized, and I can share them if that would be helpful. I’d appreciate your input.

Hmmm weird, maybe open an issue in OHIF repo, and share anonymized data witih us