We're currently using a Cloudflare proxy that inje...
# ask-questions
w
We're currently using a Cloudflare proxy that injects GrowthBook onto the
window
object. After the page loads, we create a React instance of GrowthBook using the payload and attributes from the
window
instance. However, our CRO specialist wants the
window
instance removed. I attempted to destroy it using
_growthbook.destroy()
, but it throws an error:
Cannot delete property '_growthbook'
. An alternative would be to inject the payload and attributes directly within the proxy, bypassing the
window
object. However, I'm unsure whether redirect tests would still run as quickly as they currently do. Do you have any recommendations / best practices / docs for this scenario?
s
You're right that can't call
destroy
here. Are you able to share a bit more why you're approaching it this way (injection)? And, are you using our Edge app or is the proxy injection something that's being done independently?
w
Currently we using the Edge App and we are re-using the injected Growthbook instance from the window like below. Furtermore we don't o anything with the window instance.
Copy code
export function GrowthBookProvider({ children }: PropsWithChildren) {
    const gb = useMemo(() => new GrowthBook(), [])
    useEffectOnce(() => {
        // Ensure we are in the browser and the instance has been injected
        if (typeof window !== 'undefined' && window._growthbook) {
            const payload = window._growthbook.getPayload()
            const attributes = window._growthbook.getAttributes()
            gb.initSync({
                payload,
            })
            gb.setAttributes(attributes)
            
        } else {
            console.warn('Unable to find GrowthBook. Please check if the proxy app is running.')
        }
    }, [])
    return <ReactGrowthBookProvider growthbook={gb}>{children}</ReactGrowthBookProvider>
}
s
Thanks for the follow up. So, it's possible to disable the
window._growthbook
by disabling injection_. See_
DISABLE_INJECTIONS
in the docs: https://docs.growthbook.io/lib/edge/cloudflare Then, you could modify your Cloudflare Worker to pass the necessary payload/attributes for consumption in React.
w
Thanks — that was indeed our backup plan. We'll just need to check how the redirects behave with this setup. Appreciate it, and we really like using GrowthBook!
s
Awesome to hear. Let us know if have more questions about the Cloudflare setup!
🙌 1