Skip to main content

Fixing not closing

·1 min

If you are like me and you want to use on your HTPC (computer connected to your TV) with something like the following flags:

--kiosk --user-agent="Mozilla/5.0 (X11; Linux x86_64; Xbox; Xbox One; Valve Steam Gamepad)" ""

You might have encountered an issue where, after watching a video, attempting to exit YouTube using the controller’s back/escape button proves ineffective.

Upon inspecting developer tools, you’ll discover that the browser refuses to execute window.close, claiming the window wasn’t opened by the script. Ironically the exit functionality works fine before watching videos and much javascript has had the chance to run.

Scripts may close only the windows that were opened by it.

So what do we do to work around this? Well lets just make sure the window is opened by a script in the first place.

Create a open-youtube.html file containing the following:

<!DOCTYPE html>
    <title>Open YouTube</title>
  <body onload="'', '_blank');window.close()">

Visit it with your browser of choice (either by double clicking or typing the path in the browser) and authorize the popup.

After this configure your shortuct open the new file instead:

--kiosk --user-agent="Mozilla/5.0 (X11; Linux x86_64; Xbox; Xbox One; Valve Steam Gamepad)" "C:\Users\John\Documents\open-youtube.html"

Enjoy a experience which actually closes!