node-export-server icon indicating copy to clipboard operation
node-export-server copied to clipboard

Chart Export feature is giving CORS issue suddenly.

Open Neha44hz opened this issue 1 year ago • 13 comments

Expected behaviour

Png, jpg, pdf must download from chart export button

Actual behaviour

Its is giving CORS issue

Live demo with steps to reproduce

Product version

Affected browser(s)

Neha44hz avatar Nov 19 '24 15:11 Neha44hz

@Neha44hz thanks for reporting! Could you please share the exact error message that you're getting in your request/response?

Also, are you just clicking the exporting button on your chart, via the exporting.js module? Or are you sending a custom JSON request?

Please share more details.

jszuminski avatar Nov 20 '24 18:11 jszuminski

Hello, we are having the same issue, we use highcharts in our website and the issue is reported is Download PNG is not working. exact error is:

Access to fetch at 'https://export.highcharts.com/' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

foroozan avatar Nov 21 '24 14:11 foroozan

I am also facing the same issue. please update once resolved or if there is any workaround ?

sharmankita avatar Nov 26 '24 07:11 sharmankita

Our web application is also encountering this issue. We are running Highcharts 11.4.6 and highcharts-vue 2.0.1

It happens when a user clicks on any of the download options in the hamburger menu of a highchart: Screenshot 2024-12-04 at 11 44 16 AM

The following errors are printed to the console locally and on higher environments: Access to fetch at 'https://export.highcharts.com/' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

POST https://export.highcharts.com/ net::ERR_FAILED 403 (Forbidden)

   Uncaught (in promise) TypeError: Failed to fetch
