I was writing user script for Google Chrome that would automatically open a specific chat tab, but it’s not working,
I think that it is because the Chat.openTab is not specifically defined, because when i run the code in the javascript console it works fine.
CODE:
var face = "facebook.com"
var domain = document.domain
if (domain = face)
{
Chat.openTab("sam.sebastian1", "Seb")
}
The other answers point out that it should be
(domain == face), and this is an error.However, it is not what prevented the script from appearing to work as you expected.
The main problem is that Chrome userscripts cannot use JS defined in the target page. You must inject your code into the page, like so:
That was the basic answer. However, since this is Facebook, things are a bit more complicated.
Chatobject does not load right away.To get around these obstacles, we setup a timer, that doesn’t try to execute our code until the resource is found.
Like so: