grapesjs
grapesjs copied to clipboard
FEAT: Disable scripts on canvas
Hello, first of all thanks for a great tool.
On my project i hit the problem where I need to disable scripts inside the editor. I found 2 similar issues with this problem - https://github.com/artf/grapesjs/issues/2046 https://github.com/artf/grapesjs/issues/2814. So the problem is quite common and maybe it's better to add such feature to the next version?
In https://github.com/artf/grapesjs/issues/2046 issue @sdrebel mentioned that he's removing scripts in canvas and running them only in preview mode. Can someone prompt how to do it, I didn't find a way how to remove and set js for the template.
Hi @kuhelbeher I'm still trying to achieve that too, but here's a tip that can help us to achieve it. I'll post here if I figure out a way. See this issue #2772
@RJCAM thanks for tip, I tried that, but problem with this approach is that it disables script for component, not the whole template.
Once the editor and its components are loaded it's hard to think about disabling JS, think about a component with custom scripts that binds events all around the DOM (maybe even using some external plugin).
The only way it could be possibly done is to reload the entire Frame (with the current components state), once some configuration flag (eg. via Canvas.enableScripts(false)
) is updated, and prevent their append here.
PRs are welcome :)
In the mean time you can put this in the beginning of your script to disable it in the editor
if (!this) return;
if (this.getAttribute("data-gjs-type")) return;
Since data-gjs-type is not exported when you request the html.