Is it possible to persist CSS/JS modifications made to a remote resource when the page is reloaded, or to link a remote resource in DevTools to a local

Although I am aware of the Workspaces feature recently added to DevTools, it does not address my specific needs. For instance, when a page utilizes jQuery from a CDN and I make modifications to the library code, saving them by pressing ctrl-s only to find that the changes are lost upon reloading the page. Additionally, there are situations where I need to debug a site but do not have permission to alter any files.

My goal is not just to save changes like in saving CSS while browsing using Chrome Dev or Firebug, but rather to ensure that these modifications persist between page reloads.

Answer №1

You seem to have understood most of it, with just a small adjustment needed:

To make a change in the Styles pane (or in Sources), switch over to the Sources tab and open your modified file. Once it's open, press ctrl-s.

Next, simply right-click on the asset in the Sources list and select Save As... to save the updated file to your computer.

Please note that there is no way to modify a remote file without saving it to disk first; any changes made will only take effect upon reloading the file.

Answer №2

Utilizing workspaces gives you the ability to make edits to files linked to a specific local directory. However, it's important to note that serving local files is a requirement for this feature to function properly.

If you find yourself working with files that you can't easily access directly, I suggest configuring a tampering proxy tool like Burp. With a tool like this, you can quickly alter server responses and perform real-time search and replace operations such as changing

cdn.example.com/jquery-library.js
to localhost:8080/jquery-library.js in the HTML code. Once you've set up a local server (which is straightforward), you can then edit the script on your local machine!

This method is a useful way to preview modifications made on a local level against the production content, but it should not be used as a substitute for a proper testing environment.

Answer №3

Though challenging, it is indeed possible to achieve:

  • Begin by opening the resources and right-clicking on the folder with styles\resources (remember to click "allow" when prompted below the address bar)
  • Next, right-click on the specific resource and select "save as" (save it to the working directory you specified earlier)
  • Then, right-click on the same resource and choose "Map to file system resource" (using the same name as in the previous step, like all.css but without any extra identifiers)
  • Make changes to the styles using the dev tools.
  • After making modifications, refresh the page (only to find that your changes were not applied).
  • Navigate to the resources, locate your workspace folder and the corresponding resource (e.g. all.css).
  • Right-click on the resource and opt for "local modifications."
  • In the console that opens up, select "apply original content" and witness your styles being successfully applied =) This method may be intricate, so using a tool like Fiddler to replace resources with local files could be a better alternative.

Answer №4

If you're using jquery, here's a different approach you could take:

