I am currently working on an addon and it had a addon window with addon buttons and a tab in main window it maintains. I am able to open a page in main tab by
mainWindow().location = "http://murmuring-retreat-7618.herokuapp.com/signin";
I created mainWindow by following way
getBrowser().getBrowserForTab(bridge.recordingTab).contentWindow;
where I have already saved bridge.recordingTab as the tab I am connected.
but if I want to send a post request instead of just open a url, how do I do it?
If you use jQuery in your firefox addon then you could simply do a $.post
Note though that you need the destination server to be CORS enabled, otherwise you can only do JSONP requests using $.getJSON
Related
I'm working on small automation and encountered one problem. At first attempt I wanted to send CORS request from one web to another but it is restricted on the domain I'm automating (redirect is not allowed). In this case I have to open the origin page first and then send the request. I'm gonna open new window window.open and send the request from there (Checked and it works). I'd like to make it as simple as possible so to do it I need to control the new tab from current tab - Force it to run some lines of code. Is it even possible in modern js ?
It should be, you'd utilize something along the lines like:
var myWindow = window.open("", "_self");
myWindow.document.write("<p>I replaced the current window.</p>");
Control gets finicky but this should help.
I try to port my Firefox extension to Chrome but the way of working of webrequestonHeadersReceived doesn't seem to be the same.
When I use:
chrome.webRequest.onHeadersReceived.addListener(analyse,{urls: ["http://*/*", "https://*/*"]},["blocking", "responseHeaders"]);
the function analyse is correctly called and I can analyse the response headers and if the function return "cancel: true", on Firefox the page doesn't update and it is perfect but in Chrome, the page is updating and display the famous message
"Requests to server have been blocked by an extension"
The goal of my extension is to manage some type of downloadable file. But where in Firefox, if you click on download, the page doesn't move and I can display a panel who let you choose what to do, in Chrome even if my panel is correctly displayed, the main page is updated with this error message and I am forced to click on "back" to retrieve the original page.
Furthermore, in Firefox, when a request is blocked one time, it does not try to get again the request, while in Chrome, the page which displays the error message try to get a new the request.
Since Firebug has been discontinued, I'm missing two very important pieces of functionality.
I was wondering if there is some replacement available for the following functionality within the default Firefox Web Console.
When a URL was called using Ajax, I had the following options with the URL.
"Open response in new tab" Using this I could open errors that were generated after an AJAX-POST call.
"Resend query" I'm not entirely sure what this function was called, because I used it in Dutch but I used this function to retry AJAX-Calls without having to fill in a form again.
So, is there any way to achieve these two functions in the default Firefox Web Console?
You can access to XHRs in 2 tabs, Console (Web Console) & Network (Network Monitor).
In Console you can see quick view of XHRs. (Headers, Params, Response, Cookies, Call Stack)
In Network tab you can see all requests incl. XHRs. try to select one XHR request, you will see a new column show up in left side with following tabs, Headers, Cookies, Params, Response, Timing & Preview (as Firefox 51.0.1), check the Preview tab, it's great.
Also try to right-click on any XHR in Network tab, you can see few options, incl Edit and Resend and Open in New Tab. this 2 options will be your answer. :)
You can request features/report bugs about Firefox Developer Tools (& of course Firefox) using Bugzilla#Mozilla. Gaps between Firebug and the Firefox DevTools are tracked in bug 991806.
Background
We have two web applications hosted on different sub-domains. Application 1 is an internal admin system. Application 2 is a helpdesk system.
We can modify the source code of Application 1 but we have no access to modify Application 2.
The Goal
To display a link against an order in Application 1 that will open a new window, the URL of which is that of a ticket in Application 2.
The idea being that our staff can see that an order has a helpdesk ticket raised against it and simply needs to click a link on the order to view the ticket and reply to it.
The problem
Regardless of how I open the new window (window.open, target="_blank", etc.) the ticket in the new window is unable to make any ajax requests back to the helpdesk system where it is hosted.
The URL of the new window is part of Application 2.
In Google dev tools it tells me "The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "https". Protocols must match." even when I open it using _blank.
If I go to the exact same URL manually everything works... but this doesn't help when I need it to work from the link.
Is there any way to achieve the above?
If not, is there any way I can open a new window that is "detached" from the window that opened it so that same origin policy no longer applies?
Edit 2014-03-28 10:23
I have no access to App2's code at all. I cannot make any changes to App2. Any answer must take this into account.
I am trying to open a new window from my application (App1) where the target URL of that window is a page in App2. That page inside App2 then needs to be able to use ajax to communicate with other areas of App2. This is where the problem lies. Because App1 opened the window the same origin policy is preventing that window from making it's ajax requests.
I suspect that JavaScript on the second (helpdesk) app is trying to access the first app via window.opener (which could lead to the cross-origin error you're seeing) and subsequent JavaScript (fetching stuff via AJAX) is then not getting executed. You can probably narrow things down by setting appropriate breakpoints in the second app.
If this is the cause and you can't modify the source for the helpdesk app, how about going to a URL in the internal domain that would then redirect to the help desk? The redirect should cause the window.opener property to become null (same as manually typing in the URL).
Assuming https://admin.mydomain.co.uk and http://helpdesk.mydomain.co.uk, clicking on the "Help Ticket" link would go to a URL in the internal app, e.g. https://admin.mydomain.co.uk/getHelp?ticketId, which would respond with a 301 response and an appropriate Location: http://helpdesk.domain.uk/help/ticketId header taking the user to the actual helpdesk URL.
You could use a proxy server or iframe proxying.
Use the following url //app2.mydomain.co.uk without the http or https.
It's not only a cross domain problem but a protocol issue :
You can't embed https into http page without this warning.
Consider using iframe inside your App1 :
<iframe src="https://app2.mydomain.co.uk" ></iframe>
Or maybe you can use CORS to access data between your two domains ( but i think it's not the point, you want the whole App2 page, isn't it ? )
Edit : By re-reading your question, i'm pretty sure of two thing :
You're not looking at the right direction. You say App2 don't use SSL, and that obviously false when Chrome say "Protocols must match"
It's not a "attach" or "detached" problem. If you put a link (blank or not) in a page, it can be load the new page without any problem, nor link with the referal page.
So my guess is : Your are calling App2 without SSL ( no https), BUT inside the App2, there is some https involved ( certainly some ajax query). So here is the problem : When you open the page without https, it's seem to load, but when the first https Ajax fires, it fail.
Try using https when calling your App2 url, and give us the result
My solution is this: in Application 1 you create a method your method that calling Application 2 on the server side, then you can use AJAX calling your method which will return result of Application 2.
I have a ajax call to a controller that checks for authentication, when no authentication exists it sends the call onwards to the signin controller who checks if it is a xhr request. If it is it renders an rjs containing a page.redirect_to to the signin path and the main window is redirected to the signin page. This works flawlessly in google chrome but fails in Firefox.
the only code in the rjs file is:
page.redirect_to("http://localhost:3000/signin")
As i said, it works flawlessly in chrome but Firefox(v3.6) refuses to redirect the main Window. Does anyone have any ideas as to how i can get this to work in Firefox as well?
Are there any errors appearing in the console?
Would it not be easier to respond to "js" and render a js template with something like:
window.location = "http://localhost:3000/signin"
On a bit of a tangent, should you really be redirecting to "localhost:3000" absolutely anyway? Maybe there is a different solution?
You will probably need to handle the response from the ajax request and redirect via JavaScript:
window.location = urlToDirectTo;
I think most browsers will redirect the ajax request itself, not the page from which the ajax request was made. Here's an answer to a similar question that details the solution.