<@U07FJ89LFFB> is it possible to inject changes vi...
# ask-ai
w
@brash-pillow-71627 is it possible to inject changes via JS with growthbook?
o
A message from kapa.ai
Yes, it is possible to inject changes via JavaScript with GrowthBook, but it requires some manual coding work. For instance, you can use feature flags to make changes to the page. Here is an example:
Copy code
javascript <script>   // Wait for the GrowthBook SDK to load before running   window.growthbook_queue = window.growthbook_queue || [];   window.growthbook_queue.push((gb) => {     // Function that uses feature flags to make changes to the page     const applyFeatureFlags = () => {       if(gb.isOn("dark-mode")) {         document.documentElement.classList.add("dark");       } else {         document.documentElement.classList.remove("dark");       }     }        // Call your function initially plus whenever new data is received     applyFeatureFlags();     document.addEventListener("growthbookdata", applyFeatureFlags)   });   </script>
This script waits for the GrowthBook SDK to load before running. It then uses a feature flag to add or remove a class from the document element based on whether the feature is on or off. The function is called initially and whenever new data is received. However, it's important to note that injecting JavaScript through the visual editor or any other way without dev work is currently not supported. It's also mentioned that injecting JavaScript strings as the value of a feature and evaluating it on the client is generally not recommended due to potential security risks [[source](https://linen.growthbook.io/t/8042956/hey-all-i-have-been-exploring-growthbook-for-couple-of-days-)]. For more complex changes, GrowthBook is working on a feature to allow JS and CSS injection via the visual editor, but this feature is not yet available [[source](https://linen.growthbook.io/t/9714304/hiya-i-m-trying-to-get-growthbook-to-send-experiment-data-to)].