javascript - get html page as response from url inside an extension -


i developing extension in whatever request coming want change request parameters , send dummy request server response. eg. if original request loaded www.abc.com/eg.php?user="some code", want change www.abc.com/eg.php?user="ritubala" , html page in response further processing inside extension.. used these codes given in following url return html content string, given url. javascript function causing recursion... in short want html code url inside extension...plz help

use nsitraceablechannel, note copy of content being loaded.

if abort request aborts giving copy.

here's me using nsitraceablechannel: https://github.com/noitidart/demo-nsitraceablechannel

what think want this:

const { ci, cu, cc, cr } = require('chrome'); //const {interfaces: ci, utils: cu, classes: cc, results: cr } = components; cu.import('resource://gre/modules/services.jsm'); cu.import('resource://gre/modules/devtools/console.jsm');  var observers = {     'http-on-examine-response': {         observe: function (asubject, atopic, adata) {             console.info('http-on-modify-request: asubject = ' + asubject + ' | atopic = ' + atopic + ' | adata = ' + adata);             var httpchannel = subject.queryinterface(ci.nsihttpchannel);             var requesturl = httpchannel.uri.spec             if (requesturl.indexof('blah')) {                 //httpchannel.cancel(cr.ns_binding_aborted); //this how abort if use redirectto don't need abort request                 httpchannel.redirectto(services.io.newuri('http://www.anotherwebsite/', null, null));             }         },         reg: function () {             services.obs.addobserver(observers['http-on-modify-request'], 'http-on-modify-request', false);         },         unreg: function () {             services.obs.removeobserver(observers['http-on-modify-request'], 'http-on-modify-request');         }     } };    //register observers (var o in observers) {     observers[o].reg(); } 

note redirectto function ff20+ https://developer.mozilla.org/en-us/docs/xpcom_interface_reference/nsihttpchannel#redirectto%28%29

so combine example nsitraceablechannel demo , you'll have want.

if don't want redirect can abort request, document of request , xmlhttprequest new page gives source first , doesnt load tab, , modify source load document.

or instead of xmlhttprequesting it, abort request, redirectto new page , modify tab. tab of channel see solution here:

security error when trying load content resource in firefox addon (sdk)

also http requests extension see snippet: https://gist.github.com/noitidart/9088113


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -