I am trying to clear a website using casper, and when the page is loaded, I see that there are a lot of navigation requests with isMainFrame = false. I assume this is an advertisement. Example from verbose logs -
[debug] [phantom] Navigation requested: url=https://static.licdn.com/scds/common/u/lib/inject/0.4.2/relay.html?swf=https://static.licdn.com/scds/common/u/lib/inject/0.4.2/relay.swf&xdm_e=https://www.linkedin.com&xdm_c=default3784&xdm_p=1, type=Other, willNavigate=true, isMainFrame=false
This really slows down the script, and I don’t want the cache server to waste time selecting / navigating to these URLs.
To stop them, I think I will have to catch the event navigation.requestedand stop it there. But I'm not sure how to stop navigation.
I think I will need to do something like this -
casper.on 'navigation.requested', (url, navigationType, navigationLocked, isMainFrame) ->
if not isMainFrame
//stop this navigation
else
//proceed normally
Any idea how I can do this?
source
share