5

Say I am on a website viewing the homepage at https://whateverxyz.com/index. Then I either

  • (A) click a navigation link in the HTML of the page to https://whateverxyz.com/app1.html
  • (B) click on a browser bookmark to https://whateverxyz.com/app1.html

Can the server tell the difference between whether request was from A or B? Can client-side JavaScript running on app1.html tell the difference?

Bharata
  • 13,509
  • 6
  • 36
  • 50
jwl
  • 10,268
  • 14
  • 53
  • 91

3 Answers3

11

Citate from your question:

  • Can the server tell the difference between whether request was from A or B?
  • Can client-side JavaScript running on app1.html tell the difference?

In both cases this is not possible to detect the difference.

What say us official resources?

Citate from RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1)

If the target URI was obtained from a source that does not have its own URI (e.g., input from the user keyboard, or an entry within the user's bookmarks/favorites), the user agent MUST either exclude the Referer field or send it with a value of "about:blank".

The Referer field has the potential to reveal information about the request context or browsing history of the user, which is a privacy concern if the referring resource's identifier reveals personal information (such as an account name) or a resource that is supposed to be confidential (such as behind a firewall or internal to a secured service). Most general-purpose user agents do not send the Referer header field when the referring resource is a local "file" or "data" URI. A user agent MUST NOT send a Referer header field in an unsecured HTTP request if the referring page was received with a secure protocol. See Section 9.4 for additional security considerations.

Read more about it:

Alternative solution

But something you could do on client side. In the page https://whateverxyz.com/index you could write one listener in JavaScript which detect all clicks on this page links. And on click event you could write the link URL and the time in a cookie, an IndexedDB or a localStorage. Then in the page https://whateverxyz.com/app1.html you have to read this information. In the case if this information is not undefined it is from link and in all other cases it is from bookmark (or may be it was tipped in adress bar, or whatever).

See related questions:

Community
  • 1
  • 1
Bharata
  • 13,509
  • 6
  • 36
  • 50
1

I am afraid, you can not find out! It is only accessible in browsers extensions.

Iman Nia
  • 2,255
  • 2
  • 15
  • 35
  • Do you have proof or documentation? – jwl Aug 17 '18 at 21:16
  • 1
    @jwl Well, there is no documentation for something that does not exist. Yet, I may refer you to use [WebApplication](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks) which works with firefox at least! But I am sure it is not what you have looked for. – Iman Nia Aug 18 '18 at 09:35
1

You can set a query parameter after the page is loaded with JavaScript. (use history.pushState so its not reloading). Like:

history.pushState({}, "", "?bookmarked")

So when the navigation is from a bookmark, its with the ?bookmarked parameter, and when its a regular navigation you'll get it without any parameters.

Working example, Code for example

Edit: As pointed out in the comments, there are two problems with this approach.

  1. The URL bar in the browser will always include the ?bookmarked query parameter.
  2. When reloading, the server will get the ?bookmarked even when it's not from the bookmark. (can be worked around as pointed out in the answers to this question)
Mendy
  • 7,612
  • 5
  • 28
  • 42
  • Unfortunately, it does not work. It is always with `?bookmarked` parameter. May be you have to read about your **[function `history.pushState` in the documentation](https://developer.mozilla.org/en-US/docs/Web/API/History_API)**. – Bharata Aug 21 '18 at 17:07
  • The example is working fine in for me chrome, however I made an update so that it says on the page if it was loaded from the bookmark. – Mendy Aug 21 '18 at 18:22
  • It does not work! It is always with ?bookmarked! You should read the documentation. – Bharata Aug 21 '18 at 19:17
  • Let me explain, the '?bookmarked' will always be there, this is not the way to determine if it's from a bookmark! The way to check if it's from the bookmark is either by the server checking the URL 'it' received, or by JS checking 'before' adding the '?bookmarked' if there is a '?bookmarked' already. Please click the example link, you should see "Not From Bookmark", now bookmark it and click on the bookmark, you should now see "From Bookmark" BTW: I read the docs multiple times already, please let's try to comply with the stack overflow mission statement. – Mendy Aug 21 '18 at 19:59
  • It does not work! If you add a bookmark after the page was loaded then the URL is already with '?bookmarked'. I think you misunderstood something. – Bharata Aug 21 '18 at 20:13
  • That's exactly the point, the 'bookmarked' query is added after the page is loaded so when you bookmark it, it's with the 'bookmarked' query. Now when you load the page from the bookmark, the server gets the request 'with' the 'bookmarked' query. however, if you load the page from a link, even though the query is added its only by JS and the server doesn't get it. – Mendy Aug 21 '18 at 20:29
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/178475/discussion-between-mendy-and-bharata). – Mendy Aug 21 '18 at 20:34
  • That's exactly the point, which you misunderstood! The URL in a link should be the same like in a bookmark! They can not be different! – Bharata Aug 21 '18 at 21:01
  • Not at all technical explanation, but just visiting the site and refreshing says it's from a bookmark. – Jack Strosahl Aug 23 '18 at 15:51
  • @JackStrosahl, just reading the documentation from this function says _it has nothing to do with checking of bookmarks_. – Bharata Aug 23 '18 at 16:34
  • Clever technique. Although it's not perfect, it has a high likelihood of differentiating between A and B since most users will bookmark the page they are on rather than bookmarking from a link on a page. – rovyko Dec 13 '21 at 01:16