Copy Paste Components
This is our implementation of using localStorage in case someone needs the solution. Clipboard API would have been a great cross browser solution but it's not yet widely used.
Read full answer below ↓Question
Hello Grapesjs Team Ive seen the regular copy paste works as long as is made in the same page, Is it possible implement a a copy paste between 2 different pages with the editor opened
Thanks in advance
Answers (3)
This is our implementation of using localStorage in case someone needs the solution.
function newCopy(selected) {
window.localStorage.setItem('grapesjs_clipboard', JSON.stringify(selected));
}
function newPaste(selected) {
var components = JSON.parse(window.localStorage.getItem('grapesjs_clipboard'));
if (components) {
if (selected && selected.attributes.type !== 'wrapper') {
var index = selected.index();
// Invert the order so last item gets added first and gets pushed down as others get added.
components.reverse();
var currentSelection = selected.collection;
components.forEach(comp => {
// TODO: Add check for validity of paste.
var added = currentSelection.add(comp, {at: index + 1});
editor.trigger('component:paste', added);
});
selected.emitUpdate();
} else {
// No components are selected so just insert at the end.
editor.addComponents(components);
}
}
}
const commands = editor.Commands;
commands.add('core:copy', editor => {
const selected = [...editor.getSelectedAll()];
//Filter out components that are not copyable.
var filteredSelected = selected.filter(item => item.attributes.copyable == true);
if (filteredSelected.length) {
newCopy(filteredSelected);
}
});
commands.add('core:paste', editor => {
const selected = editor.getSelected();
newPaste(selected);
});
Clipboard API would have been a great cross browser solution but it's not yet widely used.
I didn't try it, I just read the code
You don't trigger the paste event when pasting in the body
Also the css is added in a style tag after each paste... There must be a better way to handle the styles, I'll take a look soon
Is it possible implement a a copy paste between 2 different pages with the editor opened
Well, if for 2 different pages you mean 2 different tabs, I don't think so. Obviously, you're dealing with different editor instances so you have to find your way to make them talk with each other (eg. localStorage if you're on the same domain)
Related Questions and Answers
Continue research with similar issue discussions.
Issue #4837
HTML elements ids are incremented on different pages loaded in projectData
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Firefox 109 Reproducible demo link https:/...
Issue #3289
(0.16.41) Components have lost their styles
Version: 0.16.41 Are you able to reproduce the bug from the demo? [X] Yes [ ] No What is the expected behavior? 1) Copy selected parent com...
Issue #1329
Question: How to use same CSS for Multiple pages
Hello Grapejs Team, We've been working on Multi-page Website Builder. For each project there will be multiple html pages with single common...
Issue #6606
Editor takes a long time to load (sometimes over 1 minute)
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Firefox Reproducible demo link https://gra...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Tutorial
GrapesJS vs Webflow vs Tilda (2026): Honest Comparison, Pricing & Which to Pick
GrapesJS vs Webflow vs Tilda compared head-to-head: real 2026 pricing, SEO features, code export, and which one actually fits your project
Tutorial
Preset DevFuture 2.0 — New Update Released
Preset continues evolving as a clean, production-ready starting point for building visual editors powered by GrapesJS
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.