How to access host from chrome extension

Pasaribu

I'm looking for a way to read the current tab's host (not just hostname).

I can read the url, but can't seem to find a reliable regex to extract out the host.

I can get the host from the window.location object, but I can't find a way to access that data from the extension.

Rob W

Given an URL, you can use the URL constructor to parse it and extract the parsed URL components. For instance:

// Just an example, there are many ways to get a URL in an extension...
var url = 'http://example.com:1234/test?foo=bar#hello=world';
var parsedUrl = new URL(url);
console.log(parsedUrl.host);

// Or if you want a one-liner:
console.log(new URL(url).host);
Open the JavaScript console, and you'll see "example.com:1234" (2x).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to access an iframe from chrome extension?

How to access chrome storage from multiple HTML files in a chrome extension

Access Dynamics from a Chrome extension

How to access angularjs root scope from chrome extension

How to distribute a Native Messaging Host with Chrome Extension

How to bundle a Native Host with Chrome Extension and publish it?

Access to website data from chrome extension

Secure access to api only from chrome extension

Access icon image from html in chrome extension

Access to Chrome extension elements from frontend

Access to all request from chrome extension level

In chrome extension, how to obtain an access token from a gmail user other than current chrome user?

Chrome extension: is there a ways to access the $0 (the selected console element) from an extension?

Chrome Extension - How to access webcam and Audio at intervals?

Native messaging from chrome extension to native host written in C#

How to read current page's HTML to access an element from a Chrome extension?

Chrome Extension Access Xively

How to read file from chrome extension?

How to Call an OnBlur Method from a Chrome Extension

How to release chrome extension from GitHub repository

chrome extension needs offline access from server side

Access global js variables from js injected by a chrome extension

access website localStorage from chrome extension popup open

Can I get access to localStorage of site from chrome extension?

Access DOM elements inside iframe from chrome extension

Access Google Cloud SQL database from Chrome extension

Access 'Chrome dev-tool mobile emulator' from custom extension

How to access server running in VirtualBox from the host?

How to access host component from directive?