Error "Refused to execute script from 'https://example.com' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled."

Error "Refused to execute script from 'https://example.com' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled."

book

Article ID: KB0080680

calendar_today

Updated On:

Products Versions
Spotfire Web Player 7.5 and higher

Description

When loading custom visuals in Web Player, it may throw the following error when viewed from Web Player.

"Refused to execute script from 'https://example.com' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled."

The same may be reproduced against the SDK example CustomVisualsExample.CustomDonutChart. This is expected to be fixed in SDK version 7.10
 

Issue/Introduction

Custom visuals may show up as blank in Web Player when loaded in Web Player.

Resolution

In order to survive the mime type check we need to declare the correct mime type, and have an API method for that on CustomVisualView<T> called ResolveContentType as is documented here:

https://docs.tibco.com/pub/doc_remote/sfire_dev/area/doc/api/TIB_sfire-analyst_api/html/M_Spotfire_Dxp_Application_Extension_CustomVisualView_1_ResolveContentType.htm

With respect to the SDK example CustomVisualsExample.CustomDonutChart, the problem is in the override for GetResourceCore in CustomDonutChartView.cs. Code in the API example follows.
=======================================================================
        protected override HttpContent GetResourceCore(string path, NameValueCollection query, CustomDonutChart snapshotNode)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = "CustomDonutChart.html";
            }
 
            var bytes = GetEmbeddedResource("SpotfireDeveloper.CustomVisualsExample.webroot." + path);
 
            return new HttpContent("text/html", bytes);
        }
=======================================================================

It needs to be modified to :
=======================================================================
        protected override HttpContent GetResourceCore(string path, NameValueCollection query, CustomDonutChart snapshotNode)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = "CustomDonutChart.html";
            }
 
            var bytes = GetEmbeddedResource("SpotfireDeveloper.CustomVisualsExample.webroot." + path);
            var mimeType = ResolveContentType("SpotfireDeveloper.CustomVisualsExample.webroot." + path);
 
            return new HttpContent(mimeType, bytes);
        }
=======================================================================

Additional Information

https://docs.tibco.com/pub/doc_remote/sfire_dev/area/doc/api/TIB_sfire-analyst_api/html/M_Spotfire_Dxp_Application_Extension_CustomVisualView_1_ResolveContentType.htm