1

I've written the following chrome extension to detect and what URL a user is on and process some data from a specific URL. Background.js contains the following code:

var triggerURL = "http://xxxxxxxxxxxxxxx/";

function SearchURL(theURL) {
  this.URL = theURL;
  this.checkURLorigin = function() {
    if (this.URL.indexOf(triggerURL) !== -1) {
      console.log("you're on the search page");
      return true;
    }
    else
      return false;
  };
  this.query = function() {
    console.log(this.URL);
    var index = this.URL.indexOf("q=");
    var searchQuery = this.URL.substr(index + 2);
    return searchQuery;
  };
}

chrome.webRequest.onBeforeRequest.addListener(function(details){
  var currentSearchURL = new SearchURL(details.url);
  console.log(currentSearchURL.checkURLorigin);
  if (currentSearchURL.checkURLorigin) {
    msg = currentSearchURL.query;
    console.log("you're on the search page, query = " + msg);
  }
},
{urls: [triggerURL + "*"], types: ["main_frame"]}, ["blocking"]);

console.log shows however that the code in the SearchURL object is not executed, instead the function's content are printed in the console. Why is this?

1 Answer 1

4

You are missing a (). The correct call should be

 msg = currentSearchURL.query();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.