This forum is in read-only mode. The new forum is live at and registrations are open!

How to execute JavaScript code

  • Admin

    A lot of people mistake the ExecuteJS block for a builtin js interpreter.
    That block, being on the bottom part of the Add Block window, belongs to the set of blocks that control a Selenium-driven browser.

    If you instead wish to purely execute javascript using the builtin interpreter Jint you can do it like this:

    BEGIN SCRIPT JavaScript
    var a = 1+2;
    var b = 'hello';
    END SCRIPT -> VARS "a,b"
    • All the SINGLE and LIST variables you declared inside the OpenBullet scope will be automatically declared and initialized inside the JavaScript scope.
      NOTE: only the variables with legal names according to the js standard are declared (variables must not start with a number, must not contain spaces etc.)

    • The variables you extract using END SCRIPT -> VARS "a,b" will be initialized and declared in the OpenBullet scope, so you can have a full 2-way communication vector between OpenBullet and Jint.

    If you want to read more about this you can open the LoliScript documentation
    and select Flow Control -> Begin (end) Script

    Bonus: You can also use another scripting language, IronPython, which allows you to work with .NET assemblies using a pythonic syntax.

  • BEGIN SCRIPT JavaScript
    function getAlert() {
      // get all scripts
      var elem = document.scripts;
      // loop and check
      for (var i = 0, len = elem.length; i < len; i++) {
        var txt = elem[i].textContent.match(/alert\(['"]([^'"]+)['"]\)/);
        if (txt) { return txt[1]; } // if matched, return the alert text and stop
    var alert = getAlert();
    END SCRIPT -> VARS "alert"

    Will this work in order to get the alerts text? And how can I use the variable?

  • Admin

    Hey, in order to talk to the browser when using selenium you have to use the EXECUTEJS block.

  • Hey, how can i pass variable to JavaScript code in LoliScript?

  • if you have a variable <VARNAME> in Openbullet it is available as VARNAME in the Scriptblock

Log in to reply