Darshan Jadiye
Darshan Jadiye

Reputation: 241

How to detect if url protocol is http or https in chrome extension development?

I have the following code to detect the url from the browser tab. I want to detect the protocol of that url (is it http or https). How can I do this?

chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
    console.log(tabs[0].url);// returning the current url of tab     
});

Upvotes: 1

Views: 601

Answers (1)

punkrockbuddyholly
punkrockbuddyholly

Reputation: 9794

You could simply split the url on ":"

// protocol will be http or https
var protocol = tabs[0].url.split(":")[0];

Upvotes: 1

Related Questions