JavaScript and the Wii U Browser

Share this article

With all the talk of desktop, tablet, and mobile, there is another type of browser which tends to slip through the cracks – console browsers. In late 2012, Nintendo released it’s Wii U console, an eighth generation console which introduces a GamePad that features a second screen experience. The Wii U also features a NetFront browser powered by WebKit, making the programming model somewhat similar to that of Safari for iOS. This article explores the console’s browser, including the Wii U specific JavaScript API.

HTML5 Features

The Wii U likely possesses the most HTML5 compliant console based browser in existence today. Of course, this is to be expected, given that it is the newest. The Wii U scores a 258/500 on the HTML5 test – the highest among gaming browsers. While this number may not seem impressive (my installation of Chrome scores 448/500 with 13 bonus points), it is way up from the original Wii console’s score of 94/500. So what features does the Wii U support? For starters, there are a number of DOM Level 3 events for handling keyboard and mouse style inputs. The browser also supports touch events for interfacing with the GamePad’s touch screen. Some of the other supported features include SVG, Canvas 2D Context, Session History, Web Storage, and Server-Sent Events. A more comprehensive list of features can be seen on WiiUBrew.

Accessing the Wii U GamePad

The Wii U browser exposes a special object, wiiu.gamepad, which allows JavaScript to read the current state of the GamePad. Nintendo provides a nice example page, which, when loaded in the Wii U browser, extracts the state information and displays it on screen. The GamePad state is obtained by calling the wiiu.gamepad.update() method. According to WiiUBrew, it is safe to call update() from a timer to get real time updates. Therefore, your initialization code will resemble the example shown below. In this example, we are querying the state of the GamePad every 20 milliseconds.
window.addEventListener("load", function(event) {
  if (window.wiiu) {
    setInterval(function() {
      var state = window.wiiu.gamepad.update();

      // process the current state
    }, 20);
  } else {
    // browser is not a Wii U
  }
}, false);
After querying the state of the GamePad, you must ensure that the data is valid. If the query was successful, an isDataValid flag will be set to one, otherwise it will be zero. You can also determine if the GamePad is connected using the isEnabled flag. According to WiiUBrew, these flags are located on the wiiu.gamepad
object (i.e. wiiu.gamepad.isDataValid). However, the demo page provided by Nintendo checks for these flags on the state object returned from update(). Based on my own tests, both locations seem to be correct. So, using the Nintendo syntax, checking for valid data looks like the code shown below.
if(state.isEnabled && state.isDataValid) {
  // valid GamePad data
} else {
  // invalid GamePad data
}

Conclusion

This article has introduced some of the features of the new Wii U browser. Obviously, we haven’t fully covered reading from the touchscreen, buttons, and other input devices. Be on the lookout for an upcoming article which picks up where this one left off.

Frequently Asked Questions (FAQs) about JavaScript and the Wii U Browser

What is the Wii U Browser and how does it support JavaScript?

The Wii U Browser is a web browser developed by Nintendo for the Wii U gaming console. It supports HTML5, CSS3, and JavaScript, making it a versatile tool for web browsing and game development. JavaScript, a popular programming language, is used to create interactive elements on websites and games. The Wii U Browser’s support for JavaScript means that developers can create dynamic, interactive games and applications that can be accessed and played directly from the Wii U console.

How can I enable JavaScript on the Wii U Browser?

JavaScript is typically enabled by default on the Wii U Browser. However, if you find that JavaScript is not working, you can check its status in the browser settings. Navigate to the settings menu, find the option for JavaScript, and ensure that it is enabled. If it is not, simply toggle the switch to enable it.

Can I develop games using JavaScript for the Wii U?

Yes, you can develop games using JavaScript for the Wii U. The Wii U Browser’s support for JavaScript means that you can create interactive, dynamic games that can be played directly from the console. This opens up a world of possibilities for game development, as JavaScript is a versatile and widely-used programming language.

How does the Wii U Browser compare to other browsers in terms of JavaScript support?

The Wii U Browser offers robust support for JavaScript, similar to other modern web browsers like Google Chrome, Mozilla Firefox, and Safari. This means that websites and games developed with JavaScript should function properly and as intended on the Wii U Browser.

Are there any limitations to using JavaScript on the Wii U Browser?

While the Wii U Browser supports JavaScript, it may not support all features of the latest JavaScript versions. This is because the Wii U Browser is not updated as frequently as other web browsers. Therefore, developers should be mindful of this when creating games or applications for the Wii U Browser.

Can I use JavaScript libraries and frameworks on the Wii U Browser?

Yes, you can use JavaScript libraries and frameworks on the Wii U Browser. However, compatibility may vary depending on the specific library or framework. It’s always a good idea to test your application thoroughly on the Wii U Browser to ensure it works as expected.

How can I debug JavaScript on the Wii U Browser?

Debugging JavaScript on the Wii U Browser can be a bit challenging as it does not have built-in developer tools like other browsers. However, you can use console.log statements to output information to the console, which can help in debugging.

Can I use the Wii U GamePad with JavaScript?

Yes, you can use the Wii U GamePad with JavaScript. The Wii U Browser supports the GamePad API, which allows you to interact with the GamePad’s buttons and joysticks using JavaScript.

How can I optimize my JavaScript code for the Wii U Browser?

Optimizing your JavaScript code for the Wii U Browser involves following best practices for JavaScript development. This includes writing clean, efficient code, minimizing the use of global variables, and using requestAnimationFrame for animations.

Can I access the Wii U’s hardware features using JavaScript?

While the Wii U Browser supports JavaScript, it does not provide direct access to the console’s hardware features. However, you can use the GamePad API to interact with the GamePad’s buttons and joysticks.

Colin IhrigColin Ihrig
View Author

Colin Ihrig is a software engineer working primarily with Node.js. Colin is the author of Pro Node.js for Developers, and co-author of Full Stack JavaScript Development with MEAN. Colin is a member of the Node.js Technical Steering Committee, and a hapi core team member. Colin received his Bachelor of Science in Engineering, and Master of Science in Computer Engineering from the University of Pittsburgh in 2005 and 2008, respectively.

HTML5 GamingIntermediateWii U
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week