If any <a>, <s-link>, <s-button> or <s-clickable> in an embedded app’s page has an href that new URL(href, location.href) can’t parse, clicking the app’s nav items in the admin sidebar stops working. The sidebar highlights the new item, but the app iframe stays on the current page. Reloading shows the right page.
The link doesn’t have to be in the nav menu. For us it was a message in a third-party chat widget (Crisp), which autolinked support text into href="http://**Domain:**``example.com/``". Apps don’t control what chat widgets, reviews or merchant content put in the page, so one bad link from anyone breaks the app’s admin navigation.
Steps to reproduce
-
Use any embedded app that loads
https://cdn.shopify.com/shopifycloud/app-bridge.jsand has a nav menu (<ui-nav-menu>or<s-app-nav>) with at least two links. -
Anywhere in the page, add a link whose href doesn’t parse, for example:
<a href="https://">broken</a>(
http://**Domain:**``example.com/,https://my shop.comandhttp://example.com:abcbehave the same.) -
Open the app in the admin and click another of the app’s items in the admin sidebar.
Expected: the app navigates to that page.
Actual: the sidebar moves to the new item, the app stays on the old page, and the console shows:
Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid URL
at on (https://cdn.shopify.com/shopifycloud/app-bridge.js:1:17737)
at https://cdn.shopify.com/shopifycloud/app-bridge.js:1:18345
at Array.filter (<anonymous>)
at an (https://cdn.shopify.com/shopifycloud/app-bridge.js:1:18221)
at r (https://cdn.shopify.com/shopifycloud/app-bridge.js:1:19696)
at async Promise.all (index 0)
at async ut.dispatchEvent (https://cdn.shopify.com/shopifycloud/app-bridge.js:1:10368)
at async MessagePort.d (https://cdn.shopify.com/shopifycloud/app-bridge.js:1:90209)
Cause
In the navigate handler, the lookup for the link to click (an in the minified build) collects every a, s-link, s-button and s-clickable in the document, not only the nav menu’s. It runs each href through the URL normaliser (on), which calls new URL(href, location.href) with no try/catch. The first href that doesn’t parse throws, the async handler rejects, and navigation is abandoned.
The same file already guards this elsewhere: the helper that reads nav menu hrefs ($n) wraps the same normaliser in try { … } catch {}.
Suggested fix
In the link lookup, skip elements whose href doesn’t parse (the same try/catch as $n), or only look at the nav menu’s links.
Check whether a page is affected
Run this in the console with the app’s iframe selected as the context:
[...document.querySelectorAll('a, s-link, s-button, s-clickable')]
.filter((el) => { const h = el.getAttribute('href'); if (!h) return false; try { new URL(h, location.href); return false; } catch { return true; } })
.map((el) => ({ tag: el.tagName, href: el.getAttribute('href'), el }))
Related: these errors never reach error trackers
app-bridge.js is loaded without a crossorigin attribute, so browsers don’t fire unhandledrejection for its errors. They appear in the console but never error reporting tools, which is why this took us a while to find. The CDN already sends Access-Control-Allow-Origin: *. Is loading it with crossorigin="anonymous" supported?