Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep puppeteer browser running background without jumping to foreground?

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',
            ]
like image 584
avocado Avatar asked Mar 08 '20 11:03

avocado


People also ask

How to take a screenshot with puppeteer?

Let’s start our Puppeteer tutorial with a basic example. We’ll write a script that will cause our headless browser to take a screenshot of a website of our choice. Create a new file in your project directory named screenshot.js and open it in your favorite code editor.

How do I slow down a puppeteer script?

Since this aspect is more architecture-related, I won’t cover this in depth in this Puppeteer tutorial. That said, the most basic way to slow down a Puppeteer script is to add a sleep command to it: This statement will force your script to sleep for five seconds (5000 ms). You can put this anywhere before browser.close ().

What is the use of puppeteer?

Puppeteer lets you automate the testing of your web applications. With it, you can run tests in the browser and then see the results in real-time on your terminal. Puppeteer uses the WebDriver protocol to connect with the browser and simulate user interaction with HTML elements or pages. What is Node.js?

Is puppeteer the new Headless chrome?

But today we’ll be exploring headless Chrome via Puppeteer, as it’s a relatively newer player, released at the start of 2018. Editor’s note: It’s worth mentioning Intoli’s Remote Browser, another new player, but that will have to be a subject for another article. What exactly is Puppeteer?


1 Answers

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

like image 64
mbit Avatar answered Oct 20 '22 15:10

mbit