0

I am trying to override the XMLHttpRequest.protype.open method in Firefox's WebExtension. I have written a following code in content script

var oldOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url, async, user, pass) {
    console.log("url :"+url+"\n method: "+method);
    oldOpen.apply(this,arguments);
};

But this code is not working. If anyone know that how to override the XMLHttpRequest.prototype.open method then please let me know.

sam
  • 481
  • 2
  • 8
  • 21

1 Answers1

0

The scripts making XHR requests have no access to the content script. Your content script has to insert a script with your code into the page. The inserted page script can communicate with the content script by messages. For details inserting a script into a page see here: Insert code into the page context using a content script. For details communicating page script and content script see here: https://developer.chrome.com/extensions/content_scripts (section "Communication with the embedding page")

Community
  • 1
  • 1