David Callanan
David Callanan

Reputation: 5958

JavaScript how to uniquely identify a website

I am writing an extension for chrome, but there might be regular JavaScript solutions to my question too.

My extensions enhances / extends the APIs available for websites.

For example, a website can request access to UDP sockets from my extension, and the user will be prompted for permission.

When the user is prompted if they want to give access for that feature to the site, I need to remember what sites have access to what features.

What is the best form of website identification, either obtainable in regular javascript, or using the chrome extension APIs?

My ideas

Upvotes: 0

Views: 36

Answers (1)

woxxom
woxxom

Reputation: 73526

The standard identification in all of the web for permissions is the URL origin i.e. scheme://host:port (the port is optional) which you can extract either via manual string manipulation or as new URL(urlString).origin, although this one is slower especially for superlong string like data URI.

To defuse the domain problem use the Public Suffix List, there are lots of libraries (link and link).

Upvotes: 1

Related Questions