Ubuntu start Node.js server and open Chrome in kiosk mode

06
2014-04
  • J4G

    I'd like for a computer to immediately start a Node.js application on boot. I'd then like Chrome to open in Kiosk mode, but only after the server has been started. Looking on the Ubuntu Stack Overflow, I found a way to execute a script on startup

    Adding a line to your cron like this:

    @reboot /path/to/script

    will execute that script once your computer boots up.

    I thought I could do this with a .sh script, but I'm new to Linux. If I were to write something like this:

    node server.js
    chromium-browser --kiosk http://example.com
    

    Would the chromium-browser command not execute until the node server was completely started?

  • Answers
  • nerdwaller

    Have you tried that? If so, what was the result?

    I would expect that if you had tried that, it failed. That's because the process node server.js never ends to move on. Typically in this case, you would use node server.js & to send the process to the background; however, that does not mean that the server is ready.

    To actually know that, your best bet is to use the listen callback to execute the system command. For example:

    var http = require("http");
    
    var srv = http.createServer(...);
    srv.listen(8000, ExecuteChromium);
    
    function ExecuteChromium() {
        exec("chromium-browser --kiosk http://example.com", function(error, stdout, stderr) {
            console.log("stdout: " + stdout);
            console.log("stderr: " + stderr);
            if (error !== null) {
                console.log("exec errror: " + error);
            }
        });
    }
    

    Note: This isn't tested as it stands, just looked at some docs an an SO answer to execute a command.


  • Related Question

    Chrome in Linux Ubuntu stays in Full screen mode
  • Roland

    I've recently installed the latest version of Chrome for Linux on my Ubuntu 9.10 installation. The only problem is is that it stays in Full Screen mode no matter what I do. I pressed F11 but it does not want to return to normal mode. I even completely uninstalled it using synaptic package manager en re-downloaded it and still nothing. Any suggestions will be welcome.


  • Related Answers
  • Mike Graf

    You might try to remove your chrome config dir:

    rm -rf ~/.config/google-chrome
    

    Deleting chrome via synaptic would not have deleted it.

    • NOTE: this will uninstall all of your extensions and remove their data. There is another answer that talks about replacing the "bottom","left" etc.. Use that if you need to retain your extension data.
  • Steve Bosman

    load the file "~/.config/google-chrome/LocalState" into a text editor and change the values under "window_placement" so that the window will be smaller than your screen size, e.g I chose "bottom":500, "left":10, "right":1000, top:"50".

  • sudheer

    Few other ways to solve this problem other than deleting the ~/.config/google-chrome dir completely.

    I faced the same problem on Centos 6.3 with Chrome version 24.0

    The solution that I found : 1. The easiest way:

    Exit chrome. Either by killing the command (from top command or using kill -9 ) or switch to some other tasks (using alt-tab), and then right click on the chrome tab and close.

    And the delete the Preference file from Defaults dir

     # rm -f ~/.config/google-chrome/Defaults/Preferences
    

    (or move the file to some other dir # mv ~/.config/google-chrome/Defaults/Preferences /var/tmp) And start the chrome again. If you try this way, you will loose some setting like your login to google etc. But you won't loose your history or plugins..

    2. The other solution:

    Exit chrome. Edit the ~/.config/google-chrome/Defaults/Preferences file. Seach for "window_placement", change the value of "right" which you can find inside the "window_placement" section. You can find the current value to be the pixel size of your screen. Reduce the value by 100 pixel. (eg: if the value was 1280, change that to 1180) Save the file, and start chrome again.. You are not in full screen mode any more and you won't loose any thing if you try this option.

  • user68163

    I had a similar problem on a dev build. Try scrolling to the top of the page and then putting your mouse pointer at the top of the screen and THEN hit F11. It may work it may not.