0

Is it possible to modify the javascript code in chrome dev tools?

I have created this example, how can i prevent the element from being removed when dev tools are opened? https://jsfiddle.net/2nfw3rau/

var currentInnerHtml;
var element = new Image(); 
var elementWithHiddenContent = document.querySelector("#element-to-hide");
var innerHtml = elementWithHiddenContent.innerHTML;
element.__defineGetter__("id", function() { currentInnerHtml = "";});
setInterval(function() {    currentInnerHtml = innerHtml;                      console.log(element);   console.clear();                    elementWithHiddenContent.innerHTML = currentInnerHtml
}, 1000);
geierwally
  • 87
  • 1
  • 6
  • Note that `__defineGetter__` is a non-standard, deprecated JavaScript extension which was never cross-browser and probably isn't implemented for DOM elements (as opposed to JavaScript objects) even on the browsers that (used to) support it. – T.J. Crowder Apr 09 '16 at 15:49
  • Possible duplicate of [Editing in the Chrome debugger](http://stackoverflow.com/questions/5067532/editing-in-the-chrome-debugger) – Ocelot20 Apr 09 '16 at 17:20
  • I would never use a code like this, this is a very bad code and against the nature of web. I just want to know, how i can stop the setInterval from "removing" the website during dev tools are opened. – geierwally Apr 11 '16 at 17:48

1 Answers1

0

how can i prevent the element from being removed when dev tools are opened

You can't. The user is in control of their browser, not you. If they're using dev tools, they can remove the element (in any of several ways).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • The best you can do is keep checking if the element has been removed and re-add it. But then the user could probably figure out how you did that and stop it too. – vahanpwns Apr 09 '16 at 16:16
  • I don't believe that's what the user is asking based on the title. Seems like he wants to be able to "edit and continue" in such a way that allows him to prevent the element from being removed when debugging *himself*. – Ocelot20 Apr 09 '16 at 17:22
  • Ocelot20: You are right, i WANT to be able to see the website while dev tools are opened, thus seeing the source code. – geierwally Apr 11 '16 at 17:46