javascript - Chrome Extension to Redirect to URL with Parameter -


i'm attempting create chrome extension add parameter end of url if url matches given pattern (*://*.mydomain.com/s/*). below manifest file , background script have, cannot working. doing wrong?

manifest.json:

{   "manifest_version": 2,   "name": "search grid view",   "version": "0.1",   "description": "changes mydomain.com search grid view default",    "background": {      "scripts": ["background.js"]   },    "permissions": [     "tabs",     "webrequest",     "*://*.mydomain.com/s/*",     "webrequestblocking"   ]  } 

background.js:

chrome.webrequest.onbeforerequest.addlistener(   function(details) {              var currenturl = tabs[0].url;     var newurl = currenturl + "&style=gridview"     return { redirecturl: newurl};   },   {     urls: [       '*://*.mydomain.com/s/*'     ],     types: ['main_frame']   },   ['blocking']); 

thanks in advance advice!

  1. use debugger - click extension's background page on chrome://extensions page , switch sources panel.
  2. to obtain url use onbeforerequest's callback parameter
  3. check if url modified.

chrome.webrequest.onbeforerequest.addlistener(     function(details) {         return {             redirecturl: details.url +                  (details.url.indexof("?") == -1 ? "?" : "") +                 (details.url.indexof("&style=gridview") == -1 ? "&style=gridview" : "")         };     },     {urls: ['*://*.mydomain.com/s/*'], types: ['main_frame']},     ['blocking'] ); 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -