Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the current domain name in Chrome when the page fails to load

If you try to load with Chrome: http://sdqdsqdqsdsqdsqd.com/

You'll obtain:

ERR_NAME_NOT_RESOLVED

I would like, with a bookmarklet, to be able to get the current domain name and redirect it to a whois page in order to check if the domain is available.

I tried in the console:

window.location.href

but it outputs:

"data:text/html,chromewebdata"

Is there any way to retrieve the failed URL?

like image 993
mattspain Avatar asked May 01 '15 14:05

mattspain


2 Answers

The solutions given by others didn't work (maybe because I was getting a different error or have a newer version: Chrome 55):

document.querySelector('strong[jscontent="hostName"]').textContent

but the same can be achieved via:

document.querySelector('#reload-button').url

A potentially more future-proof version (from Thomas's comment)

loadTimeData.data_.summary.failedUrl

So a cross-version solution incorporating all workarounds:

var url = (l‌​ocation.href === 'data‌​:text/html,chromeweb‌​data'
    && loadTimeData.data_.summary.failedUrl
    || document.querySelector('#reload-button').url
) || location.href;

var hostname = (l‌​ocation.href === 'data‌​:text/html,chromeweb‌​data'
    && loadTimeData.data_.summary.hostName
    || document.querySelector('strong[jscontent="hostName"]').textContent
) || location.hostname;
like image 116
TWiStErRob Avatar answered Sep 20 '22 12:09

TWiStErRob


On the Chrome error page, location.href doesn't point to the domain you tried to visit, since it's an internally-hosted page.

However, the domain name you tried to visit is available if you expand the "Show Details" link.

You can run this code in console (or a bookmarklet) to parse out the domain name:

document.querySelector('strong[jscontent="hostName"]').textContent
like image 35
nderscore Avatar answered Sep 22 '22 12:09

nderscore