javascript - Chrome extension messaging with XMLhttprequest object fires more then once -


im developing chrome extension (developer tool) , injection code directly in website:

(function (send) {      xmlhttprequest.prototype.send = function (method, url, async) {           send.call(this, method, url, false);          document.dispatchevent(new customevent('data', {              detail: {                 data_1: 'hello world'             }          }));      };   })(xmlhttprequest.prototype.send); 

this code listens requests websites , sends message (through content script) message script. problem messages pile up. on first request 1 message, on second 2 messages resulting in 3 messages total, 6 , on. why pile way?

the message goes through "content" script:

document.addeventlistener('data_2', function(e) {   sendobjecttodevtools({data_3: e.detail.data_1 });  }); 

and received "message" script:

port.onmessage.addlistener(function(message) {  ...  if (message.data_3) {  //do stuff  ... 

ps. not iframe problem or scripts being loaded more once.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -