I am currently working on a JavaScript project to create a cookie. My main goal is to save the tab name as a cookie when the user clicks the extension icon while watching a YouTube video. This way, I can access the cookie from my Java program.
Although I'm using Chrome, I've encountered an issue where I can't see the cookie in the list even though the alert successfully displays. I'm seeking help to identify any potential issues with my code.
If anyone has alternative suggestions for transferring the tab name to my Java program, I would greatly appreciate hearing your ideas.
Thank you all for your assistance! Below is the code I have been working on:
chrome.browserAction.onClicked.addListener(run);
function run()
{
var cookieName, cookieValue;
cookieName = "Tab";
chrome.tabs.getSelected(null, function(tab)
{
cookieValue = tab.title;
createCookie(cookieName, cookieValue);
});
}
function createCookie(name, value)
{
var expires = new Date().getTime() + (1000 * 3600);
var domain = ";domain=.youtube.com";
document.cookie = name + "=" + value + ";expires=" + expires + domain + ";path=/";
alert(name + " = " + value + ". Date = " + expires);
}
UPDATE: I have made adjustments to my code utilizing Google's chrome APIs and achieved success!