【发布时间】:2019-06-06 16:10:30
【问题描述】:
我正在使用带有 wraith(https://github.com/BBC-News/wraith) 的 headless chrome 浏览器。 问题是我的页面打开 alert wraith 失败
ERROR: unexpected alert open: {Alert text : Bla bla bla.}
(Session info: headless chrome=71.0.3578.98)
(Driver info: chromedriver=71.0.3578.33 (269aa0e3f0db08097f0fe231c7e6be200b6939f7),platform=Mac OS X 10.13.6 x86_64)
这是我尝试过的,但到目前为止失败了:
const BACKEND_USERNAME = "";
const BACKEND_PASSWORD = "";
function resizeIFrameToFitContent(iFrame) {
iFrame.width = iFrame.contentWindow.document.body.scrollWidth;
iFrame.height = iFrame.contentWindow.document.body.scrollHeight;
}
var original_url_asked = document.referrer;
if (typeof jQuery !== 'undefined') {//maybe 500 or 404 page
$(document).ready(function () {
//we ended up on login page, let's login
$('body > div:nth-child(23) > div.backend_right_content > div > div > form > input[type="password"]:nth-child(3)').prop('value', BACKEND_PASSWORD);
$('body > div:nth-child(23) > div.backend_right_content > div > div > form > input[type="text"]:nth-child(1)').prop('value', BACKEND_USERNAME);
$('body > div:nth-child(23) > div.backend_right_content > div > div > form > input[type="submit"]:nth-child(5)').click();//submit form
//we are logged in
$('body').empty();//clear all the stuff
//since we can't redirect, we'll open a full page iframe with the url we wanted to see initially
$('body').append('<iframe id="ifr" width="100%" height="100%" frameborder="0" src="" ></iframe>');
//load the original_url finally
$("#ifr").attr("src", original_url_asked);//cannot redirect or wraith complains
//hide the menu and other elements, for smaller screenshots
$('#ifr').on('load', function () {
$('#ifr').contents().find('div.backend_left, div.backend_right_top').remove();
resizeIFrameToFitContent(document.getElementById('ifr'));
});
});
}
//important or wraith will not understand it is ready to take a screenshot
var callback = arguments[arguments.length - 1];
setTimeout(callback, 20000);//wait for page to load
【问题讨论】:
-
到目前为止失败是什么意思?有什么错误吗?
-
@TomM 好吧,我想他仍然有 wraith 产生的相同错误,因此他的尝试失败了...... :-)
-
@IslamElshobokshy 是的,这是有道理的。
-
在设置 'src' 属性之前,您是否尝试设置
iframe.contentWindow.alert和iframe.contentWindow.prototype.alert? -
你确定它是
alert而不是confirm?
标签: javascript html google-chrome iframe overriding