Anyone, help me, how to get Headers and PostData inside extension, using xpcom/something else?
i cant find functions inside firebug due to it is big codebase... thank you guys
I am assuming that you want request headers, not response headers. Then you register an observer for the http-on-modify-request notification. The general documentation is https://developer.mozilla.org/en/Observer_Notifications#HTTP_requests, a code example can be found under https://developer.mozilla.org/en/Creating_Sandboxed_HTTP_Connections#Handling_cookies. Getting the headers is easy, you simply call nsIHttpChannel.getRequestHeader().
Getting response headers is similar but you need to listen to http-on-examine-response notification and probably http-on-examine-cached-response as well.
POST data is tricky. You can get the upload stream as httpChannel.QueryInterface(Components.interfaces.nsIUploadChannel).uploadStream. But the stream can only be read once - it is either you or the code sending data to the server. So you need to replace the stream by something that looks identical but allows you to peek on it - probably nsIInputStreamTee where you set the original stream as source and nsIPipe as sink. Not sure whether this is the approach chosen by Firebug.
Wladimir is right on for the headers. For the POST data, here's a couple of code snippets with a little more detail:
https://developer.mozilla.org/en/Code_snippets/Miscellaneous#Getting_postData_of_a_webpage
Related
I am trying to access the 'successURL' element of a response payload in chrome console, but cannot work it out. I've tried everything I can think of --> payload.successUrl, e.payload.successUrl, data.payload, but can't seem to access the element.
Anyone able to help? Thanks!
As you shown on image attached to your question - you have successfully accessed this in chrome console :)
You can now right-click to see context-menu and copy it to a variable or do some other things.
But If what you mean is to access data from developer tools straight away in a script - it's rather impossible.
For more information on that - read this aswered here: https://stackoverflow.com/a/50571792/3054380
If the request resulting with that payload data was made by your script - then you need to show how you did this - and surely it is quite simple to access any data recieved in response.
I found the answer in my question from webdev-dan and Tch (I can't upvote them as I don't have the reputation, sorry!). I was trying to access the response after it was posted to console as opposed to parsing the data in my script then sending to console.
Here is what I did to get the element from the response I needed (successUrl).
Javascript
const result = await frui.getSession();
console.log(result);
console.log(result.payload);
console.log(result.payload.successUrl);
Response in console
I'll now set the result.payload.successUrl as a variable to use later on.
Using GWT I am loading images from a server I do not control. Currently, I use GWT new Image( url) and then use ImageHandlers and ErrorHandlers to catch what happened and put the images in my buffer and the DOM. Then I make the images visible sequently to animate the process. But now I need a bit more, I need to know the error code, e.g.304 that the server returned for the image and also I need to get at the header response attribute, 'Last-modified'. For 304, I know I need to resubmit the request later when the server will have created a new version ( with exactly the same url ) which I think I can manage, but it will then have a new 'Last-modified' and I need to know that DateTime.
By using new Image(url), I am letting the browser do the loading, but I don't know how to get at the details of the load.
Q1:Is there a way to pull more info from an image?
GWT Image just seeems to wrap a JS object. I look in Firefox Console-Network, but don't see much detail there either. Is Last-modified and error code forgotten by the time it gets (or doesn't) in the DOM tree.
If the answer to Q1 is no the information is gone or inaccessible, ..
Q2: Do I need to stop using the browser to fetch images and do it with an XmlHttpRequest and then presumably I have access to the response codes and the header attributes. SOP is not an issue. But how then do I get from say the Response OutputStream to an Image? Do I have to Base64 encode it or is there a better way? Will one of the other non-url constructors for image help, say Image(Element) or Image(ImageResource). Then the issue becomes how to make a response stream into a Element or ImageResource?
Note: This other question 'How to print error message of why image failed to load?' is related, but doesn't get to an answer.
Getting Error codes, and getting the response as a stream must be done with an HTTP client (GWT has the built in RequestBuilder). You can also try to get the error code with native JS, using the method described here.
I am developing an application that needs to gather information from GitHub, so I began looking at their API. My initial thought was to use the d3.json() function to get the data (because it's simple and has done good things for me in the past), but there doesn't appear to be a way for me to authenticate with that function. For example, $ curl -u "username" https://api.github.com is given as an example of basic authentication (from GitHub API--obviously they use curl for their examples).
So, is there a way to do authentication with the d3.json() function? And if not, what are my other options to get the JSON with JavaScript?
Thanks!
Edit:
I'm experimenting now with using jQuery's getJSON method as shown here, because I started getting the error "XMLHttpRequest cannot load url Origin url is not allowed by Access-Control-Allow-Origin." Of course, the switch doesn't help with the ability to authenticate, but I can at least get the public data (which is most).
Edit #2:
Has anyone experimented with michael/github or fitzgen/github-api? I'm going to start looking into those.
If you have a PHP script which echos JSON, you can do all authentication server-side. Note that you can also send a GET request to your PHP script, so the way you call your script can be dynamic.
I am trying to access a remote json file using YUI, example code can be seen in the jsfiddle below. The request goes off to the server (you can see it in Google dev tools network tab)
. The on success or failure functions don't get executed which I can't understand
http://jsfiddle.net/brendan_rice/4FZc4/3/
Can anyone help please?
Your datasource must support the callback syntax, wrapping the data with callback([...]);
Read the first section (in blue) http://yuilibrary.com/yui/docs/datasource/datasource-get.html
I figured out the issue by putting in YUI({ filter: 'debug' }), which showed that there was a syntax error in the .Get request (which is indicative of sending over unwrapped JSON data).
Also, if you just want the raw data from a cross-origin request and don't need a real DataSource instance, you may find Y.jsonp easier to use (http://yuilibrary.com/yui/docs/jsonp/).
I need to find a way to write ajax responses to a file. The responses are XML strings, which is more than fine by me.
What I would like to do, is click on something in my webpage, and save the XML that is returned to a file.
But since I know, that Javascript can't access local files by itself, it is also possible to just send the data on to another server, where PHP would take care of this.
Now the place where I'm stuck is the javascript and the interception. I know, that some of this can be done using greaseMonkey in Firefox. If so, how? Thanks!
Edit: Some explaining.
The script that creates the output is not written by me.
Yes, I could see the data in Firebug, seeing is one thing. I need to interpret the data
There are a lot of requests going on here. About 1 every 2 seconds, so copying them by hand isn't an option.
Still, help?
You should provide more details, a link to the target page is best.
Is the page using jQuery?, Some other library?, or custom XMLHttpRequest() calls?
Anyway, a simpler approach may work, try it first...
If the AJAX data is being written to the page, attach a DOMSubtreeModified event listener to the container element. Something like:
document.getElementById ("ContainerID").addEventListener ("DOMSubtreeModified", YourFunction, false);
function YourFunction () {
//--- Get the target node's inner HTML and send it to our server.
}
Note that DOMSubtreeModified events work fine in FF and Chrome, the two main browsers for Greasemonkey.
If the data is not being written to the page, then the best way to intercept the AJAX depends on if the target page is using a library like jQuery.
A generic way to intercept AJAX can be seen in this SO question (and others).
As you said, once you have the data, to automatically write it to a file, use GM_xmlhttpRequest() to send it to a server that you control.
Why cannot you do it like this?
Save AJAX response to file on the server side and then provide a link to it, so it can be downloaded.
Firebug will also help, you can view in very convenient way each response in few formats, and eventually copy/save it.
Use a normal (non-AJAX) request and add a Content-Disposition: attachment; filename="foo.xml" header to the response.
If you're just going to save the XML, why are you using AJAX? Just set location.href to the location of a PHP script that sends a "Content-disposition: attachment" header and gives the XML in the response body. AJAX seems totally the wrong tool for the job.