Request Blocking Using Javascript? - javascript

How to block requests from a certain URL using JavaScript? For example, the manual way to do so on chrome will be to open the inspect page, go to network and block from there. But I need to block requests from certain URLs for an automated test that i am writing in JavaScript (using testcafe, if that offers any help).
Here are screenshots of manually blocking a request from chrome, I want to do the same thing automatically in my test/JavaScript:
ScreenShot1
Screenshot2
Thank you.
Edit:
I tired following this post: Blocking request in Chrome
but for some reason i always keep getting an error stating that chrome is undefined when I use chrome.webRequest

You can use the nock library, which allows you to intercept requests and process them as you wish.

Related

How to handle JavaScript files via Jmeter

I get this message in Jmeter when I run my testplan.
<noscript>
<p>
<strong>Note:</strong> Since your browser does not support JavaScript,
you must press the Continue button once to proceed.
</p>
</noscript>
How do I get around this issue on JMeter? When I go to the link manually in Chrome, the page/charts load fine.
I asked the UI engineer how things worked and they said when we go to the webpage
The http request returns an html
The browser reads the html and requests js files.
Thanks in advance for any help.
As per JMeter Project main page:
JMeter is not a browser
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
Browsers don't do any magic, they just execute HTTP requests and render responses. If JavaScript is being used to "draw" something on page - you should not be interested in it as it happens solely on client side.
If JavaScript is used for building i.e. AJAX requests - these are basically "normal" HTTP Requests which can be recorded using HTTP(S) Test Script Recorder and replayed via HTTP Request samplers.
If you cannot successfully replay your script - most likely you're missing HTTP Cookie Manager and/or need to perform correlation of dynamic parameter(s)

how to create web pages in which network requests cannot be captured by browser's debugger

This doesn't involve coding. I am just curious on how to make a page like the one described below.
I came across a website where we can attend quiz/tests.
I tried to debug the browser so that I can see if I could hack through the codes by getting the values that are getting passed in debugger.
But to my surprise the debugger is not coming up when I click F12 in that page.
Somehow I opened debugger for that page and I clicked on the Network tab to capture requests that are sent.
But as I was proceeding through the test, not even one request is getting captured in the debugger but the answers are getting validated and scores are getting updated !! I was not even able to do inspect element
I guess its a java applet as i saw the below line in the the launch button
flagPlayerCourse = true;launchApplet(secureSessionId,courseName, courseType,winParams, use508);disablePlayButton(1, 0);
the url had SinglePassUserCmd.cfm?sessionid=3xxxxx
So my question is how can we create such a webpage in which the requests are not captured in the debugger!? I would be happy if someone could tell me how do the same in asp.net. In which language can we develop such web pages!?
Applets are completely different world. Its almost as good as running a .net application on your client machine.
What you see in the debugger are ajax requests and resources loading. If a site doesn't make them, you won't see any network requests in the browser.
That doesn't mean that you can't capture the data being send. You can always use a debugging proxy like fiddler to see what traffic is going across. Ofcourse a secure site would secure their traffic over https.
Applets require a java plugin in your browser. There are similar plugins like Silverlight, flash/shockwave(swf) that too can make network requests.

How does the Firebug network monitor work?

In the Firebug add-on for Firefox, how is Firebug able to get the connecting, waiting, and receiving time? Also, how is it that Firebug can know the file size before the file is even finished loading?
Is JavaScript used in these calculations, or does Firebug use another method altogether?
Firebug plugs into Firefox and can fetch data from there. The webserver maybe sends a Content-Length HTTP header, so this is the expected size of the downloaded file. Firefox puts all resources to load into a queue while parsing the website. The time from putting an item into the queue until it is fetched can be considered "waiting time". The HTTP fetch engine from Firefox can give information about how long a connect() to the server takes.
So to put a long story short, I believe Firefox has an API so that extensions can fetch information like that from the engine.
Firebug is most, if not all, JavaScript.
If you're truly interested, you can find the network monitor related bits and pieces here in the Firebug source tree.

JQuery $.post not working on some PCs

I have a very strange problem with JQuery $.post()
I have implemented it in my new web application and get messed response from QA after testing, some say it is working perfectly and some say it is not working;
It generate no error and no warning,,, but i am very upset i have almost compeleted the application and it is impossible to use some alternative,,, please if some one has any idea then please help me.
Regards
I suggest you to write a simple test page that makes only a $.post call and print a result (like 'test passed'). This way you can be sure that there is no other problem in your application causing the error. Afterwards you can send this link to the QA and see if the XHR requests are really working (or not).
Maybe the specify computer setting, such as different browsers or browser security configuration or others, check then step by step. You should may the error logs more detail. otherwise you can use HTTP sniffer tools such as firebug, ieinspectoer..

What's an easy way to see what AJAX calls are being made?

I'm looking for something (preferably a Firefox extension) which will allow me to see all AJAX subrequests. Basically, anytime an XMLHTTPRequest() is made, I want to know what URL was being requested and what (if any) GET and POST vars were passed along with it.
Unless I'm missing it, I don't see anything quite like this in Firebug or Web Developer Toolbar.
(In case you're curious, the main reason for wanting this is that I want to scrape a local copy of a site that is using JS to load all its contents, and I don't want to spend hours digging through their JS code when I could just see the subrequests being made.)
Firebug should show it in the Net panel.
EDIT: Also, if Firebug slows down your Firefox in a way that makes it unusable, like it does for me sometimes, WireShark (formerly Ethereal) will analyze all network traffic on your system, including HTTP and AJAX requests.
Fiddler 2 is a great tool for watching HTTP traffic.
* 2014 Update *
Since my original post, both Internet Explorer and Chrome have added built-in developer tools that are quite useful. While I still support and use Fiddler for non-web related http monitoring or when I need to really dig in deep and modify requests in transit, these days I find myself pretty much using IE or Chrome's built in tools as they are sufficient for 99% of my needs. They both have a networking tab, where you can monitor http requests, plus other nifty features for debugging webpages.
Internet Explorer F12 Tools Introduction
Documentation for Chrome's F12 Tools
FireBug, which is mentioned above is also a good tool if you're using FireFox.
I have used nearly all the big tools out there (fiddler, firebug, httpfox, live http headers). The best one in my opinion is HTTPFox if you are using Firefox because it has easy filtering capabilities, allows you to view your JSON the request/response as raw or formatted and the over all interface is very clean.
Also, I can't do without WFetch for testing web services and AJAX stuff. Usually I'll take the request from HTTPFox and paste it into WFetch. This way I don't have to go through the browser each time. I just hit F5 in WFetch to replay the request and I directly modify the request.
Side note: In WFetch, be careful about content-length if you have a POST payload. If you modify the payload the content-length needs to be changed as appropriate. For this reason I save my requests in a file and point WFetch to the file. In the file itself it is easy to know the length of the line and change content-length to that.
(source: koreus.com)
alt text http://www.port80software.com/assets/images/ld_wfetch3.gif
Firebug shows them in both the Net panel, and the Console view. You need to turn on "Show XMLHttpRequests" though.
Have a look at Tamper Data as well. It's a Firefox add-on that lets you have a look at each individual HTTP request (including any post data) and response, and the headers of both. I've found it very useful for debugging AJAX problems...although Firebug works just fine.

Categories

Resources