Twitch Extensions with Phaser: Build Guide
In this article
Creating a Twitch Extension with Phaser lets you build interactive overlays, panels, or mobile components that run inside a broadcaster's channel using the same game engine you already know. You'll get a live canvas that can react to channel events and viewer input. Before you start, you need a Twitch developer account, a basic understanding of JavaScript and Phaser 3, and Node.js installed on your machine.
What You'll Need
- A Twitch account with two-factor authentication enabled (required for developer registration).
- Node.js and npm installed (version 14 or newer recommended).
- Phaser 3 library files (you can install via npm or use a CDN in your test page).
- A code editor (VS Code or similar).
- Twitch Developer Rig (optional but recommended for local testing) – download from the official Twitch developer site.
- An HTTPS server for final testing (Twitch requires HTTPS for production, but localhost works for development).
Step-by-Step
- Create a Twitch Developer Application – Go to dev.twitch.tv/console/apps and click “Register Your Application”. Name it, set the OAuth Redirect URL to
https://localhost:8080(or your local test port), and choose “Extension” as the type. Save the Client ID – you'll need it later. - Create an Extension Version – In the same developer console, go to “Extensions” > “Create Extension”. Choose a name, set the extension type (Panel, Overlay, or Mobile), and select the anchor (video or component). For a first project, choose “Panel” – it's the simplest to test.
- Set Up Your Project Folder – Create a new directory and initialize npm:
npm init -y. Install Phaser:npm install phaser. Also install the Twitch Extension helper library:npm install twitch-ext(or use the CDN version from the Twitch developer docs). - Create the Basic HTML File – Make an
index.htmlthat loads Phaser and the Twitch extension script. Include a<div id="game"></div>and a script tag for your main JavaScript file. The Twitch extension script must be loaded before your game code. - Write the Twitch Extension Initialization – In your main JS file, call
window.Twitch.ext.onAuthorizedto get the authentication token and user ID. Then start your Phaser game inside the callback. Example:Twitch.ext.onAuthorized(function(auth) { new Phaser.Game(config); }); - Configure Phaser for the Extension – Set the Phaser game width and height to match your extension's iframe size (e.g., 300x300 for a panel). Use
type: Phaser.AUTOand set the parent to the#gamediv. Make surebackgroundColoris set to a transparent or dark color that fits Twitch's UI. - Add a Simple Scene – Create a scene with a basic sprite or text. For example, add a text object that says “Hello Twitch”. This verifies that Phaser is rendering inside the extension.
- Test Locally with the Developer Rig – Download and run Twitch's Developer Rig (from the official Twitch developer site). In the Rig, add your extension version and set the local test path to your project folder. The Rig will serve your files over HTTPS and simulate the Twitch environment.
- Handle Extension Events – Use
Twitch.ext.onContextto get the current context (like theme, video, etc.). Also listen forTwitch.ext.onErrorto catch any issues. You can also useTwitch.ext.rig.logto console.log in the Rig. - Build for Production – When ready, bundle your JavaScript (using a bundler like Webpack or Parcel) into a single file. Upload this file, along with your HTML and any assets, to the Twitch extension version in the developer console.
- Submit for Review – In the developer console, fill in the required metadata (description, screenshots, etc.) and submit your extension for Twitch review. Once approved, it becomes available for broadcasters to install.
Common Mistakes
- Forgetting to load the Twitch extension script before Phaser – The extension script must be present before you call any Twitch.ext methods.
- Using a non-HTTPS server for testing – Twitch extensions require HTTPS, but localhost is an exception. If you test on a network IP, it will fail.
- Not handling the onAuthorized callback – Phaser will start before the auth token is ready if you don't wait. Always start the game inside the callback.
- Setting the wrong iframe size – If your Phaser canvas is larger than the extension iframe, it will be cut off. Check the extension type's recommended dimensions (e.g., 300x300 for panels).
- Using DOM elements that conflict with Twitch's UI – Avoid overlaying interactive elements outside the Phaser canvas unless you handle z-index carefully.
Tips
- Use the Developer Rig's built-in simulator to test different themes (light/dark) and roles (viewer, broadcaster, mod) – this helps you design for all contexts.
- Keep your Phaser scene lightweight – extensions run in an iframe on the broadcaster's page, so performance matters. Avoid heavy particle effects or large textures.
- Use
Twitch.ext.rig.logfor debugging in the Rig – it shows up in the Rig's console. - For overlays, make your Phaser background transparent by setting
transparent: truein the Phaser config, so the video shows through. - Test on both desktop and mobile – Twitch extensions can run on mobile apps, but the iframe size and touch input differ.
- Read the Twitch extension documentation on allowed APIs – you can't access the DOM of the parent page, only the extension's own iframe.
Troubleshooting
Phaser doesn't load or shows a blank screen – Check the browser console for errors. Make sure Phaser is correctly installed and the path to the library is correct. Also verify that the Twitch extension script is loaded first.
Twitch.ext is undefined – This usually means the extension script wasn't loaded, or you're testing outside the Developer Rig or a proper extension environment. Use the Rig for testing.
Authentication fails – Ensure your Client ID matches the extension's version. Also check that you have the correct OAuth redirect URL set in the developer console.
Game renders but doesn't respond to Twitch events – Make sure you're calling Twitch.ext.onContext and other listeners inside the onAuthorized callback, and that you're using the correct event names.
Extension works in Rig but not in production – Check that your uploaded files are all included (HTML, JS, assets) and that the paths are relative. Also verify that your production server uses HTTPS and that the extension version is set to “Hosted Test” or “Released” correctly.
Frequently Asked Questions
Can I use Phaser 2 instead of Phaser 3?
Yes, but Phaser 3 is the current version and has better documentation and support. The integration steps are similar, but you'll need to adapt the config syntax.
Do I need to use the Developer Rig?
No, but it's highly recommended. It simulates the Twitch environment and provides easy testing. You can also test by creating a local HTTPS server and manually adding the extension script, but the Rig simplifies the process.
Can I use npm packages in my extension?
Yes, but you must bundle them into a single file for production. Tools like Webpack or Parcel can bundle your code and dependencies.
How do I get the viewer's username?
Use Twitch.ext.viewer after authorization. It contains the viewer's opaque ID and display name (if allowed by the user's privacy settings).
Can I make an extension that works on both overlay and panel?
Yes, you can create a single extension that adapts its layout based on the context from Twitch.ext.onContext. You'll need to handle different iframe sizes.
How long does Twitch review take?
Review times vary, but typically a few days. Make sure your extension complies with Twitch's developer guidelines to avoid delays.