@storyblok/preview-bridge
@storyblok/preview-bridge enables real-time preview of an iframe-embedded website within the Visual Editor.
Requirements
Section titled “Requirements”StoryblokBridge can only run in a browser environment.
- Modern web browser (latest versions of Chrome, Firefox, Safari, Edge, etc.)
Installation
Section titled “Installation”To add the package to a project, run this command in the terminal:
npm install @storyblok/preview-bridge@latestAccess StoryblokBridge in the global scope, either directly or as a property of window:
<body> <script> const storyblokBridge = new StoryblokBridge(); </script></body>Following is a minimal implementation of the StoryblokBridge class. This webpage loads within the editor’s iframe and logs the story’s unsaved state each time the input in the Visual Editor changes.
<!doctype html><html lang="en-US"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> </head> <body> <script> const storyblokBridge = new StoryblokBridge();
storyblokBridge.on("input", ({ story }) => { console.log(story); }); </script> </body></html>