How to skip the code execution from PhantomJS or grover

假如想象 提交于 2019-12-24 02:31:31

问题


The problem is next: I have JavaScript code in my application and I want to skip/hide some peace of code from PhantomJS and grover checking/execution.

So, how can I skip/hide the code execution from PhantomJS or grover?

Note: the problem has occurred when I was writing the JavaScript unit-tests. But I think it would be helpful in other cases.


回答1:


You just need to wrap the code with simple verification:

if (!window['phantom'] && !window['_phantom']) {
  // your code here...
}

In this case the code in your application will be executed as normal but skipped when the PhantomJS or grover will inspect it.

Notes:

  • I use "window['phantom']" - because my application is minimized using google closure compiler, in other case you can easily use (!window.phantom && !window._phantom);
  • window['_phantom'] - indicates presence PhantomJS using grover tool.


来源:https://stackoverflow.com/questions/26186101/how-to-skip-the-code-execution-from-phantomjs-or-grover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!