3

UPDATED WITH REASONING

Goal: Run chrome web driver in background without showing an app icon in the dock or application bar. FYI: I can already run chrome headless, but I have not been able to hide or not show the chrome icon in my app bar.

Reason: I am building an application that accesses various websites in parallel and I would not like the chrome app icons to display for the synchronous tasks that are taking place. I want to run these tasks in the background.

Current Code with chrome options that will display headless chrome

chrome_options = Options()
chrome_options.add_argument('headless')
chrome_options.add_argument('window-size=1200x600')
driver = webdriver.Chrome(executable_path=executable_text, chrome_options=chrome_options)

Research

list of chrome options: https://peter.sh/experiments/chromium-command-line-switches/

one of many posts explaining how to do headless chrome: Selenium - chrome Driver fail to start in background (without a start-up window)

How can I hide the chromedriver app icons from displaying? Is there a chrome option I can set in addition to setting the 'headless' chrome option? Is this more of an OS setting that needs to be made to run chromedriver in the background? I am successfully able to run multiple chromedrivers in headless mode but it would be nice to NOT show the chrome icons in the dock or application tray similar to how phantomjs does not launch an app icon.

enter image description here

^In the image above those are the chromedrivers that run in headless mode displaying in my dock and ideally for my program I would not even want to display those icons since it is all background processing anyways.

Krusaderjake
  • 479
  • 1
  • 7
  • 19

2 Answers2

3

Update (this worked for me to hide the chromedriver icons at least on my Mac):

I was not able to find a Chrome Option to accomplish hiding the chromedriver icons that appear in the dock. However, I was able to edit the Info.plist file for Chrome as part of my program to do the trick (of hiding chromedriver icons) using the LSBackgroundOnly key.

In the Info.plist for Chrome, programmatically, I entered:

<key>LSBackgroundOnly</key>
<string>1</string>

On my Mac using python3 code I used os.system to execute a terminal command using defaults to enter the LSBackgroundOnly key when the program is executing and then at the end of program execution I delete the LSBackgroundOnly key from the Info.plist.

like this:

1)

defaults write /Applications/Google\ Chrome.app/Contents/Info.plist LSBackgroundOnly -string '1'

2)

defaults delete /Applications/Google\ Chrome.app/Contents/Info.plist LSBackgroundOnly

AS INFO: This is tricky because your normal chrome app may start up in background mode if you don't add/delete LSBackgroundOnly properly during program execution. In my experience, worst case scenario you may have to manually remove LSBackgroundOnly from the Info.plist file then restart your computer to get Chrome out of background mode.

I remove the LSBackgroundOnly key from the Info.plist file in my program after program execution because the key only needs to be in the file when the chromedrivers are launched. After that I want to be able to use regular Chrome app without issues of it opening in background mode. But, if you understand your program execution and handle your exceptions, this will definitely work to hide the icons correctly and there will be nothing different in using your regular Chrome app.

Happy hacking.

Krusaderjake
  • 479
  • 1
  • 7
  • 19
0

This is not possible using Selenium. I don't really understand why you want to do this. Is there a real purpose, or it's just you don't want it to show? Even if the Chrome app shows on the dock, in headless mode, it works pretty good.

However, if you want your icon to not appear in the dock when opened, then you need to disable it by modifying the Info.plist file for that application.

In your Info.plist for Chrome, add this

 <key>LSUIElement</key>
 <true/>

This will prevent your app icon from appearing in dock, when working. I found this out a long time ago and this is the post where I saw it.

PS - I have not tested it for Chrome app. Please test at your own peril.

demouser123
  • 4,108
  • 9
  • 50
  • 82
  • I updated the description with reasoning. Essentially, I want to run the tasks that are being performed in the background. There is no point to showing chrome apps being opened since I show a progress bar of the tasks in the app I am building. – Krusaderjake Jul 21 '17 at 20:24
  • Unfortunately adding those tags in the Info.plist doesn't seem to work for Chrome/running the chromedriver. It successfully does not open the app icons but the background processing does not take place. – Krusaderjake Jul 21 '17 at 20:29