my client side react app is running on http://localhost:3000 and my node js server is running on http://localhost:8080. When client url is loaded, it sends GET /auth/user 304 0.494 ms - - fetch ajax request to load user(on react componentDidMount function). Problem is, when typing 'l' on Safari browser and url is autofilled with 'http://localhost:3000', it is confirmed that my server get the same request as GET /auth/user, before I even press enter key and before the client page is loaded. In Chrome it doesn't. Why Safari browser sends ajax request when user didn't visit the page and just typed part of its url? Is it a designed behavior?
As a result of tracking the reason for 6 hours. I figured out Safari implements cached ajax request differently from other web browsers. When Safari has client url data which has records of requesting ajax to external api, Safari sends the same ajax request just before user visits the client url page(when url is being typed and auto-suggested) to check if the response is 200(different) or 304(same). If the response is 304(same) and client page is loaded actually, Safari doesn't send ajax request again. This can be very annoying in the user login process, because the user data is loaded before actual authentication process is complete(user data response is 304), so client app remains unauthenticated when browser is authenticated. The solution I landed was adding an extra query parameter when fetching user data( '${root}/auth/user?' + 'nocache= new Date.getTime()' ) to prevent Caching AJAX in Safari browser. Hope it helps someone who faces the same problem.
Related
I am trying to intercept all web requests using by Puppeteer-Sharp but it is not working properly if the request sent by IFrame which is located on the page. For instance, After navigated this link, I clicked the video link since the video is in the iframe(maybe this is not the cause, this is only my hypothesis), the new web requests sent by IFrame did not intercept but the others were intercepted. When I checked it on the Chrome Developer Tools I was able to see what I am looking for and also more requests.
By the way, I set Request Interception as true as below:
await page.SetRequestInterceptionAsync(true);
and I registered for the PageRequest event as below:
page.Request += Page_Request
Is there any other setting or missing setup?
If I hit any AJAX request on targeting server then the request directly goes to targeting server or the request first goes to origin server and then goes to targeting server?
Cross-origin AJAX requests go directly from your browser to what you call the “targeting server”.
A cross-origin AJAX request is initiated by JavaScript running in your browser on the client side after the browser fetches the JavaScript for your Web application/document from the origin server.
A cross-origin AJAX request does not go back to the origin server ever. The communication is: JavaScript running in your browser sends a request to the “targeting” server, which replies with a response directly back to the browser and back to your JavaScript running on the client side.
My website uses Ajax to report the user's progress back to the server while the user stays on the same webpage. This works fine on all browsers except the Facebook In-App Browser (FB IAB). Why?
If your web server uses cookies when processing Ajax requests, you will have the following problem:
After a web page loads, FB IAB doesn't send cookies to the server for Ajax calls. I consider this a bug.
A workaround is to send all required data in the querystring instead.
We have a Node.js application that invokes a Spring controller. For a PoC purpose, I am creating the cookie in the Spring controller before returning the JSON response to the Node.js application.
Cookie cookie = new Cookie("myCookie", "myCookieValue");
response.addCookie(cookie);
I had my Firebug console open to see if the cookies created in server side are visible but, unfortunately i did not see them.
Also, on the 2nd submit, i tried reading the cookies using request.getCookies() but this is also giving me NULL.
Are the cookies not being received by the browser because it is a
Ajax/JSON request-response ?
How does browser send back cookie to the server during post requests. How is this different than the form data that is sent during a post ?
Also are the values of cookies for a particular domain automatically sent back to the domain for all its subsequent requests ?
Thanks,
Murtaza
There is no different between how cookies are sent for GET and POST requests.
Form data is data such as fields from an HTML Form, eg. name, username, file, etc...
Any cookies sent back in a response from a domain will be sent back to the server in subsequent requests. This is true in web browsers at least, if you are doing this in code, you might have to write additional code to handle cookies.
This should work for AJAX calls made by your browser as well as full pages. Every request, be it full pages, images or AJAX calls will have the Cookies attached if they are going to an appropriate domain and path.
These primers on cookies and HTTP POST would be useful:
http://en.wikipedia.org/wiki/HTTP_cookie
http://en.wikipedia.org/wiki/POST_(HTTP)