To execute code when your form is ready (DOM document) but not shown yet, use this: window.PeggyPay.events.formReadyInternal.push( () => {} ) You should also check if that object is already created by Peggy Pay. Peggy will extend the PeggyPay object if already exists, so: if (typeof window.PeggyPay === "undefined" || !window.PeggyPay) { window.PeggyPay = { events: { formReadyInternal: [] } }; }