0

If a webapp have JS code such as the following:

for(i=0; i > -1; i++){var a=1}; // Infinite loop

and I use Selenium/Phantomjs to browse it, it will be stuck forever.

How can I solve this problem? Does phantomjs have an option to set a timeout for script execution?

DrakaSAN
  • 7,673
  • 7
  • 52
  • 94
user1571234
  • 261
  • 3
  • 4
  • 9
  • No, you can't. Which version of PhantomJS are you using? By the way, any browser should freeze when opening such a site. – Artjom B. Aug 12 '16 at 16:20
  • I'm using 2.1.1. So this problem is seems to be unsolvable ? – user1571234 Aug 12 '16 at 19:07
  • Since JavaScript is single threaded and PhantomJS access the page context through JavaScript, an infinite loop in the page context will freeze the page. That's just bad programming. Anyway, you may try to change the page JavaScript that does this madness through a proxy or something like that. – Artjom B. Aug 12 '16 at 19:16

1 Answers1

-2

Use resourceTimeout

var page = require('webpage').create();  
page.settings.resourceTimeout = 5000; // 5 seconds

Origin: phantomJS webpage timeout

Community
  • 1
  • 1
Raskayu
  • 735
  • 7
  • 20