gpt4 book ai didi

selenium - headless 谷歌浏览器 : How to prevent sites to know whether their window is focused or not

转载 作者:行者123 更新时间:2023-12-04 00:02:17 24 4
gpt4 key购买 nike

有没有办法阻止网站知道它们是否可见?

也许是命令行标志?我在这里查过,但找不到合适的https://peter.sh/experiments/chromium-command-line-switches/ .

我认为他们使用页面可见性 API:https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API

最佳答案

如果您的目标是欺骗可见性 API,则将这段脚本注入(inject)相关页面或框架中:

await page.evaluate(`
Object.defineProperty(window.document,'hidden',{get:function(){return false;},configurable:true});
Object.defineProperty(window.document,'visibilityState',{get:function(){return 'visible';},configurable:true});
window.document.dispatchEvent(new Event('visibilitychange'));
`);

它首先覆盖 window.hidden让它返回 false .然后,它触发 visibilitychange在页面已经隐藏的情况下通知文档的事件。

或者在创建文档后立即覆盖 API:

await page.evaluateOnNewDocument(`
Object.defineProperty(window.document,'hidden',{get:function(){return false;},configurable:true});
Object.defineProperty(window.document,'visibilityState',{get:function(){return 'visible';},configurable:true});
`);

关于selenium - headless 谷歌浏览器 : How to prevent sites to know whether their window is focused or not,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58772369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com