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!
- use debugger - click extension's
background page
on chrome://extensions page , switchsources
panel. - to obtain url use onbeforerequest's callback parameter
- 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
Post a Comment