I’m trying to fix this issue from a couple days and I’m still not manage it.
My app was rejected, because Shopify App Bridge doesn’t work properly. When I install the app, the browser redirects to the original url of the app (not shopify admin).
The error, which appears in console is:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://shopvote-test.myshopify.com') does not match the recipient window's origin ('https://middleware.shopvote.de').
In my app, I’m using the following script:
As you see I use version 2 of app-bridge, so I encode host with Base64. With version 1 I used shopOrigin property without encoding and the result was the same.
If I change forceRedirec to true, it redirects me to page, which is not founded - https://shopvote-test.myshopify.com/apps/8e54a3332a950a059679711784aa9227/login.
On version 1, it redirects me to the shopify admin page, but in the iframe I have ‘500 Server error’.
When I open the app from Apps in admin dashboard, everything works fine. The issue is only on installing.
I was able to reproduce this error by using an invalid host value and setting forceRedirect to false.
I think we have a couple things going on here:
We don’t recommend handling the host encoding on your own. You should be able to get it from the location on the iFrame. So something like this:
const host = new URLSearchParams(window.location.search).get('host')
We also want forceRedirect to be true so the app can go through the auth process within Admin. We have the option of turning it off for debugging or if you want to insert some additional operations, but then your app would be responsible for redirecting back to the auth flow.
I’m not sure what value this returns…
let host = btoa('{{ Auth::user()->name }}');
… but I suspect, like mentioned in the responses below, that it’s missing /admin at the end. If you get the host from the iframe query params and set forceRedirect to true, things should work!
I was able to get the host value from the params on my end, but perhaps it was because I was landing on Admin. The redirect shouldn’t be taking back to your app domain after the auth process, but to Admin.
I am facing same issue. when I tried your solution I am getting following error.
[email removed] Uncaught TypeError: Failed to construct ‘URL’: Invalid URL
at Object.dispatch [email removed]
at [email removed]
at [email removed]
at P [email removed]
at Object.e.compatibilityCreateApp [email removed]
at u [email removed]
at loadApp?shop=raj-dev-store6.myshopify.com&host=cmFqLWRldi1zdG9yZTYubXlzaG9waWZ5LmNvbS9hZG1pbg:63
If you are a newbie in shopify app development like me, You might encounter this issue as often, Please look in to your cmd for error, and fix that issue, it will be fixed. or try removing or editing your recent changes in the code.