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
Post a Comment