HtmlUnit 在 window.open 之后停止 JavaScript 执行

发布于 2024-09-16 00:37:36 字数 574 浏览 3 评论 0原文

我最近从 HTMLUnit 2.4 更新到 2.5(我们会选择最新版本,但由于已弃用的 API,有很多代码需要重构)。我现在遇到一些打开窗口的 JavaScript 问题。

正在测试的页面是报告的“加载屏幕时请稍候”。该页面打开一个新窗口,然后重定向回最初启动打印的页面。

所以 JavaScript 看起来像这样:

window.open(url,'report_window');
document.location.href  = original_url;

使用 HtmlUnit 2.4,脚本将继续执行,如果我抓取原始 Window 对象,它将执行重定向。但是,升级到 HtmlUnit 2.5 后,原始窗口仍然位于“请稍候”页面上 - 重定向从未执行。看起来好像 JavaScript 在调用 window.open 之后停止执行。

如果我手动测试,我已经确认页面行为正确。我还在 window.open 调用之后尝试了不同的 JavaScript,以确认该特定调用不是问题。

有人知道这样的问题以及任何潜在的解决方法吗?由于 jQuery 兼容性,我们必须保留 HtmlUnit 2.5。

I've recently updated from HTMLUnit 2.4 to 2.5 (we'd go for the latest version but there is a lot of code to refactor due to the deprecated APIs). I'm now having a problem with some JavaScript that opens a window.

The page under test, is a 'Please wait while loading screen' for reports. The page opens a new window then redirects back to page that originally launched the print.

So the JavaScript looks something like:

window.open(url,'report_window');
document.location.href  = original_url;

With HtmlUnit 2.4 the script would continue executing and if I grabbed the original Window object it would have performed the redirect. However, after upgrading to HtmlUnit 2.5, the original window is still on the 'Please wait' page - the redirect is never executed. It appears as though the JavaScript stopped executing after the call to window.open.

I have confirmed the page behaves correctly if I test manually. I've also tried different JavaScript after the window.open call to confirm that that particular call is not the issue.

Is anyone aware of an issue like this and any potential workarounds? We have to stay on HtmlUnit 2.5 because of jQuery compatibility.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话已封尘 2024-09-23 00:37:36

我能够通过从 WebClient 对象上的 Web 窗口侦听器中删除 CurrentWindowTracker 对象来解决此问题。不幸的是,这个字段被完全封装了,所以我不得不通过反射来检索它。

        Field windowListeners = WebClient.class
                .getDeclaredField("webWindowListeners_");
        windowListeners.setAccessible(true);
        Collection webWindowListeners = (Collection) windowListeners
                .get(webClient);
        webWindowListeners.clear();

I was able to fix this issue by removing the CurrentWindowTracker object from the web window listeners on the WebClient object. Unfortunately, this field is completely encapsulated, so I had to retrieve it via reflection.

        Field windowListeners = WebClient.class
                .getDeclaredField("webWindowListeners_");
        windowListeners.setAccessible(true);
        Collection webWindowListeners = (Collection) windowListeners
                .get(webClient);
        webWindowListeners.clear();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文