- Load the page for the first time and then set a breakpoint on line 1 in the sources tab - Reload the page, make your changes to the file, and save it (you'll notice that the page has paused at the breakpoint) - Click the play button to continue loading the page Your modifications should now be applied. Keep in mind that if you refresh the page again, these modifications will be lost.

I hope this alternative method proves useful!

Answer №5

After exploring Chrome's DevTools, it appears there is currently no straightforward way to achieve this task. It may be beneficial to refer to the documentation on saving and implementing local changes. The only feature that seems to endure page reloads is snippets, but it may not meet your requirements.

If a solution for this functionality becomes available in the future, I would eagerly welcome it. In the meantime, utilizing content scripts and similar methods may be the most effective approach.

Answer №6

My approach might not fit the traditional definition of an answer, but it's what works for me in getting as close as possible to meeting your needs.

First, I load the webpage in my browser and then save it locally by using the save as function. I make sure to save the entire page with its HTML, JavaScript, and CSS files.

If I need to make changes to the CSS, I edit the HTML file directly and link it (or them) to my development files.

After reloading the page, I can work on it according to your specifications by saving and then reloading the changes I've made.

This method does require full access to the files, and they are likely stored locally. However, I assume you wouldn't want to edit the actual web files online.

Once I've finished modifying the files, syncing my development files with the web files is a simple process.

Answer №7

If you're using Firefox, a great tool I recommend is Greasemonkey. It allows you to run JavaScript scripts on webpages and even change CSS dynamically. If you're new to Greasemonkey, here's a helpful guide to get started:

For Chrome users, a similar tool called Tampermonkey is available:

Answer №8

When working on my website, I like to use Apache in debug mode alongside Eclipse. This allows me to see changes reflected on the site immediately after saving a page.

Answer №9

Just a heads up, this code snippet can make use of the jQuery library (although it's not mandatory).

If you want to see the result, open your browser console.

function modifyStyles() {
  $("*").css("color", "blue"); /* Styling elements for development using CSS and JS */
  $("head").append("<script>console.log(\"restyle\")</script>"); /* Inserting JS script into header */
  var elements = document.querySelectorAll("*"); /* Selecting all elements in the document */
  var outerHTML = document.documentElement.outerHTML; /* Grabbing outer HTML of the document */
  var innerHTML = document.documentElement.innerHTML; /* Grabbing inner HTML of the document */
  return $.ajax() /* Making an AJAX request */
  .done(function(data) { /* Handling the response from the server */
    document.documentElement.innerHTML = outerHTML; /* Modifying the document with fetched data */
    console.log(data, innerHTML, outerHTML, $(elements)) /* Logging options and callbacks */
    /* $.each($(elements), function(index, value) { console.log(value) }); */
  })
};
modifyStyles();

Answer №10

Take a look at this link:

If you need to replace resources, the Resource Override extension is perfect for that:

  • Create a rule for the URL you want to modify
  • Edit the JS/CSS/etc within the extension
  • Reload as necessary!

You can even add a tab to the developer tools for more convenience.

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

What is the best way to configure redux-sagas and organize file hierarchy?

After learning how to install JWT and apply it to my React Native project, I realized that without proper state management, I had to pass the JWT token fetched from the login authentication as props down multiple levels, which became quite cumbersome. This ...

What is the best way to combine attributes in AngularJS?

I am looking to display a list of attributes as a comma-separated line in HTML: json { "city":"<b>londo</b>", "country":"<i>uk</i>", "zip":"123" } Since I need to render HTML markup, I am using the ngSanitize directive ...

(CSS/HTML) How to hover over an "li" element without affecting the text inside the "li" element

Looking for some assistance. I've created an unordered list with list items and applied the following CSS to it: li { opacity: 0.5; } li:hover{ opacity: 1; } The issue arises when I hover over a pixel from within a word in "li" - it stops hovering ...

The full-width header is generating a horizontal scrollbar

Why am I seeing horizontal scroll bars on Safari and Chrome when the header width is set to 100%? Here is the code snippet: window.onscroll = function() { scrollFunction(); }; function scrollFunction() { if (document.body.scrollTop > 400 || doc ...

Encountering "Error: Class constructor vA cannot be invoked without 'new'" when using Angular 10 Kendo Grid

I am currently working on integrating a Kendo Grid into my Angular application. However, I have run into an error when enabling the Kendo Grid component: vendor.4add67dadae0cd9152b9.js:16 ERROR Error: Uncaught (in promise): TypeError: Class constructor vA ...

How can you determine if a mouseover event is triggered by a touch on a touchscreen device?

Touchscreen touches on modern browsers trigger mouseover events, sometimes causing unwanted behavior when touch and mouse actions are meant to be separate. Is there a way to differentiate between a "real" mouseover event from a moving cursor and one trigg ...

Determine the Ratio by comparing shared keys within an array of dictionaries

Looking to create a function that can calculate ratios based on specific keys and control which keys are eligible for ratio calculation. num = [{"HCOName":8919,"timestamp":"2019-01-01T00:00:00.000Z","Territory":"USA"}, {"HCOName":8275,"timestamp":" ...

Importing a 3D Model Using Three.js

I've been trying to import a 3D model by following tutorials. I managed to successfully import using A-Frame Tags, but encountering issues with Three.js. The code snippets are from a tutorial on YouTube that I referred to: https://www.youtube.com/watc ...

Is there a way to transform this Json array into a format that JQuery can interpret easily?

Having a bit of trouble with this issue. I'm not entirely sure how to get it working correctly. According to Firebug, the Json object (or possibly array) from my ajax request appears as follows: { "jsonResult": "[ {\"OrderInList\":1}, ...

How can I access app.locals.<myvar> within routes/index.js in Express.js 4?

I am trying to access my own variable, `app.locals.port`, from the app.js file within my routes/index.js file. app.js: app.locals.port = 3001; var index = require('./routes/index'); app.use('*', index); // use router in ./routers/inde ...

Automatically updating div content using a static HTML page

Is there a way to refresh the content of an HTML div tag every 5 minutes without having to reload the entire page? <div id="pie"> <script src="index.js">// this script should be reloaded every 5 minutes </script& ...

Navigating the terrain of multiple checkboxes in React and gathering all the checked boxes

I am currently developing a filter component that allows for the selection of multiple checkboxes. My goal is to toggle the state of the checkboxes, store the checked ones in an array, and remove any unchecked checkboxes from the array. Despite my attemp ...

Converting a PHP multidimensional array to JavaScript

I'm facing an issue with printing data from a PHP array in a JavaScript function. The current setup is not producing the desired outcome. Here's how the data is being processed in PHP: $daten = array(); $anzahl = array(); $leads = array(); if ($ ...

Drag to rotate using JavaScript when the mouse is pressed down

I am experimenting with making a spinning wheel rotate as the user drags the mouse over it. The wheel consists of 3 pieces, so I have individually mapped each image to target the specific section of the wheel that I want to rotate. Currently, it is funct ...

What is the best way to update the content of a particular div and its associated link ID whenever the link is clicked?

I need to update the content of a div by clicking on an href link that includes an id named data. The issue I'm facing is that I can't access the id value within my script because it's passed within a function. How can I pass the data variab ...

Starting a line series from the beginning of the y-axis on a bar chart using chart.js

We have a new request from the business regarding the implementation of chart.js. Take a look at the image below, which shows a combination of bar and line charts. The line chart contains only a few data points. https://i.sstatic.net/mCSlR.png Within th ...

I have an empty array that needs to be filled with numbers

Currently, I am facing a challenge where I have an empty array and need to insert numbers from 1 to 20 into it. Once that is complete, the next step is to calculate the total sum of all these numbers. The stumbling block I am encountering lies in this sect ...

Check the feature that retrieves data from a `json` file

In my util file, I have a function that imports and checks whether a given sectionUUID has a video in the JSON file. import multipleVideos from '../data/videos.json' function hasSectionMultipleVideos (sectionUUID) { return multipleVideos.vide ...

Mapping memory for FirefoxOS is like equivalent strides

Is there a way to create a memory mapped file in FirefoxOS, Tizen or other pure-JS mobile solutions? In the scenario of a mobile browser where you have large amounts of data that can't fit in RAM or you prefer not to load it all at once to conserve R ...

The database has unfortunately registered an incorrect value for the "date" input after it was saved

When I select a date from the datepicker input field, it is being incorrectly saved in the database. I am selecting the date using the datepicker and then using AngularJS to send it to Spring MVC AngularJS: $scope.updateProjectDetails = function(detail) ...