0

I am trying to access the details for the current url within my chrome extension, however I cannot even console them out.

This is what I have:

chrome.webRequest.onBeforeRequest.addListener(
function(details) {
    console.log(details.url);

},
{urls: ['*://*.mySite.co.uk/*'], types: ['main_frame']},
['blocking']
);

Which returns nothing in the console.

I am wanting to redirect a user based on the parameters found in the url. so how do i:

1) get the current url

2) if already contains correct parameter (location=123) then do nothing

3) if not correct parameter of (location=123) then change whatever parameter there, so maybe regex like location=/location=(.*)&/

If would be awesome if I could get that in a function that outputs a new details so I could just o this:

redirectUrl: details.url {
    redirectUrl: details.url 
}

Thanks guys.

update

here is the permission section in my manifest file

 "permissions": [
    "tabs",
    "webRequest",
    "*://*.mySite.co.uk/*",
    "webRequestBlocking"
 ],
JamesG
  • 1,552
  • 8
  • 39
  • 86
  • Please [edit] the question to be on-topic: include a **complete** [mcve] that duplicates the problem. Including a *manifest.json*, some of the background *and* content scripts. Questions seeking debugging help ("**why isn't this code working?**") must include: ►the desired behavior, ►a specific problem or error *and* ►the shortest code necessary to reproduce it **in the question itself**. Questions without a clear problem statement are not useful to other readers. See: "**How to create a [mcve]**", [What topics can I ask about here?](http://stackoverflow.com/help/on-topic), and [ask]. – Makyen Nov 21 '16 at 05:49
  • Your manifest is significant here - please add it to the question. You need 2 permissions for blocking webRequest, and **you need host permissions for the site**. – Xan Nov 21 '16 at 10:32
  • @xan added - see original answer – JamesG Nov 21 '16 at 15:18
  • 1
    Okay that seems clean, then is it the case that you're [looking in the wrong console](https://stackoverflow.com/questions/10257301/where-to-read-console-messages-from-background-js-in-a-chrome-extension)? – Xan Nov 21 '16 at 15:20
  • @Xan - I had no idea that console existed... You are a life saver If you post this as an answer You will win the internet points. – JamesG Nov 21 '16 at 15:30
  • Glad that helped, closed as duplicate. Give the well-deserved imaginary internet points to RobW! – Xan Nov 21 '16 at 15:38

0 Answers0