tableau / extensions-api

Extensions API sample code and developer docs.
http://tableau.github.io/extensions-api
MIT License
268 stars 251 forks source link

Extension will not work on Tableau Server and Chrome #336

Closed emanual4real closed 2 years ago

emanual4real commented 4 years ago

I'm receiving the below error on Tableau Server using Chrome:

[Report Only] Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src * blob:".

My extension is hosted on Rancher and works fine on Tableau Desktop. It also works using Edge with Tableau Server. The best I can tell, this is related to Content Security Policy and it does not like me running the Tableau Extensions script.

Code:

/public/tableau.extensions.1.4.0.min.js

/public/index.html <script src="%PUBLIC_URL%/tableau.extensions.1.4.0.min.js"></script> in the head tag

/src/DashboardName.jsx

import React, { useState, useEffect } from 'react';

const { tableau } = window;

export default function DashboardName() {
  const [dashboardName, setDashboardName] = useState('');

  useEffect(() => {
    tableau.extensions.initializeAsync().then(() => {
      const { name } = tableau.extensions.dashboardContent.dashboard;

      setDashboardName(name);
    });
  });

  return (
    <h1>
      {`You have opened ${dashboardName ||
        '____'} Tableau workbook or dashboard`}
    </h1>
  );
}
johnDance commented 4 years ago

Hi, This message is "Report Only" so everything should still run. Do you have any other errors in the console? We are guessing that you are seeing this because of how you are webpacking your code. Perhaps with "eval-source-maps" (or one of the other "eval" options) for devtool. See https://webpack.js.org/configuration/devtool/. Try using a production bundle (with no source maps) or one of the non-eval options. Let us know how it goes. John

bcantoni commented 2 years ago

Closing based on John's latest comment. If this is still an issue, please reopen with comments.