How to get the URL in Javascript when page is blocked

295 Views Asked by At

I am trying to build a bookmarklet that will grab the URL from a link that is blocked on my network and run a process on the query string parameters.

I have tried to use window.location.href, but all that is returned is URL of the browsers error page that is displayed, not the URL that generated the error (even though that URL is in the address bar up top.

I get nothing with document.referrer.

This is an example of a URL that this should work on:

https://ue.flipboard.com/usage?data=%7B%22prod_type%22%3A%22notification%22%2C%22event_category%22%3A%22email%22%2C%22event_action%22%3A%22click%22%2C%22event_data%22%3A%7B%22type%22%3A%2210today.media.sat.20210710.436.2%22%2C%22target_id%22%3A%22104t%2F0%22%2C%22url%22%3A%22https%3A%2F%2Fflipboard.com%2F%40businessinsider%2Flabor-shortages-and-calls-for-higher-pay-continue-across-the-us-v632ten2kt4p63a4%3Frefresh%3D1%22%2C%22method%22%3A%22web%22%2C%22redirect_url%22%3A%22https%3A%2F%2Fflipboard.com%2F%40businessinsider%2Flabor-shortages-and-calls-for-higher-pay-continue-across-the-us-v632ten2kt4p63a4%3Frefresh%3D1%22%7D%2C%22properties%22%3A%7B%22uid%22%3A%228606374%22%2C%22unique_id%22%3A%228606374%22%2C%22time%22%3A1626124956022%2C%22ab_tests%22%3A%22436_2%22%7D%7D

javascript:(function() {
            let cleanURL = new URL(window.location.href);
            console.log(cleanURL);
            let urlObj = cleanURL.searchParams.get("data");
            urlObj = decodeURIComponent(urlObj);
            let jsonObj = JSON.parse(urlObj);
            window.location.href=jsonObj.event_data.url;
}());

enter image description here

0

There are 0 best solutions below