luciopaiva / witchcraft

Inject Javascript and CSS right from your file system. Think GreaseMonkey for more advanced users.
https://luciopaiva.com/witchcraft
MIT License
254 stars 18 forks source link

Cannot assign variables to the window or document scope? #29

Closed goahe closed 3 years ago

goahe commented 3 years ago

Hi,

Nice work. A question, though:

<!-- https://mydomain.com -->
<html>
  <body>
    <video src="somevideo.mp4">
    <script>
      window.onload = () => 
        document.querySelector('video').play(); // PLAY: I'm not seeing this event...
    </script>
  </body>
</html>
// mydomain.com.js
var video = document.querySelector('video');
video.play = function () {
    console.log('video play called from root window'); // PLAY: ... here
    return this.apply(video);
  }.bind(video);

Why am I not seeing the PLAY event, while I've supposedly overridden the function of the video object?

This works fine in the debugging console of (in this case) Chrome, but not with the plugin.

Any help would be appreciated.

I'm guessing it's related to the fact that I do not seem to be allowed to assign any variables to the javascript in window. When I try to assign something like this:

// mydomain.com.js
window.somedata = {foo: 'bar'};

Opening the console on that window and typing this:

console.log('window.somedata.foo);

Results in:

undefined
goahe commented 3 years ago

Nevermind; here's the answer

also mentioned in the faq