I'm trying to create a simple chrome extension, to change the uploaded youtube title text to upper case or lowercase according to the selection from user.
App flow: https://www.youtube.com/upload -> Upload Video -> Prompt appears to provide video details (title, description etc)
Here is where I need to change the title text. Using the console on chrome with inspect I am able to get the text with document.querySelector('[aria-label="Add a title that describes your video]').firstChild)
ContentScripts.js
chrome.runtime.sendMessage(null, text, (response) => {
console.log("I'm from the send response function: " + response)
console.log("Title", document.querySelector('[aria-label="Add a title that describes your video"]').firstChild)
console.log("Description", document.querySelector('[aria-label="Tell viewers about your video"]').firstChild)
// chrome.storage.local.set({
// title: document.querySelector('[aria-label="Add a title that describes your video"]').firstChild),
// })
})
Manifest.json
"permissions": ["storage", "tabs","contextMenus", "search", "tts", "webRequest"],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["contentScript.js"],
"run_at": "document_end"
}
]
The following error message appears on contentScripts.js: Error handling response: TypeError: Cannot read properties of null (reading 'firstChild')
. Apparently, the call is being made before the element is set on the DOM. On content_scripts manifest, I have "run_at": "document_end", so it should run at the end. Based on the network calls, it seems to be https://studio.youtube.com/youtubei/v1/creator/get_creator_videos?*
contains the title and description values. Maybe I can wait for that POST call to be made then get the value.. or maybe there is a simpler way of achieving this?
https://developer.chrome.com/docs/extensions/reference/webRequest/