This might be a little bit of a weird question but I'm trying to make an extension that updates the youtube queue when you add a video from another window. I was thinking of just remaking the queue for youtube (I know that this would be a large task). How would I manually add a video to this queue?
There are two main problems that need to be solved to add a this feature.
Both Firefox and chrome provide extension storage for this purpose and this should solve the first problem.
https://developer.chrome.com/docs/extensions/reference/storage/
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage
For the second problem you need to write a content script that will either add your own button to YouTube or override the original add to watch queue button functionality. So that when clicked the url of the video will be added to extension storage.
You could then display the queue in the extension popup and when a video is played a message can be sent to the active window changing the location to the new video like so.
// popup.js
chrome.storage.sync.get(['queue'], (result) => {
const firstInQueue = result.queue.shift();
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {video: firstInQueue}, function(response) {
chrome.storage.sync.set({queue: result.queue}, () => {
console.log(`${result.queue.length} videos in queue`);
});
});
});
});
// content.js
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
document.location.href = request.video;
});
Overriding functionality on an existing site can be difficult and short-lived as if YouTube chooses to update its UI it may break you feature.
Looking at the network tab when adding a video to the queue reveals that a post request is made to https://www.youtube.com/youtubei/v1/playlist/create
this may be another area to look.