Headless Google Chrome: How to prevent sites to know whether their window is focused or not
问题 Is there a way to prevent sites to know if they are visible or not? Perhaps a command line flag? I checked here but I could not find anything suitable https://peter.sh/experiments/chromium-command-line-switches/. I think they use the page visibility API: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API 回答1: If your goal is to fool the visibility API, then inject this piece of script in the related page or frame: await page.evaluate(` Object.defineProperty(window.document,