So I have an embedded app that loads app-bridge using plain JS(No NPM or Node used). I’m aware this is not the recommended way, but we’re stuck with this and it should work still.
I can load app-bridge, and create an app. the app-bridge objects contain the relevant structures. There are no errors or console warnings at all. But whenever I try to call an app-bridge function I get no response, or nothing happens. Something is wrong with the link to app-bridge, but I cannot figure out what it is.
I’m loading the packages using unpkg :
<script src="https://unpkg.com/@shopify/app-bridge"></script>
<script src="https://unpkg.com/@shopify/app-bridge-utils"></script>
And then creating my app :
const shopifyApp = window[“app-bridge”];
let createApp = shopifyApp.default;
const app = createApp({
apiKey: “XXXX”,
host: “XXXX”
});
If I log the app variable it shows correctly :
console.log(“App Bridge Initialized:”, app);
Then I try to call a simple Toast command to test :
const toast = Toast.create(app, {
message: “App Bridge is working!”,
duration: 5000,
});
toast.dispatch(Toast.Action.SHOW);
No toast appears on the screen. There are no console errors in the browser, and no network errors.
I also try to call getSessionToken, but this eventually causes a timeout :
(async function () {
console.log(“Session token verification started.”);
const token = await getSessionToken(app);
console.log(“Session token loaded”);
})();
I’m a bit at a loss for what to test next?