0

I was doing some chrome extension dev and I found linkurl method giving some strange url back like this "https://www.google.ca/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uact=8&ved=0CDQQFjAD&url=https%3A%2F%2Fdeveloper.chrome.com%2Fdevtools%2Fdocs%2Ftips-and-tricks&ei=41OEVfSXG4nioATdvrCAAQ&usg=AFQjCNHiSugE_b8f5LZbiamLQzS2Df2I9Q&sig2=acYqGi4bSiUgLeO4HwwM5Q&bvm=bv.96339352,d.cGU"

Is there any way we can get the proper url ?

My code is here

function genericOnClick(info, tab) {
  window.alert(info.pageUrl);
  var urlHandler =  info.linkUrl;
  chrome.tabs.create({url: urlHandler});
}

var contexts = ["page","selection","link","editable","image","video",
                "audio"];
for (var i = 0; i < contexts.length; i++) {
  var context = contexts[i];
  var title = "Test"
  var id = chrome.contextMenus.create({"title": title, "contexts":[context],
                                       "onclick": genericOnClick});
}
Achayan
  • 5,720
  • 2
  • 39
  • 61

1 Answers1

0

The "proper" URL is one of the parameters in the large URL, if you look closely - it's the "url" parameter. There are libraries that will take care of parsing the URL parameters and decoding for you if you want to get the proper URL to which that larger one redirects, or you can also do it manually :)

Edit: depending on what your use-case is, you can use the solution here How can I get query string values in JavaScript? or here Parse query string in JavaScript

You need to change the snippets slightly because they use the window.location variable instead of taking a string.

Community
  • 1
  • 1
bbill
  • 2,264
  • 1
  • 22
  • 28