I am working on a chrome extension where I want to inject some piece of text into monaco code editor present on leetcode.
I am tring to access the monaco api through chrome extension but I am failing to do so, but if I type window.monaco
in console of browser it shows the monaco object.
Following is the code I am using for accessing monaco object
manifest.json
{
"manifest_version": 3,
"name": "LeetCode Template Injector",
"version": "1.0",
"description": "Insert algorithm templates into LeetCode editor.",
"permissions": ["activeTab", "scripting"],
"action": {},
"content_scripts": [
{
"matches": ["https://leetcode.com/problems/*"],
"js": ["content.js"]
}
]
}
content.js
function checkMonacoEditor() {
const interval = setInterval(() => {
if (typeof monaco !== "undefined" && monaco.editor.getModels().length > 0) {
console.log("monaco editor found");
} else {
console.log("Waiting for Monaco editor...");
}
}, 1000);
}
window.addEventListener("load", function () {
checkMonacoEditor();
});
Here is a screenshot of my browser console