I am trying to make a chrome extension which redirects the user to modified link when user clicks the extension button.
I created manifest.json,icon file,popup.html and popup.js
But my code is not working.
I have read the answer to a similar question but still I'm not able to resolve the problem. Link--> How to modify current url location in chrome via extensions
Pseducode of what I am trying to do:
1.get url of current tab(suppose www[dot]xyz.com)
2.Modify the url (abcxyz[dot]com)
3.update the link and redirect to new link (go to abcxyz[dot]com)
This is what I've written so far....
// To get the url
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tabs) {
// Do something
var targ=tabs[0].url;
});
var toBeOmitted="xyz";
var toBeAddded="abc";
var newTarg=targ.replace(toBeOmitted,toBeAddded);
//to update to new url
chrome.tabs.query({ active: true, lastFocusedWindow: true }, function (tab) {
chrome.tabs.update(tab.id, {url:newTarg});
});
I am not able to debug it.