function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohammad Zakir HossainMohammad Zakir Hossain 

Visual force / JavaScript error: Access to image has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I am facing CORS error when accessing image by javascript from visualforce page.
I have already tried adding to CORS whitelisting and remote settings too ..

If I use external image link it works but what ever image use from salesforce content version it shows such error even I tried with sfdc cv public image ContentDownloadUrl.

my use case is exporting image as pdf by html2pdf library .

 
Access to image at 'https://...content.force.com/sfc/dist/version/download/?oid=...&asPdf=false' from origin 'https://....visual.force.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

 
SwethaSwetha (Salesforce Developers) 
HI Mohammad,
Try adding the image as a static resource in your code for fixing the CORS error.

Related:
https://salesforce.stackexchange.com/questions/140693/static-resource-blocked-from-loading-by-cross-origin-policy
https://help.salesforce.com/articleView?id=sf.pages_static_resources.htm&type=5
https://salesforce.stackexchange.com/questions/140693/static-resource-blocked-from-loading-by-cross-origin-policy

If this information helps, please mark the answer as best. Thank you
Mohammad Zakir HossainMohammad Zakir Hossain
No , images should be from content version of related objects.