CasperJS : Why does my url change to about:blank when my page is loaded?

☆樱花仙子☆ 提交于 2019-12-03 02:44:43

There are open issues (see update below) on CasperJS and PhantomJS Github Repos regarding redirecting to/opening about:blank page


  • --proxy-type=none command-line argument

On Windows, the default proxy setting may cause a massive network latency (see Known Issues in the release note). The workaround is to disable proxy completely, e.g. by launching PhantomJS with --proxy-type=none command-line argument. 1


Your code worked correctly, with the following versions :

  • PhantomJS 2.1.1
  • CasperJS 1.0.4
  • MacOSX

[info] [phantom] Starting...
[info] [phantom] Running suite: 3 steps
[debug] [phantom] opening url: https://www.google.fr/, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.google.fr/, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "https://www.google.fr/"
[debug] [phantom] Successfully injected Casper client-side utilities
[debug] [phantom] start page is loaded
[info] [phantom] Step 3/3 https://www.google.fr/ (HTTP 200)
Page Loaded
PASS Welcome to Google
[info] [phantom] Step 3/3: done in 262ms.
[info] [phantom] Done 3 steps in 341ms

There were some issues with page navigation in casperjs 1.1.x beta and PhantomJS >1.9.8 where the recommendation was to downgrade PhantomJS to 1.9.7


I would recommend, if possible, to try different versions

Either Github Issue 1485 solution or @Ross solution may solve the problem - any comments?

I also had this same enigmatic debug logging for my step:

[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "about:blank"

In my case I needed to click Submit button on an AJAX form that was a link element with href='javascript:;'. It turned out this in itself was not the main problem. Rather it was that their web system was built with Apache Wicket java web framework, which issues stateful sessions for each search interaction. And it happens via redirection – and this was the key point here.

Now CasperJS supports two engines PhantomJS and SlimerJS... When digging into CasperJS documentation I wound this linked page Differences between SlimerJS and PhantomJS which states:

'PhantomJS doesn’t do redirections, whereas SlimerJS does.'

For reference here was my options as set to be most loose and with debug enabled (some of these are with the default values):

var casper = require('casper').create({
    engine: 'slimmerjs',
    verbose: true,
    logLevel: 'debug',
    exitOnError: false,
    ignoreSslErrors: true,
    pageSettings: {
        javascriptEnabled: true,
        loadImages: true,
        loadPlugins: true,
        localToRemoteUrlAccessEnabled: true,
        userAgent: 'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36',
        XSSAuditingEnabled: false,
        logLevel: 'debug'
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!