Added middleware to inject script tag and capturing of console output