at index-DFJFBoW7.js:8:46109
at Object.post (accessibility-C--XD5AD.js:3:106404)
at ot.U [as exportChart] (accessibility-C--XD5AD.js:3:112682)
at ot.onclick (accessibility-C--XD5AD.js:3:101042)
at HTMLLIElement.onclick (accessibility-C--XD5AD.js:3:111325)`

llabend avatar Dec 04 '24 18:12 llabend

Background

EDIT: Making another reply to my comment with a solution that I discovered this morning.

I am having a similar problem; or at least an extremely similar error message.

I attempted to implement exporting from Highcharts at https://utilities.ericoc.com/ today. However, I am trying to locally host as much as the front-end JavaScript code as possible. I really would like to avoid having to host a Highcharts "export server" as well though?

Example

You can see the error message that occurs when trying to export images from both of my Highcharts charts here:

  • https://utilities.ericoc.com/electric/
  • https://utilities.ericoc.com/water/

NOTE: The "water" database table contains significantly less data, compared to the electric database table. The water data only contains a single row per day, and therefore water loads significantly faster than electric for all testing purposes.

It happens when a user clicks on any of the download options in the hamburger menu of a highchart

As @llabend stated, nothing happens other than I receive the following CORS error message in the JavaScript console when I click any of the "Download" options in the "Export" hamburger menu of a Highchart, like so:

Screenshot

Screenshot 2024-12-14 at 2 49 52 PM

Console Message

water/:1 Access to fetch at 'https://export-svg.highcharts.com/' from origin 'https://utilities.ericoc.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
exporting.js:11
POST https://export-svg.highcharts.com/ net::ERR_FAILED 403 (Forbidden)
    post	@	exporting.js:11
u	@	exporting.js:11
onclick	@	exporting.js:11
onclick	@	exporting.js:11

exporting.js:11

Uncaught (in promise) TypeError: Failed to fetch
at Object.post (exporting.js:11:7132)
at aH.u [as exportChart] (exporting.js:11:12687)
at aH.onclick (exporting.js:11:2079)
at HTMLLIElement.onclick (exporting.js:11:11418)
post	@	exporting.js:11
u	@	exporting.js:11
onclick	@	exporting.js:11
onclick	@	exporting.js:11
exporting.js:11 Fetch failed loading: POST "https://export-svg.highcharts.com/".

Source Code

The source code for this utilities.ericoc.com Django web application is available here:

  • https://github.com/ericoc/utilities
    • My Highcharts instances JavaScript (currently) lives in the Django HTML template files, for example:
      • https://github.com/ericoc/utilities/blob/main/apps/core/templates/base.html
      • https://github.com/ericoc/utilities/blob/main/apps/electric/templates/electric.html
      • https://github.com/ericoc/utilities/blob/main/apps/water/templates/water.html

Data Source (API)

Both of these (electric and water) charts depend upon data gathered via XMLHttpRequest to local Django REST Framework ("DRF") API end-points, which return JSON, and are backed by PostgreSQL:

  • https://utilities.ericoc.com/api/
    • https://utilities.ericoc.com/api/electric/
    • https://utilities.ericoc.com/api/water/

This seems to be working well to gather display the data in the chart (as well as to provide data for a DataTables JavaScript table on the same page).

CDN?

I imagine that if I used the Highcharts CDN (rather than hosting my own JavaScript files), this would probably not occur? I may test this CDN theory at some time in the future, and will try to update here if so.

ericoc avatar Dec 14 '24 19:12 ericoc

Including this additional Highcharts JavaScript library file locally seems to have resolved my issue!

https://code.highcharts.com/modules/offline-exporting.js

as can be seen on any of these pages using Highcharts, where exporting images seems to work okay now:

https://utilities.ericoc.com/electric/ https://utilities.ericoc.com/natural_gas/ https://utilities.ericoc.com/water/

using the following locally hosted/referenced Highcharts JavaScript per:

https://github.com/ericoc/utilities/blob/b7bf0771827ecdb7dbbd08c18194cedf549c1fd3/apps/core/templates/base.html#L26-L30

ericoc avatar Dec 15 '24 15:12 ericoc

Including this additional Highcharts JavaScript library file locally seems to have resolved my issue!

https://code.highcharts.com/modules/offline-exporting.js

as can be seen on any of these pages using Highcharts, where exporting images seems to work okay now:

https://utilities.ericoc.com/electric/ https://utilities.ericoc.com/gas/ https://utilities.ericoc.com/water/

using the following locally hosted/referenced Highcharts JavaScript per:

https://github.com/ericoc/utilities/blob/b7bf0771827ecdb7dbbd08c18194cedf549c1fd3/apps/core/templates/base.html#L26-L30

Yep, this is indeed a working solution. Just tested it. Thanks!

Vitalii-001 avatar Dec 18 '24 05:12 Vitalii-001

@Vitalii-001 awesome - thanks for confirmation! :)

@llabend would you be able to confirm whether you are including the offline-exporting.js JavaScript? If not, I would totally suggest that it might be worth giving it a shot since our error messages were so similar!

ericoc avatar Dec 18 '24 22:12 ericoc

@ericoc Yes! Thank you for your detailed notes & solution, I really appreciate it. After testing locally, I deployed to my DEV environment to test out the changes there and can confirm that including the OfflineExporting module from Highcharts seems to have resolved the issue for our project.

For any Vue 3 users out there, I imported the module within each of our chart components: import OfflineExporting from 'highcharts/modules/offline-exporting';

and then included it with the other Highcharts function calls: OfflineExporting(Highcharts);

Exporting works again. 🥳

llabend avatar Dec 18 '24 22:12 llabend

Thank you everyone in this thread.

Especially @ericoc Thank you so much for the inputs to add offline-exporting.

I added following lines in our common component HIghChartComponent.js

import OfflineExporting from 'highcharts/modules/offline-exporting'; OfflineExporting(Highcharts);

And it worked nicely.

shiddugmail avatar Jan 02 '25 06:01 shiddugmail

"@shiddugmail Could you please confirm which version of Highcharts you are using? I am currently using Highcharts 11.4.0, but it is not working for me."

mujtaba36 avatar Jan 02 '25 07:01 mujtaba36

"@shiddugmail Could you please confirm which version of Highcharts you are using? I am currently using Highcharts 11.4.0, but it is not working for me."

Hi @mujtaba36 following are the versions I am using.

"highcharts": "^11.4.3"
"highcharts-react-official": "^3.2.1"

Hope this helps.

shiddugmail avatar Jan 02 '25 09:01 shiddugmail

Including this additional Highcharts JavaScript library file locally seems to have resolved my issue!

https://code.highcharts.com/modules/offline-exporting.js

as can be seen on any of these pages using Highcharts, where exporting images seems to work okay now:

https://utilities.ericoc.com/electric/ https://utilities.ericoc.com/natural_gas/ https://utilities.ericoc.com/water/

using the following locally hosted/referenced Highcharts JavaScript per:

https://github.com/ericoc/utilities/blob/b7bf0771827ecdb7dbbd08c18194cedf549c1fd3/apps/core/templates/base.html#L26-L30

This worked for me as well, thank you!

joseph-luketelo avatar Jan 22 '25 09:01 joseph-luketelo