how to identify the http method of a web page from javascript - javascript

location.href gives us the url of the current page, but how does one find what HTTP method was used to fetch this page. For ex., when you submit an HTML form using POST, I want to query for this method in the resulting page.
Context of this question is generating browser applications telemetry and analytics - we want to track details on the pages user visited.

Related

Googleapis authentication in iFrame

My application is writing/reading files to/from Google Drive. Before I can access the files I need to get a token that would be passed with the request. I am using googleapis node package.
The flow is as this:
get auth url:
the front end sends request to my api
my api requests the auth url from Google with
(new google.auth.OAuth2(
creds.GoogleDrive.clientId,
creds.GoogleDrive.secret,
'http:localhost:3000/ifr'
)).generateAuthUrl({scope: 'https://www.googleapis.com/auth/drive'});
the received url looks something like this:
https://accounts.google.com/o/oauth2/v2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&client_id=<...>&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fifr
this url I return to the front end and set the source of the iframe to it
If a user has already gone before through the steps of consenting to my app accessing their Drive, then google redirects to the provided url, i.e. http:localhost:3000/ifr, in this case, and adds code query sting parameter, which I then pass to my api to get the token from google. This token is later used to create google.drive object that gives access to the drive (this part works fine, though maybe there is a way to avoid going back and forth between client and api?)
If a user hasn't consented yet, then the above url loads google's page where the user has to click through a few confirmation buttons and after they agree to everything, google redirects to http:localhost:3000/ifr?code=.... And this is where I have a problem. In this scenario google's confirmation page wouldn't load in the iframe, it gives me a "broken" page. I don't see a way to distinguish between the url that would load the consent vs the one one that redirects with code, they look the same, so I can't load one in the iframe and the other in parent.
How are these pages different? Why one is ok to be loaded in the iframe and other one isn't? Maybe I am doing this all wrong and the whole authentication can be done server side?

How to convert JavaScript dynamic data into HTML and render?

We have developed a website and it uses JavaScript library to query database and display the data in HTML page. When you go to the website, you need to search for something in order to retrieve the data.
so by default website doesn't display any data and it needs users to perform action.
The search result data is not visible in HTML view source as it uses JavaScript.
So, the search engines have no visibility as to what our website used for and data used in order to redirect more visitors.
Secondly, I wonder how search bots/engine crawl the websites with non-static content and understand enough about the website to redirect users.
from what i see from your question what you need to do is send requests to your server to query data from your database and show it to you client in real-time.For that i would recommend that you use web sockets(such as socket.io) or AJAX so that you could update your website seamlessly
From what I have researched, crawlers actually don't read dynamic content. Instead, they use this technique called dynamic rendering.
Dynamic rendering has to do with the server itself. It checks each request and if it determines it to be a bot, then it will send static HTML content to the bot. Otherwise, it will send normal dynamic content to the user.
Also, google and other search engines make use of meta tags. With meta tags you can define a short description of the webpage which will oftentimes be shown in the search results page.
As for question in the title, you would need to send the search information to a server. From there, you would process the data server-side and send the results back to the client where JavaScript would render it based off of the results.
You should use AJAX for this.
Resources:
https://ignitevisibility.com/dynamic-rendering-seo-details-need-know/
https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX
https://developer.mozilla.org/en/docs/Web/HTML/Element/meta

How to send data across domain using javascript and tampermonkey?

I follow a forum where people post many links. I've made a script, using javascript and tampermonkey (chrome extension), that first opens all unread thread in new tabs, than it looks for unread posts that have links and opens those links in new tabs.
This script saves me a lot of time and it is working pretty well. Nevertheless, I would like to improve it.
I want to change the title of the page that has been just opened in order for it to show the name of the thread on which the link that sent to this page was. For example:
On the thread "Fruits" there is a link that opens a new tab to a website "www.apple.com". I would like to change the tittle of this page to "Fruits - The name of the page", so I can know from which thread this link comes.
I use localstorage and sessionstorage to send information from one page to another page when my script is navigating inside the forum domain, but I have no idea what I can use to send information across different domains.
Furthermore, I would like to know if there is a way to tell tampermonkey to run the script according to the link that was opened.
I do know how to change the tittle of the page, the problem is taking the name of the thread that is on the forum domain and using it to change the tittle on the new tab that is on a domain different from the forum domain.
Localstorage doesn't allow access on different domain. You need to store that data in database server. The easiest is to sign up a database service, and it provides API you can use. If you're going to host your own, you must write your own scripts that allow CORS to provide the access to database server.

Google Analytics not tracking clientside redirects

I'm trying to solve a problem with tracking traffic to individual blog posts on a system that uses a javascript redirect system where something somehow break tracking.
The way the system works is as follows:
Permalinks are in the format of domain.com/ab_XXXXXX where ab_XXXXXX is a unique code. That code is parsed by a piece of javascript, which tells the browser to load the individual blog post page. This page has a URL format of blog.html/?cd_XXXXXX_ef=YYYYYY. Here too, XXXXXX and YYYYYY are unique codes which, combined, identify the particular page.
When I load the blog.html/?cd_XXXXXX_ef=YYYYYY URL directly, Google Analytics does seem to track the page and the user shows up in the real-time dashboard as visiting that particular page.
However, when I load the domain.com/ab_XXXXXX URL, the user does not show up in Analytics' real time dashboard, even though the analytics tracking gif gets loaded.
Since the ab_XXXXXX URL is the permalink, Analytics appears to contain no data on individual blog post visits at all.
I'm not the programmer on this system, and at this point I'm not sure what to test or to suggest as changes to the programmers.
My question is: why would Analytics track the user in the one occasion, but not in the other? And what could be done to remedy this?
Does the page ab_XXXXXX actually redirect the user to cd_XXXXXX_ef=YYYYYY or does it simply load the contents of that blog post into the same page? In either case, but particularly the latter, you can simply choose to manually track the page view in your existing Javascript snipped by adding something along the lines of _gaq.push(['_trackPageview', 'blog.html/?cd_XXXXXX_ef=YYYYYY']);

How to extract some information such as the meta and the topic using url or the page and JQUery

Consider I have a URL, now I want to have some information associated with the URL on my page same way as Facebook or other websites such as LinkedIn do. You submit a URL and the data about the website is retrieved to be submitted. I am using JQuery and HTML for an application and want to know how to do this thing. My application has few URL's retrieved from the different sources. I want to show some of the information instead of plane URL's. How is it possible to make such a thing using JQuery?
You cannot access external URL's directly by AJAX calls because of the Same Origin Policy. What you'll have to do is to submit a request to your own server, and have some serverside code request the external URL and retreive information.
How that is best achieved depends on what serverside setup you're running.
.NET example
PHP example
(basically just google "Screen scraping" + your language of choice)
You need to process the whole page to search for images or useful information.

Categories