1
votes

Using PhantomJS and bash, I'm working on a little piece of anti-malware that reads a web page, grabs all the domains that are delivering assets to the browser, then prints each server's country of origin. It works fine except for one site that has a... uh... 'suboptimal' piece of javascript that calls to an external server every 5 seconds. PhantomJS just loads the resource over and over and over, page.open() never finishes, and page.onLoadFinished() is never called.

Is there a way around this? Can I set a time limit on page.load()? I guess, as a workaround, can I set a time limit on the Linux process?

Thanks in advance, and if anyone is interested in a copy of this script let me know and I'll post it somewhere public.

1
I don't know whether page.settings.resourceTimeout = 3000; will do anything in your case, but it's worth a try. - Artjom B.
Already using it, no effect. - siliconrockstar
can't you just put phantom.exit() in a setTimeout? - pguardiario
OMG that so simple and I never thought of it, let me try it. - siliconrockstar
setTimeout 'worked', in that it stopped execution, but it also caused PhantomJS to crash with segfault :( Apparently it's a known issue with PhantomJS. I honestly think I'm just going to rewrite the PhantomJS parts using Selenium. - siliconrockstar

1 Answers

0
votes

I solved this problem using the solutions given here to set a execution time limit on the phantomjs command and kill it if needed.

Command line command to auto-kill a command after a certain amount of time