There is a certain site. Let's call it mysite.ru
So, I want to perform some functionality on the site and do not want to do it manually. so I wrote a JS script that ran on the page and it worked fine.
var node = document.createElement('div'); node.innerHTML = '\ <button onclick="start()" id="playBut" style="margin: 5px">play</button>\ '; document.getElementsByTagName('body')[0].appendChild(node); function start(){ // My code here }; and everything works great. But I’m tired of constantly running the code when the page is updated, so I decided to create a browser extension. Polazil on Habra and gathered that's what
{ "manifest_version": 2, "name": "MyExt", "version": "1.0.0.16", "permissions": [ "tabs", "activeTab", "https://mysite.ru/*" // Разрешить расширению обращаться к указанному адресу ], "content_scripts": [ { "matches": [ "https://mysite.ru/*" ], "js": [ "MyScript.js" ] } ], "browser_action": { "default_title": "MyExt" } } In the MyScript.js file, just the script that I described at the beginning.
But the problem is that when the extension is launched on the site I need, the button appears, but the start() function is not executed. I see in the console
Uncaught ReferenceError: start is not defined at HTMLButtonElement.onclick
start()function starts theF()function, which starts itself recursively. That is, even if I assign my function through this listener, then functionFwill be lost in the same way. so I need to give the injection exactly - iRumba