close default browser in nodejs

Using nodejs there is the open package to open a default browser, what is a good way to programatically close the default browser using nodejs or bash on ubuntu.

        var open = require('open');
open('https://www.youtube.com/watch?v=5RGxy2hdPJI', function (err) {
if (err) throw err;
console.log('The user closed the browser');
});

Then I would like for my video to play(simple). Then I would like to close the browser(should be simple).

I just used a bash script which works for my purposes. It is a little buggy in the functioning but accomplishes my intended outcome.

    #!/bin/bash
    for i in `seq 1 10`;
     do
     xdg-open 'https://www.youtube.com/watch?v=5RGxy2hdPJI'
     sleep 265
     done 
    pkill -x firefox
    exit 0