小编awo*_*e76的帖子

使用 Puppeteer 访问 React 状态

我正在运行一个 React 应用程序。我想知道是否可以使用 Puppeteer 访问状态值。

例如,在 React 中我有:

const [gridBlocks, setGridBlocks] = useState([])

该值稍后会更新以设置gridBlocks为值数组。

然后,使用 Puppeteer 我有:

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('http://localhost:3000/', {
    waitUntil: 'networkidle2'
  });

  // Can I get access to React and other javascript values now?
  // Something like console.log(await page.evaluate(() => <are React variables available here>));
  // Another way?

await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)

gridBlocks我想循环遍历该状态的值来更新 UI 并抓取每个值的屏幕截图。我不会gridBlocks提前知道这些值是什么,所以我不能只是在我的 Puppeteer 脚本中“硬编码”它们。我真的很喜欢能够从加载的页面中读取它page.goto

我见过的大多数文章都涉及测试并传递props …

javascript reactjs puppeteer

7
推荐指数
1
解决办法
3586
查看次数

Grunt connect和livereload - 配置基本URL

我正在尝试使用grunt connect和livereload来配置基本URL.一切都正常,但我的网址是这样的: http://0.0.0.0:8000/index.html

我希望他们这样: http://0.0.0.0:8000/**newbase**/index.html

我的咕噜声连接:

module.exports = {
    server: {
        options: {
            hostname: '*',
            port: 8000,
            base: './_site'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的咕噜咕噜表:

module.exports = {
  options: {
    livereload: true,
  },
  build: {
    files : [ '*.md', '_layouts/*.html', '_posts/*.markdown', 'css/*.css', 'css/libs/*.css', '_config.yml', 'index.html', '404.html' ],
    tasks: ['shell:jekyllBuild'],
    options: {
      spawn: false,
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

你可以看到我正在使用Jekyll.再次,connect,livereload和Jekyll构建都运行良好.只想使用不同的baseurl(像Jekyll配置允许,用例是在Github中构建项目站点).

谢谢!

javascript connect watch gruntjs livereload

5
推荐指数
0
解决办法
417
查看次数

标签 统计

javascript ×2

connect ×1

gruntjs ×1

livereload ×1

puppeteer ×1

reactjs ×1

watch ×1