diff --git a/lib/cypress/e2e/index.cy.js b/lib/cypress/e2e/index.cy.js index d0c4a227..17758dfe 100644 --- a/lib/cypress/e2e/index.cy.js +++ b/lib/cypress/e2e/index.cy.js @@ -56,7 +56,7 @@ describe("@storyblok/js", () => { describe("Bridge", () => { it("Is loaded by default", () => { - cy.visit("http://localhost:5173/"); + cy.visit("http://localhost:5173/?_storyblok_tk[timestamp]=1677494658"); cy.get(".with-bridge").click(); cy.get("#storyblok-javascript-bridge").should("exist"); }); diff --git a/lib/index.ts b/lib/index.ts index faccddee..1ab276a5 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -70,8 +70,13 @@ export const storyblokInit = (pluginOptions: SbSDKOptions = {}) => { result = { ...result, ...pluginFactory(options) }; }); - // Load bridge - if (bridge !== false) { + /* + ** Load bridge if you are on the Visual Editor + ** For more security: https://www.storyblok.com/faq/how-to-verify-the-preview-query-parameters-of-the-visual-editor + */ + const isServer = typeof window === "undefined"; + const inEditor = !isServer && window.location?.search?.includes('_storyblok_tk'); + if (bridge !== false && inEditor) { loadBridge(bridgeLatest); } diff --git a/playground/index.html b/playground/index.html index 5a64435f..5b629ce0 100644 --- a/playground/index.html +++ b/playground/index.html @@ -7,6 +7,9 @@