javascriptreactjshttpreferrer

How to get exactly url from document.referrer?


I am using React and I am getting the document referrer using

document.referrer

However when I am directed to my url from google.com, I am just getting the domain in document.referrer instead of something like this: https://www.google.com/search?q=fb&rlz=1C1CHBF_enIN850IN850&oq=fb&aqs=chrome.0.69i59j46i199i291i433j0i131i433l2j0i395j69i60l3.1007j1j9&sourceid=chrome&ie=UTF-8.

Is there someway I can get the entire URL including pathname and query string? Thanks in advance.


Solution

  • Websites can set a Referrer-Policy. If they don't then, as of version 85, Chrome defaults to strict-origin-when-cross-origin. (Other browsers will have their own defaults, but Chrome's marketshare makes it worth highlighting)

    This means that the referrer information will include only the origin and not the full URL.

    This is a feature designed to protect the user's privacy.

    There is no way around it unless you control the site that controls the link (in your example: www.google.com).