Reputation: 2735
When use puppeteer
to scrape a bunch of sites via a for-loop
, whenever a new page is created, the browser would jump to the foreground, which hinders me from doing other things on my computer.
Even I set the following args, it still doesn't work, so how could I keep the browser running quietly without jumping to foreground and interupting me?
I need to run in headful
mode, not headless
mode.
headless: false,
args: [
'--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
'--disable-background-timer-throttling',
'--disable-backgrounding-occluded-windows',
'--disable-renderer-backgrounding',
]
Upvotes: 11
Views: 11310
Reputation: 1
You can use:
headless: true
.
I did this:
const browser = await puppeteer.launch({
headless: true,
executablePath: 'C:/Users/User/Desktop/Chrome-win/chrome.exe'
});
Upvotes: -2
Reputation: 3023
Open Chromium's Info.plist
(you may find it here node_modules/puppeteer/.local-chromium/mac-XXXXXX/chrome-mac/Chromium.app/Contents/Info.plist
) in an editor and add the following piece after the first <dict>
and before <key>
:
<key>LSBackgroundOnly</key>
<string>True</string>
This works on any OS X application.
Source: Keep applications from stealing focus when opening in OS X
Upvotes: 22