【发布时间】:2016-01-12 11:38:37
【问题描述】:
我使用 node 编写了一个 phantomjs 脚本来截取网页的屏幕截图。我要截屏的页面包括一个重要的外部脚本,它向全局窗口对象添加变量。 IE。窗口.__组件。
问题是,这永远不会设置。它在浏览器中运行良好,但在 phantomJS 中就消失了。我已更改脚本以在打开页面之前注入脚本,我添加了一项检查以确保在打开页面之前已添加组件对象并且仍然失败。
有什么想法吗?
function injectExternalScripts(page, ph, url) {
page.includeJs('http://external-script', ()=>{
page.evaluate(() => {
return window;
}, function(result) {
if(result.__components) {
openPage(page, ph, url);
}
});
});
}
function openPage(page, ph, url) {
page.open(url, (status)=>{
// errors returned from page
// window.__components is null
});
}
【问题讨论】:
标签: javascript node.js phantomjs screenshot