我有下面的代码,如果我放置最大化的导航窗口,它会运行得很好,但是当我最小化它时,它就停止工作了。
更多详细信息:
当窗口最小化时,"scrollDown & scrollTop“函数将停止执行。
'use strict'
const puppeteer = require('puppeteer-core');
const lauchpuppeteer = async () => {
const browser = await puppeteer.launch({
defaultViewport: null,
headless: false,
userDataDir: `${obj.id}`,
args: [`--app=${url}`,
'--disable-background-timer-throttling',
'--disable-backgrounding-occluded-windows',
'--disable-renderer-backgrounding',
'--no-sandbox']
});
const [page] = await browser.pages()
await page.waitForNavigation();
await scrollDown(page);
await page.waitFor(5000);
await scrollTop(page);
if (await page.$('li.inline.t-24.t-black.t-normal.break-words') !== null)
fullname = await page.$eval('li.inline.t-24.t-black.t-normal.break-words', el => el.innerText.replace(/\s+/g, ' ').trim());
else console.log('The Full Name was not found.'.red);
}
const scrollTop = async (page) => {
await page.evaluate(_ => {
window.scrollTo(0, 0);
});
}
const scrollDown = async (page) => {
await page.evaluate(async () => {
await new Promise((resolve, reject) => {
var totalHeight = 0;
var distance = 50;
var timer = setInterval(() => {
var scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if (totalHeight >= scrollHeight) {
clearInterval(timer);
resolve();
}
}, 100);
});
});
}发布于 2022-05-26 06:34:14
这是相当古老和众所周知的错误(参见下面的github票证链接),从2018年!它与普彼特的线程连接。它是,而不是,它连接到最大化或最小化窗口!真正的问题是,如果窗口与木偶师失去了它的焦点。然后窗口是暂停(可能实际上被放入bg (背景)中)。
这个问题一直是众所周知的@github彩票:木偶师不工作时不集中注意力。
解决办法
解决办法的基础是将页面始终放在最前面。
一个必须在代码中实现的示例(来自github票证链接的jtourisNS和弗瑞弗里的学分):
await page.goto('https://web.whatsapp.com/',{
waitUntil: 'networkidle2',
timeout: 30000
});
// other code
// Forcing page always on front
while(true) {
page.bringToFront();
//you need create delay() function by yourself
await delay(1000);
}https://stackoverflow.com/questions/58138275
复制相似问题