How to use a inject button inside of a chrome extension to inject code into the current tab?

I’ve tried a lot of resources to fix my issue, but everything I’ve found is about instantly injecting the code once the user has entered the site; not when a button is pressed to inject the code.

I tried videos, posts and research – nothing worked. I was expecting for my inject button to run the code entered into a textbox e.g. ‘console.log(‘demo’);’.