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?