Where do I run DevTools code?

I want to get a HAR file using chrome.devtools.network.getHAR(). Specifically, I am using Selenium within a MahiMahi replay shell, and I want to inject JS that will dump the HAR into a file. The standard JS injection (Selenium‘s executeScript method) does not work, because the page’s JS scope does not include DevTools compatibility. With this in mind, I have a series of questions:

  1. Where and how can I use methods like chrome.devtools.network.getHAR()? I have yet to find where I can run this, as the console when I F12 doesn’t have it in scope.
  2. Can I automate this process?
  3. Can I get to this using Selenium specifically, or are there any other browser automation techniques that would work better? (Though I would prefer to avoid PhantomJS because it’s outdated)
  4. Are there any other easier ways to automate getting a HAR file from a site?

NOTE: My code base is in Python

Thank you!

I get an empty file for .har

I was always able to generate a .har file to help devs for troubleshooting issues. But recently I just get an empty file for that!
P.S. I use Chrome.