I am a JavaScript noob, pardon if my question is too silly or ill stated.
I am trying to figure out how to write a GreaseMonkey script that would detect whether there is a monaco editor on a webpage, and if there is one, then it would try to retrieve its contents. It seems to be easy to do as long as I have an instance of Monaco editor, but I am struggling to figure out how to find it from within GreaseMonkey script.
Basically, here is an example page with Monaco: https://app.coderpad.io/sandbox
From what I understand, a line like this is executed somewhere to initialize Monaco:
let editor = monaco.editor.create.create(...);
And then the reference to this editor
could either be dropped, or not saved in any standard place. At least I wasn't able to find it in document.*
or window.*
. I only found global variable window.MonacoEnvironment
, but it doesn't appear to contain any useful references to editor object itself.
I also read source code of Monaco and found monaco.editor.getEditors()
function. But I am JavaScript noob and can't figure out why it doesn't work - in Chrome console:
monaco.editor.getEditors()
Uncaught ReferenceError: monaco is not defined
Is there a way to import monaco namespace to make this expression to work?
In general, how can I find reference to editor
object(s) from within GreaseMonkey script, that would work reliably on any webpage using reasonably recent version of Monaco? Or is this even possible?
Thanks in advance for any help!