Going through a greasemonkey script

I know that firebug does not have access to greasemonkey scripts, but I was wondering if there is a way to show firebug script and set a breakpoint. I would like to be able to eventually execute the scripts I'm working on.

Similar note: is there a way to test scripts without having to wait every 4 seconds to install it?

+4
source share
3 answers

The simple part:

โ€œOn a similar note: is there a way to test the scripts without having to wait 4 seconds each time to install it?โ€

Yes!

  • Make sure Greasemonkey 9.0 or later is installed.

  • Make sure you have an editor with GM. You can set this in GM options or open about: config and install greasemonkey.editor , for example D:\Program Files\TextPad\TextPad.exe , but any decent program editor should do it.

  • Now edit the script, open the GM Script -Manager and click the corresponding Edit button. Your editor should open with the correct file uploaded, and any changes you make will take effect immediately, every time you save the file.

  • Beware that changes made to the @require directives this way will still not take effect. That is, the new file will not be copied and not used. You still need to uninstall / reinstall in order to get @require changes.


"I was wondering if there was a way to show the script firebug and set a breakpoint. I would like to be able to run the scripts I'm working on in the end."

There is a new add-on, FireBugMonkey , which can help (I still have to try).

The discussion of how Firebug works well on GM scripts has been going on for over 4 years. Here is the last / current question in the Greasemonkey-Dev group .

In the near future, there is no way to execute GM scripts that use GM_ functions .

You can get around this, for parts of the code that donโ€™t use such functions, by entering this code on the landing page where Firebug can see it.

For example, structure your code as follows:

 function localMain () { /*--- Put EVERYTHING inside this wrapper, functions and variables. Call or use nothing else that defined in the GM script here. You can use objects in the source page scope, though. */ console.log ("Hiya!"); } 


Then in Firefox you can use unsafeWindow.localMain = localMain; to enter the code, Firebug will see it.

unsafeWindow.localMain(); runs the code from GM, localMain(); launches it from the Firebug console.

Remember that this method provides a route for malicious JavaScript (from the landing page) to gain elevated privileges and potentially pwn your system (one of the reasons GM was moved to the sandbox in the first place). But, itโ€™s quick and easy when you are targeting reliable pages.

~~~
Alternatively, you can enter a script as follows:

 var scriptNode = document.createElement ("script"); scriptNode.textContent = localMain.toString() + "\n localMain ();"; document.body.appendChild (scriptNode); 

This method works in all relevant browsers.

~~~
Libraries such as jQuery can be copied or entered in a similar way.

+4
source

I know that firebug does not have access to greasemonkey scripts, but I was wondering if there is a way to show firebug script and set a breakpoint. I would like to be able to eventually execute the scripts I'm working on.

It is not possible to set Firebug breakpoints for custom atm scripts, but John Barton (Firebug) and others are planning a way to make this possible, so pay attention to this in the future!

Similar note: is there a way to test scripts without having to wait every 4 seconds to install it?

If you use Scriptish , there is no delay during installation.

+1
source

Try Venkman Debugger JS. I'm not sure if he has access to scripts, but worth a try. One more thing to check: open / enable Firebug and stick on a few "debuggers"; to make sure he picks her up. These are some ideas, I have not tested them yet.

0
source

Source: https://habr.com/ru/post/1342732/


All Articles