小编pra*_*rma的帖子

如何让 jsdom 等待 html 页面的完全渲染..?

我正在使用 jsdom 从服务器加载一个 html 页面,使用 nodejs 来获取一些谷歌图表图形 URL。但问题是我只能获取部分加载的图形 URL。如何让 jsdom 等到完整的图形呈现出来,然后在 console.log 中记录 URL。

下面是我的 JSDOM 代码:

 router.post('/Endpoint',(req,res,next)=>{
 // the file I will be loading
 uri = 'one.html',

 // the options that I will be giving to jsdom
 options = {
   runScripts: 'dangerously',
   resources: "usable"
 };

 // load from an external file
jsdom.fromFile(uri, options).then(function (dom) {

let window = (new jsdom(``, {  pretendToBeVisual: true })).window;

window.requestAnimationFrame(timestamp => {
    console.log(timestamp > 0);
  });
}).catch (function (e) {
   console.log(e);
});
Run Code Online (Sandbox Code Playgroud)

});//EOF API …

javascript google-visualization node.js jsdom

6
推荐指数
0
解决办法
489
查看次数

标签 统计

google-visualization ×1

javascript ×1

jsdom ×1

node.js ×1