Grapesjs-custom-code doesn't execute <script> from GrapesJS 0.16.30 and up
hi very thanks for u r replay... yes exactly , after you are replay i tried with 0.16.27 custom blocks script is working as expected but in above versions than 0.16.27 while drag and drop custom block script executing as expected but after saving and reloading the template using editor.setComponents(html text as Strin...
Read full answer below ↓Question
grapesjs-custom-code work fine with script tag until GrapesJS 0.16.27, after this version, no script content is executed.
✔️ Editor init() option : allowScripts: 1
✔️ Plugin import : https://github.com/artf/grapesjs-custom-code/issues/11#issuecomment-724512902
Is it related to https://github.com/artf/grapesjs/issues/3244 ?
Answers (3)
hi very thanks for u r replay... yes exactly , after you are replay i tried with 0.16.27 custom blocks script is working as expected but in above versions than 0.16.27 while drag and drop custom block script executing as expected but after saving and reloading the template using editor.setComponents(html text as String ); html coming properly but script is not working. i absorbed that in script in place of ' < > like this type of symbols are replacing with browser understanding codes so i tried to deploy that html in browser its working fine but script not working locally while reloading saved template. kindly if any one have the solution for this in latest version help me to get out of this
Thanks
Hi @bgrand-ch probably you're talking about a fixed bug 😂 Main reasons why you should not let execute a random script from a user:
- Self-XSS
- We can't control the script if we execute it inside the editor, so, for instance, the user paste this
<script>document.body.innerHTML = "";</script>and the editor is broken.
Actually, there is an option that kind of indicates that is by design
placeholderScript | Content to show when the custom code contains <script>
Thanks for reporting this, @bgrand-ch.
Great suggestion about grapesjs-custom-code doesn't execute <script> from GrapesJS 0.16.30 and up! While this specific feature isn't yet in the core API, there are several ways to achieve similar behavior.
Using the event system:
editor.on('component:update', (component) => {
// your logic here
});
Alternative approaches:
- Listen to
selector:addfor CSS selector changes - Use
selector:customfor custom rules - Tap into the
change:*events for fine-grained tracking - Build a plugin that extends the editor with this capability
Making it official: If this feature would benefit many users, consider opening a formal Feature Request on the GrapesJS repo with:
- A detailed use case
- Code example showing the desired behavior
- Why this matters for your workflow
The core team is receptive to well-motivated feature requests backed by real use cases.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3558
FEAT: Support Content-Security-Policy
To reduce the possible attack surface if the editor is used in "hostile" environments (e.g. in SaaS platforms) support for CSP is required....
Issue #3668
Cant Reset Canvas after Moving/scaling it
WARNING READ and FOLLOW next 3 steps, then REMOVE them before posting the issueFollow CONTRIBUTING Guidelines https://github.com/artf/grape...
Issue #3313
There are lots of click required to make text editable, can we make text field editable on a single Click.
WARNING READ and FOLLOW next 3 steps, then REMOVE them before posting the issueFollow CONTRIBUTING Guidelines https://github.com/artf/grape...
Issue #3405
FEAT: An event to hook into before a block in dropped into the canvas
WARNING READ and FOLLOW next 3 steps, then REMOVE them before posting the issueFollow CONTRIBUTING Guidelines https://github.com/artf/grape...
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
Super Tooltip for GrapesJS — Version 0.1.5 Released 🎉
We’re excited to announce the v 0.1.5 update of Super Tooltip, our floating‑menu and tooltip plugin for GrapesJS
Tutorial
GrapesJS in 2026: The Complete Guide to the Open-Source Web Builder Framework
Master GrapesJS in 2026. Architecture, code examples, React integration, plugin development, Studio SDK, and how it compares to other projects
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.