The desire here is to be abel to cancel a resource from being loaded during page.onResourceRequested something like
page.onResourceRequested = function(request) { if(request.url.indexOf("run.js") > -1) { return false; // or request.cancel() or request.abort(); } }
Comment #1
Posted on Sep 13, 2011 by Quick Rabbit(No comment was entered for this change.)
Comment #2
Posted on Dec 21, 2011 by Grumpy Monkeythis feature would be very helpful to minimize load times and start performing tasks earlier (i.e. avoiding Ads loading times, certaing .js , etc...)
It would be a fantastic feature
Comment #3
Posted on Jan 8, 2012 by Quick RabbitIssue 339 has been merged into this issue.
Comment #4
Posted on Jun 7, 2012 by Helpful WombatHoping this gets added soon.
Comment #5
Posted on Jun 18, 2012 by Grumpy OxThis would be very helpful!
Comment #6
Posted on Aug 9, 2012 by Helpful Giraffewhats the workaround for this?
Comment #7
Posted on Aug 10, 2012 by Massive CamelAt this moment there's only one way, modify the createRequest function in networkaccessmanager.cpp and rebuild phantomjs. Take a look at this example, http://stackoverflow.com/questions/4575245/how-to-tell-qwebpage-not-to-load-specific-type-of-resources. Note: I'm not a phantomjs guru so perhaps someone else can comment this.
Comment #8
Posted on Aug 15, 2012 by Helpful Giraffe... what kind of donation to the project could get this as a high priority item? i might be able to arrange something.
Comment #9
Posted on Sep 5, 2012 by Grumpy ElephantI also think that it's a really good feature. Actually event like onResourceRequested is only usefull for logging (or other features). But it would be interesting ot disable some request (javascript that load advertising and that may break the testsuite...).
Comment #10
Posted on Sep 10, 2012 by Swift Oxwaiting for this feature!
Comment #11
Posted on Oct 16, 2012 by Massive WombatYes, that would be nice.
I have created an small patch against PhantomJS for me and added an option --ignore-host='(google.com|facebook.com)'
So PhantomJS will not load any resources from hosts that matches the above regexp.
Comment #12
Posted on Oct 19, 2012 by Massive PandaI would love this feature too. J
Comment #13
Posted on Nov 28, 2012 by Massive WombatMy hacky patch for that:
https://github.com/hggh/phantomjs/compare/ignore-host.patch
If you apply that patch, you can use this:
--ignore-host='(google.com|twitter.com)'
That's perfect for Nagios/Icinga checks with https://github.com/hggh/phantomjs-nagios to ignore social media stuff or tracking.
Comment #14
Posted on Dec 1, 2012 by Quick RabbitIssue 395 has been merged into this issue.
Comment #15
Posted on Dec 9, 2012 by Happy HorseIssue 288 has been merged into this issue.
Comment #16
Posted on Jan 5, 2013 by Quick RabbitAllow to abort network requests. https://github.com/ariya/phantomjs/commit/09e929d599
Comment #17
Posted on Jan 5, 2013 by Quick RabbitFor completeness, there is a new example loadurlwithoutcss.js which demonstrates this.
The gist:
page.onResourceRequested = function(requestData, request) { if ((/http:\/\/.+?.css/gi).test(requestData['url']) || requestData['Content-Type'] == 'text/css') { console.log('The url of the request is matching. Aborting: ' + requestData['url']); request.abort(); } };
Comment #18
Posted on Jan 5, 2013 by Happy Horse(No comment was entered for this change.)
Comment #19
Posted on Jan 5, 2013 by Happy HorseFor posterity, related discussion of new API: https://groups.google.com/d/topic/phantomjs/0OnJPkDAqSk/discussion
Comment #20
Posted on Jan 9, 2013 by Happy HorseVitaliy: Is it possible to CHANGE the URL at that point rather than just abort the request? I know that is desired, too, e.g. Issue #539 (read through the initial comment).
I also just looked at the first example for Qt 5.0 WebKit and saw it is doing just that (but with the QWebView class, which is higher level than what PhantomJS does): http://qt-project.org/doc/qt-5.0/qtwebkit/qtwebkit-index.html
Comment #21
Posted on Jan 9, 2013 by Quick CatThis was my original desired end result also but I was thinking along the lines of aborting the original request and adding a new script tag for the new resource wanted.
-- http://ithoughtyouweretherobot.com Metal and Wire
http://nolonelyguineapigs.com/ Wandering and Rambling
http://morglog.org Old and Neglected.
Comment #22
Posted on Jan 10, 2013 by Quick RabbitI don't see anything in http://qt-project.org/doc/qt-5.0/qtwebkit/qtwebkit-index.html which says something about changing the URL. You may have misunderstood the "delegate" term there, it's not about redirecting the URL but it's rather handling the functionality differently.
Comment #23
Posted on Jan 10, 2013 by Happy HorseAh, yeah, that was indeed how I interpreted it. Drat....
In reality, though, in Qt, we can create and connect arbitrary signals, right? If not, it seems like we could easily generate a signal before we call [or at the start inside of?] NetworkAccessManager#createRequest
and connect another on____
signal handler for that in the WebPage
object. Am I totally off-base here? I recall Vitaliy mentioned something about not being able to appropriately stop/abort a request before it is issued... if that's the case, then we'd probably have to short-circuit such requests BEFORE the createRequest
method is invoked.
Comment #24
Posted on Jan 11, 2013 by Happy HorseWhat if we implemented a custom QNetworkReply
and set it to a terminal status in the createRequest
method e.g. the first code sample on this page:
https://blogs.kde.org/2010/08/28/implementing-reusable-custom-qnetworkreply
I know an HTTP error status is not the same as aborting the request (reply) but I'd probably still prefer it for network performance over the current solution. Unless the reply object can be aborted AND returned in the createRequest
method...?
Comment #25
Posted on Feb 1, 2013 by Happy HorseVitaliy/Ariya, any thoughts on that?
Comment #26
Posted on Feb 1, 2013 by Quick MonkeyI'm still looking for solution, but no luck.
Comment #27
Posted on Feb 2, 2013 by Happy HorseOtherwise, seems like the method in the SO answer linked to earlier by Fritz (Comment #7) would work for both "aborting" (with an empty QUrl) or redirecting: http://stackoverflow.com/questions/4575245/how-to-tell-qwebpage-not-to-load-specific-type-of-resources/4588113#4588113
Comment #28
Posted on Mar 16, 2013 by Happy HorseThis issue has been moved to GitHub: https://github.com/ariya/phantomjs/issues/10230
Status: Fixed
Labels:
Type-Enhancement
Priority-Medium
Milestone-Release1.9
Component-Logic
Module-WebPage