I use python 3.9. This is the code I use to activate headless mode:
c = Options()
c.headless = True
TRANSLATE_TO=''
driver = webdriver.Firefox(options=c)
When I run visual studio's debugger or when I click on the .py file it works like normal. When I turn it into an .exe it doesn't and the browser is opened (though the rest of the program runs like normal).
I should note that turning the file into an .exe with pyInstaller doesn't work great. When I try to turn the pyfile into an .exe it raises a recursion error. Then I have to add this line in the beginning of the resulting .spec file:
import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)
Once I do that, I run pyInstaller again for the .specfile and then the .exe is successfully created. (I use the 5.1 pyInstaller)
I don't know if this is relevant but the code using selenium is not from the main file that I turn into an .exe, it's from another file that the main imports and uses.
try this:
for create exe: