grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

FEAT: Disable scripts on canvas

Open kuhelbeher opened this issue 4 years ago • 3 comments

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.

kuhelbeher avatar Aug 25 '20 08:08 kuhelbeher

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 avatar Aug 25 '20 13:08 RJCAM

@RJCAM thanks for tip, I tried that, but problem with this approach is that it disables script for component, not the whole template.

kuhelbeher avatar Aug 26 '20 06:08 kuhelbeher

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 :)

artf avatar Aug 28 '20 00:08 artf

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.

djgamerr avatar Nov 16 '22 23:11 djgamerr