Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6227653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:15:38+00:00 2026-05-24T09:15:38+00:00

I was writing user script for Google Chrome that would automatically open a specific

  • 0

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") 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:15:38+00:00Added an answer on May 24, 2026 at 9:15 am

    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:

    function functionToInject () {
        function myCode () {
            /*--- This is where you put everything you want to do that 
                requires use of the page's javascript.
            */
            var face = "facebook.com"
            var domain = document.domain
            if (domain == face)
            {
                Chat.openTab ("sam.sebastian1", "Seb");
            }
        }
        myCode ();
    }
    
    function addJS_Node (text, s_URL) {
        var scriptNode                      = document.createElement ('script');
        scriptNode.type                     = "text/javascript";
        if (text)  scriptNode.textContent   = text;
        if (s_URL) scriptNode.src           = s_URL;
    
        var targ    = document.getElementsByTagName('head')[0] 
                    || document.body || document.documentElement;
        targ.appendChild (scriptNode);
    }
    
    addJS_Node ( '(' + functionToInject.toString() + ')()' );
    


    That was the basic answer. However, since this is Facebook, things are a bit more complicated.

    1. Facebook loads many iFrames, and the script will trigger on many of them.
    2. The Chat object 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:

    function functionToInject () {
        function myCode () {
            /*--- This is where you put everything you want to do that 
                requires use of the page's javascript.
            */
            var face = "facebook.com"
            var domain = document.domain
            if (domain == face)
            {
                Chat.openTab ("sam.sebastian1", "Seb");
            }
        }
    
        var waitForKeyElements  = setInterval (checkForElement, 500);
    
        function checkForElement () {
            if (typeof Chat != "undefined" ) {
                clearInterval (waitForKeyElements);
                myCode ();
            }
        }
    }
    
    function addJS_Node (text, s_URL) {
        var scriptNode                      = document.createElement ('script');
        scriptNode.type                     = "text/javascript";
        if (text)  scriptNode.textContent   = text;
        if (s_URL) scriptNode.src           = s_URL;
    
        var targ    = document.getElementsByTagName('head')[0] 
                    || document.body || document.documentElement;
        targ.appendChild (scriptNode);
    }
    
    addJS_Node ( '(' + functionToInject.toString() + ')()' );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a fairly basic GreaseMonkey script that locates text in a specific
I'm writing a script that will allow a user to input a string that
I am in the process of writing a script that builds upon user input,
I'm writing powershell script that simulates actions performed by user on the page. I
I'm writing a shell script to automatically add a new user and update their
I am writing a simple script that displays a dialog box when a user
I'm writing a PHP script that retrieves steam user profile information (for a servers
I'm writing a batch script that needs to install Microsoft Lync if the user
I'm writing a script where by a user registers his/her username, but a function
I'm writing a Greasemonkey script that has a fair few user settings (just using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.