相关疑难解决方法(0)

木偶| 等待所有JavaScript执行

我尝试从多个页面中截取屏幕截图,这些页面应完全加载(包括延迟加载的图像),以便以后进行比较。

我发现了lazyimages_without_scroll_events.js示例,该示例很有帮助

使用以下代码,屏幕快照看起来不错,但是存在一些主要问题。

async function takeScreenshot(browser, viewport, route) {
  return browser.newPage().then(async (page) => {
    const fileName = `${viewport.directory}/${getFilename(route)}`;

    await page.setViewport({
      width: viewport.width,
      height: 500,
    });
    await page.goto(
        `${config.server.master}${route}.html`,
        {
          waitUntil: 'networkidle0',
        }
    );
    await page.evaluate(() => {
      /* global document,requestAnimationFrame */
      let lastScrollTop = document.scrollingElement.scrollTop;

      // Scroll to bottom of page until we can't scroll anymore.
      const scroll = () => {
        document.scrollingElement.scrollTop += 100;
        if (document.scrollingElement.scrollTop !== lastScrollTop) {
          lastScrollTop = document.scrollingElement.scrollTop;
          requestAnimationFrame(scroll);
        }
      }; …
Run Code Online (Sandbox Code Playgroud)

javascript testing google-chrome node.js puppeteer

8
推荐指数
1
解决办法
4452
查看次数

标签 统计

google-chrome ×1

javascript ×1

node.js ×1

puppeteer ×1

testing ×1