witty-carpet-85180
04/29/2025, 2:12 PMwindow
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?strong-mouse-55694
04/29/2025, 2:54 PMdestroy
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?witty-carpet-85180
04/29/2025, 3:05 PMexport 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>
}
strong-mouse-55694
04/29/2025, 3:28 PMwindow._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.witty-carpet-85180
04/30/2025, 6:58 AMstrong-mouse-55694
04/30/2025, 2:05 PM