puppeteer: Make open new tab/pages doesn't switch active window

Steps to reproduce

When I create a new page it will change my active window to my new tab. Which is I don’t like it because it will disturb me to type in another application. Actually, I solved the problem by set headless mode to true. But, that’s not what I like to do because I don’t see the activity from my browser.

Tell us about your environment:

  • Puppeteer version: 0.12-alpha
  • Platform / OS version: Ubuntu 16.04
  • URLs (if applicable):

What steps will reproduce the problem?

Please include code that reproduces the issue.

What is the expected result? When Puppeteer launches new tab it wouldn’t change my window active, so I can still continue typing in another application.

What happens instead? When Puppeteer creates and launch new tab it’s changed my active window to my new tab, so I can’t type to my another app. If I want to type to my another app I should switch window into it.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 7
  • Comments: 15 (7 by maintainers)

Most upvoted comments

For those coming here looking for a remedy on macOS, there is actually a way to achieve this by modifying node_modules/puppeteer/.local-chromium/mac-******/chrome-mac/Chromium.app/Contents/Info.plist and adding this to the beginning:

<key>LSBackgroundOnly</key>
<string>True</string>

So that the file starts like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>LSBackgroundOnly</key>
  <string>True</string>
  <key>BuildMachineOSBuild</key>

For more info: https://www.cnet.com/news/keep-applications-from-stealing-focus-when-opening-in-os-x/

The above solution from @leadscloud does not seem to work anymore.

@lehni: The window doesn’t open for me as well. Looks like it’s run in headless mode.

@lopugit it is not. You still see the window, it just doesn’t steal input focus, so you can keep typing while your system runs e2e tests, for example, but you can keep having an eye on them too.

@aslushnikov have you tried this yourself?

When I’m coding, I write code with scraping and then run it on a separate screen.

While that’s running with headless:false, it grabs the keyboard focus each time a new tab is opened, automatically.

I can’t write new code or do anything else while monitoring the script in another screen.