UNPKG

@applitools/eyes-storybook

Version:
26 lines (20 loc) 655 B
'use strict'; const {URL} = require('url'); function getIframeUrl(baseUrl) { const {origin, pathname, search} = new URL(baseUrl); let baseUrlFixed = `${origin}${pathname.replace(/\/[^\/]+\.html/, '')}`; if (!/\/$/.test(baseUrlFixed)) { baseUrlFixed += '/'; } const url = new URL('iframe.html', baseUrlFixed); url.searchParams.set('eyes-storybook', 'true'); if (search) { const origParams = new URLSearchParams(search); for (const [k, v] of origParams) { if (k === 'path') continue; // skip story selection on initial load url.searchParams.set(k, v); } } return url.href; } module.exports = getIframeUrl;