I'm writing an extension for watching videos on YouTube. A site opens with a timer in which the YouTube iframe is located. I just need to play the video. I do it with a click. The problem is that it doesn't work. Access to the iframe is in the manifest. The click happens, the screen blinks for a second, and nothing happens. It is interesting that sometimes it works without problems. I do not understand what the problem is.
manifest.json:{"manifest_version": 2,"name": "test", "description": "test", "version": "1.0", "permissions": ["tabs","storage","<all_urls>","activeTab"], "content_scripts": [ {"matches": ["<all_urls>"],"js": ["background.js"],"run_at": "document_end","all_frames": true } ],}bacground.js:
const delay = millis => new Promise((resolve, reject) => {setTimeout(_ => resolve(), millis)});async function test(){var url = window.location.toString();var ytframe = "www.youtube.com/embed";var resultytframe = url.match(ytframe); if(resultytframe==ytframe){ document.querySelectorAll("button[class='ytp-large-play-button ytp-button']")[0].click(); }}test();Also, everything will work if I make a physical mouse click anywhere(besides the play button) or write something to the console before work background.js.Video for example: https://youtu.be/rlf0eVyPf8w