How to make a browser extension which can join a game (Javascript)

Ummm I wanted to make my own so I could join specific servers with a gameId but looked around and found there was no explanation as to how extensions join the games.

So I decided to make this just in case some random person in 6 years time decides they want to make a extension which joins the game.

TO JOIN WITH A SPECIFIC GAME ID PUT IT IN THE SEARCH BAR AT THE TOP OF THE PAGE

Code:

Loader Script

var s = document.createElement('script');
s.src = chrome.runtime.getURL('test.js');
s.onload = function() { this.remove(); };

(document.head || document.documentElement).appendChild(s);

WorkerScript

function GetURLParameter(sParam){
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('?');
    for (var i = 0; i < sURLVariables.length; i++){
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam){
            return sParameterName[1];
        }
    }
}

function main(){
    var PlaceID = location.href.match(/\/(\d+)\//g);
    PlaceID = String(PlaceID).match(/\d+/g);
    let gameid = GetURLParameter("gameId");

    if (!gameid || document.getElementById("navbar-search-input").value){
        gameid = document.getElementById("navbar-search-input").value
    }

    if (gameid && PlaceID){
        Roblox.GameLauncher.joinGameInstance(parseInt(PlaceID,10), String(gameid));
    }
}

function Start(){

    var JoinButton = document.getElementsByClassName("btn-common-play-game-lg btn-primary-md btn-full-width")
    
    try{
       var Clone = JoinButton[0].cloneNode(true)
       Clone.lastChild.innerText = "Join Game Id"
       Clone.lastChild.className = null
       Clone.id = "JoinID"
       Clone.style.width = "25%"
       Clone.style.paddingleft = "35%"
       document.getElementsByClassName("server-list-options")[0].appendChild(Clone)
       Clone.addEventListener("click", main);
       style = Clone.style
    }
    catch{
       setTimeout(Start,0.1)
    }
    }

    Start()

Manifest.json

{
  "manifest_version": 3,
  "name": "Put its name here",
  "description": "Base Level Extension",
  "version": "1.0",
  
  "permissions": [
    "scripting",
    "activeTab"
  ],
  
  "web_accessible_resources": [{
    "resources": ["worker script name with .js at end"],
    "matches": ["<all_urls>"]
  }],

  "content_scripts": [
    {
      "matches": ["https://*.roblox.com/games/*","https://*.roblox.com/users/*"],
      "js": ["loader script name with .js at end"]
      
    }
    
  ]
 }

This is all probably a bit messy but uhh hope it’s ok. Thanks

You can view the WorkerCode here but it was intended for tamper monkey:
https://github.com/mawesome4ever/GameLauncherTamperMonkey/raw/master/Join.user.js

Credits to mawsome4ever though for the WorkerCode :slight_smile:

8 Likes

Quick question, how did you find this function? Is there an API on the Roblox module somewhere?

There’s no documentation here:

image

1 Like

well I was messing around in the console and just found it by accident. The rest so the Place Id bit and gameId was filled in by This github user

1 Like

I know this is a old topic but you can easily find by looking at the source code in developer tools.

For example to edit the place you can use this function.
image

Most of the scripts are in the HTML file you just gotta find them.
You can press CTRL + F and type Roblox. and look through all the results

1 Like