PhantomJS - JS错误后注入的JS不会运行

时间:2016-11-17 14:56:30

标签: javascript phantomjs

我有一个看起来像这样的phantomJS脚本:

window.setTimeout(function() { //give page a couple seconds to load before injecting our scripts
        //include our version of jQuery so that our injected JS can run properly
        page.includeJs('//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js', function() {
            if (!page.injectJs(JS)) {
                console.log("unable to inject JS at " + JS);
                phantom.exit(1);
            }
        });
    }, 2000);

注入的JS是运行并最终执行终止脚本的window.callPhantom调用。问题是这个JS被注入到最终用户指定的页面上。最终用户可以提供例如http://www.google.com或其他任何内容。

看来如果页面有JS错误,则不会运行注入的Javascript。由于我不控制页面的内容,因此我无法阻止这些JS错误。

有没有办法让我注入的JavaScript运行,尽管页面上生成了先前的JS错误?

0 个答案:

没有答案