Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
From one day to another We've receiving this CORS policy error.
We've not made any recent changes to our store, but it appears the theme's code is fetching urls with the "myshopify.com" domain instead of our default domain.
Is there any way we can achieve to use entirely our default domain?
this is an example:
Access to XMLHttpRequest at 'https://mydomainname.myshopify.com/search?view=ajax-article-page&type=article,page&q=salmon*' from origin 'https://mydomainname.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Solved! Go to the solution
This is an accepted solution.
@tim Helped us a lot to find the cause of the problem, it was not the theme's code.
After viewing the homepage tags he identified the document.baseURI was mydomainname.myshopify.com
Later we found out that when creating a blog post the same way as usual (we don't know why), in the Excerpt of the post, an html tag was added
so this base tag changed all our homepage baseURI to the shopify domain generating the CORS error.
Thanks again to @tim for helping us to solve this issue that seemed to be imposible
Of course, but it would be necessary to see your store and the code which generates the message to suggest anything.
The issue is in several js calls to cart.js, search and other pages within the theme.
I've found That routes.search_URL is getting myshopify.com domain instead of my default domain.
As I've been reading there is no way to change that on the theme settings
Hope you can help me, thanks in advance
That's suspicious -- routes use relative paths and do not include domain name.
Must be something in your theme code, most probably in layouts/theme.liquid where all these variables are defined for JS use.
If you afraid of sharing your store URL, you can DM it to me.
This is an accepted solution.
@tim Helped us a lot to find the cause of the problem, it was not the theme's code.
After viewing the homepage tags he identified the document.baseURI was mydomainname.myshopify.com
Later we found out that when creating a blog post the same way as usual (we don't know why), in the Excerpt of the post, an html tag was added
so this base tag changed all our homepage baseURI to the shopify domain generating the CORS error.
Thanks again to @tim for helping us to solve this issue that seemed to be imposible
Hi, I'm having the same issue with CORs errors, seemingly all of a sudden, across several pages. I found your post and the cause appears to be the same, as I can see the wrong URL being entered with a <base href...> tag on my pages that point to the mydomain.myshopify.com instead of mydomain. The part I'm not understanding is the resolution, as I can't find where this value is being set. Can you possibly share more details as to how you resolved the issue? Thanks a lot.
In our scenario, the <base... tag was inserted when a blog post was created.
On the blog post creation There's an "Excerpt" section that allows you to see the code when clicking the "</>"button.
there we found certain blog posts with the myshopify url instead the domain name.
You can open your browser web tools and find the url to see in which part of the code it is inserted so you could look for it in a mor targeted way
Found it, thanks. Not sure how it happened, but for others it appears that a page being updated inserted the base href tag (down at the bottom where the edits were made, only visible when viewing the source obviously). Not sure why that was added given similar/earlier edits didn't add an href tag, but that was definitely the cause and removing it resolved the issue. Thanks again.
Share your store URL
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024