How to customize XMLHttpRequest in Firefox's WebExtension

Recently, I've been attempting to override the XMLHttpRequest.protype.open method within Firefox's WebExtension environment. My current approach involves the following code snippet written in a 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);
};

Unfortunately, it seems that this code isn't functioning as intended. If you have any insights on how to successfully override the XMLHttpRequest.prototype.open method, your input would be greatly appreciated. Thank you!

Answer №1

If your scripts need to make XHR requests, they won't have direct access to the content script. Instead, your content script must insert a script containing your code into the page. This inserted script can then communicate with the content script through messages. For guidance on inserting a script into a page, check out this link: Inserting code into the page context using a content script. And for information on communicating between page scripts and content scripts, refer to this resource: https://developer.chrome.com/extensions/content_scripts (specifically the section on "Communication with the embedding page")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I make sure the webpage is fully loaded before using C#'s Webclient.DownloadString() function?

Currently, I am utilizing Webclient.DownloadString() to retrieve the full HTML content of certain webpages. However, an issue arises with pages that utilize Ajax for loading images and other elements. This delay causes a lag of around 3-4 seconds between ...

Setting a default date dynamically for v-date-picker in the parent component, and then retrieving the updated date from the child component

I'm working with a custom component that utilizes the v-date-picker in various instances. My goal is to have the ability to dynamically set the initial date from the parent component, while also allowing the date to be modified from the child componen ...

I am able to successfully test the REST service on localhost through a browser, however, I am encountering difficulties testing it

[OperationContract] [WebGet] public string GetImageStatusByName(string name) { panonestEntities context = new panonestEntities(); var p = context.Panoramas.Where(x => x.ImageName.Equals(name)).FirstOrDefault(); if (p ...

Encountering a NextJS error when attempting to access a dynamic route

I am currently working on a Next.js application that involves dynamic routing. I have encountered an error message stating: Error: The provided path X0UQbRIAAA_NdlgNdoes not match the page:/discounts/[itemId]`.' I suspect that the issue may be relat ...

Sending a JavaScript object as a prop in a React component

Currently, I am enrolled in a React course that requires us to pass a single JavaScript object as props to a React application. Here's the code snippet I have been working on: import React from 'react'; import ReactDOM from 'react-dom& ...

A guide on extracting a JSON data with a BigInt type using TypeScript

I am facing an issue with parsing a bigint from a JSON stream. The value I need to parse is 990000000069396215. In my TypeScript code, I have declared this value as id_address: bigint. However, the value gets truncated and returns something like 9900000000 ...

Live streaming updates directly from Firebase

In order to achieve real-time updates from Firebase, my objective is to retrieve comments from Firebase and display them on this.note. I seem to have made a mistake in the update() function. Here is the tutorial I followed: link. methods: { update(){ db.c ...

What is the best way to reset the size of an element in webkit back to its original dimensions?

I am having an issue with an element that changes to display absolute and covers its parent element on focus via javascript. However, when it goes back to its default state on blur, it does not return to its original position. This problem seems to only o ...

Adding and removing content through ajax operations

Currently, I am focused on implementing basic functionality for insert, add, delete, and update operations using ajax. I have made some progress with the functionality but my goal is to incorporate all features in a grid format. To achieve this, I have ...

A guide to fetching API Response by clicking a button

I'm trying to access a Public Quote JSON API and display the data on my HTML page. Even though I have some knowledge of JQuery Ajax method, my code seems to be facing issues in pulling the data into HTML. I'm looking for an explanation on what mi ...

Removing duplicate elements from an array using lodash

What is the best way to remove duplicate values from an array? var numbers = [1, 1, 5, 5, 4, 9]; I want my result to be: var numbers = [4, 9]; Is there a method in lodash that can help me achieve this? ...

Error message: "jQuery is not defined and occurs exclusively in Chrome."

I've been using the following code to asynchronously load my JavaScript in the head section: <script type='text/javascript'> // Add a script element as a child of the body function downloadJSAtOnload() { var element4= document.creat ...

Error encountered in NextJS: Trying to call res.unstable_revalidate which is not a function

I recently tried out a cutting-edge feature introduced in NextJS v.12.1 . The API itself is functioning correctly and can be accessed. However, I encountered a 500 error with the message res.unstable_revalidate is not a function. This issue persisted wheth ...

Is it possible to establish communication between JAVA and Javascript using Sockets?

Recently, I developed a Java application that generates some data and saves it in a text file on my computer. Instead of saving this data in a text file, I am looking to send it via Socket. Here is an example: Java public static void main(String argv[] ...

What is the best way to retrieve response data from php using ajax in a single file?

Trying to retrieve PHP response data using AJAX has been a challenge for me. My goal is to search for a specific string in testing.txt based on user input. If the string is found, PHP should output "1", but no matter what I attempt, AJAX consistently retur ...

Deciphering Encrypted JSON Data

In need of help with our app that generates complex JSON objects where properties and values are in hexadecimal format. How can we convert them back to strings? Example Object: { "636f756e747279": { "6e616d65": "43616e616461", "6 ...

"User-friendly Material-UI input field paired with a clear label

Seeking guidance on creating a text field with a label using the material-ui library. I am searching for something similar to this example: https://github.com/callemall/material-ui/blob/master/src/TextField/TextFieldLabel.jsx Unfortunately, I have been ...

Dealing with Sideways Overflow Using slideDown() and slideUp()

Attempting to use slideUp() and slideDown() for an animated reveal of page elements, I encountered difficulty when dealing with a relatively positioned icon placed outside the element. During these animations, overflow is set to hidden, resulting in my ico ...

Every time I try to set up the MailChimp pop-up javascript, I encounter an Uncaught Error message saying that Bootstrap tooltips need Tether and an Uncaught ReferenceError message

Utilizing Wordpress and Understrap. Upon inserting the following code: <script type="text/javascript" src="//downloads.mailchimp.com/js/signup- forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"> </script><script ty ...

substitute bullet point list item with new element

Assuming I have a list: <ul class="ul-1"> <li class="li-1">xx -1</li> <li class="li-2">xx -2</li> <li class="li-3">xx -3</li> </ul> Then I store it as: var list = $('.ul-1').html(); In ...