Navigation
These archived docs are for Phaser 2.4.3 Phaser 3 docs can be found on newdocs.phaser.io.
Phaser CE docs can be found on the Phaser CE Documentation site.

Constructor

Phaser. Device

Detects device support capabilities and is responsible for device intialization - see whenReady.

This class represents a singleton object that can be accessed directly as game.device (or, as a fallback, Phaser.Device when a game instance is not available) without the need to instantiate it.

Unless otherwise noted the device capabilities are only guaranteed after initialization. Initialization occurs automatically and is guaranteed complete before Phaser.Game begins its "boot" phase. Feature detection can be modified in the onInitialized signal.

When checking features using the exposed properties only the truth-iness of the value should be relied upon unless the documentation states otherwise: properties may return false, '', null, or even undefined when indicating the lack of a feature.

Uses elements from System.js by MrDoob and Modernizr

<internal> new Device()

It is not possible to instantiate the Device class manually.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: system/Device.js (Line 30)

Public Properties

<static, nullable> onInitialized : Phaser.Signal

This signal is dispatched after device initialization occurs but before any of the ready callbacks (see whenReady) have been invoked.

Local "patching" for a particular device can/should be done in this event.

Note: This signal is removed after the device has been readied; if a handler has not been added before new Phaser.Game(..) it is probably too late.

Source code: system/Device.js (Line 520)

android : boolean

Is running on android?

Source code: system/Device.js (Line 112)

arora : boolean

Set to true if running in Arora.

Source code: system/Device.js (Line 251)

audioData : boolean

Are Audio tags available?

Source code: system/Device.js (Line 349)

cancelFullscreen : string

If the browser supports the Full Screen API this holds the call you need to use to cancel it.

Source code: system/Device.js (Line 494)

canvas : boolean

Is canvas available?

Source code: system/Device.js (Line 150)

canvasBitBltShift : boolean

True if canvas supports a 'copy' bitblt onto itself when the source and destination regions overlap.

Source code: system/Device.js (Line 156)

chrome : boolean

Set to true if running in Chrome.

Source code: system/Device.js (Line 257)

chromeOS : boolean

Is running on chromeOS?

Source code: system/Device.js (Line 118)

chromeVersion : number

If running in Chrome this will contain the major version number.

Source code: system/Device.js (Line 263)

cocoonJS : boolean

Is the game running under CocoonJS?

Source code: system/Device.js (Line 64)

cocoonJSApp : boolean

Is this game running with CocoonJS.App?

Source code: system/Device.js (Line 70)

cordova : boolean

Is the game running under Apache Cordova?

Source code: system/Device.js (Line 76)

crosswalk : boolean

Is the game running under the Intel Crosswalk XDK?

Source code: system/Device.js (Line 106)

css3D : boolean

Is css3D available?

Source code: system/Device.js (Line 192)

desktop : boolean

Is running on a desktop?

Source code: system/Device.js (Line 52)

<internal> deviceReadyAt : integer

The time the device became ready.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: system/Device.js (Line 37)

ejecta : boolean

Is the game running under Ejecta?

Source code: system/Device.js (Line 100)

electron : boolean

Is the game running under GitHub Electron?

Source code: system/Device.js (Line 94)

epiphany : boolean

Set to true if running in Epiphany.

Source code: system/Device.js (Line 269)

file : boolean

Is file available?

Source code: system/Device.js (Line 168)

fileSystem : boolean

Is fileSystem available?

Source code: system/Device.js (Line 174)

firefox : boolean

Set to true if running in Firefox.

Source code: system/Device.js (Line 275)

firefoxVersion : number

If running in Firefox this will contain the major version number.

Source code: system/Device.js (Line 281)

fullscreen : boolean

Does the browser support the Full Screen API?

Source code: system/Device.js (Line 482)

fullscreenKeyboard : boolean

Does the browser support access to the Keyboard during Full Screen mode?

Source code: system/Device.js (Line 500)

getUserMedia : boolean

Does the device support the getUserMedia API?

Default Value
  • true
Source code: system/Device.js (Line 216)

h264Video : boolean

Can this device play h264 mp4 video files?

Source code: system/Device.js (Line 406)

hlsVideo : boolean

Can this device play hls video files?

Source code: system/Device.js (Line 430)

ie : boolean

Set to true if running in Internet Explorer.

Source code: system/Device.js (Line 287)

ieVersion : number

If running in Internet Explorer this will contain the major version number. Beyond IE10 you should use Device.trident and Device.tridentVersion.

Source code: system/Device.js (Line 293)

<internal> initialized : boolean

The time as which initialization has completed.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: system/Device.js (Line 44)

iOS : boolean

Is running on iOS?

Source code: system/Device.js (Line 58)

iPad : boolean

Is running on iPad?

Source code: system/Device.js (Line 450)

iPhone : boolean

Is running on iPhone?

Source code: system/Device.js (Line 438)

iPhone4 : boolean

Is running on iPhone4?

Source code: system/Device.js (Line 444)

linux : boolean

Is running on linux?

Source code: system/Device.js (Line 124)

LITTLE_ENDIAN : boolean

Same value as littleEndian.

Source code: system/Device.js (Line 470)

littleEndian : boolean

Is the device big or little endian? (only detected if the browser supports TypedArrays)

Source code: system/Device.js (Line 464)

localStorage : boolean

Is localStorage available?

Source code: system/Device.js (Line 180)

m4a : boolean

Can this device play m4a files? True if this device can play m4a files.

Source code: system/Device.js (Line 386)

macOS : boolean

Is running on macOS?

Source code: system/Device.js (Line 130)

midori : boolean

Set to true if running in Midori.

Source code: system/Device.js (Line 317)

mobileSafari : boolean

Set to true if running in Mobile Safari.

Source code: system/Device.js (Line 311)

mp3 : boolean

Can this device play mp3 files?

Source code: system/Device.js (Line 373)

mp4Video : boolean

Can this device play h264 mp4 video files?

Source code: system/Device.js (Line 412)

mspointer : boolean

Is mspointer available?

Source code: system/Device.js (Line 236)

node : boolean

Is the game running under Node.js?

Source code: system/Device.js (Line 82)

nodeWebkit : boolean

Is the game running under Node-Webkit?

Source code: system/Device.js (Line 88)

ogg : boolean

Can this device play ogg files?

Source code: system/Device.js (Line 361)

oggVideo : boolean

Can this device play ogg video files?

Source code: system/Device.js (Line 400)

opera : boolean

Set to true if running in Opera.

Source code: system/Device.js (Line 323)

opus : boolean

Can this device play opus files?

Source code: system/Device.js (Line 367)

pixelRatio : number

PixelRatio of the host device?

Source code: system/Device.js (Line 458)

pointerLock : boolean

Is Pointer Lock available?

Source code: system/Device.js (Line 198)

quirksMode : boolean

Is the browser running in strict mode (false) or quirks mode? (true)

Source code: system/Device.js (Line 222)

requestFullscreen : string

If the browser supports the Full Screen API this holds the call you need to use to activate it.

Source code: system/Device.js (Line 488)

safari : boolean

Set to true if running in Safari.

Source code: system/Device.js (Line 329)

silk : boolean

Set to true if running in the Silk browser (as used on the Amazon Kindle)

Source code: system/Device.js (Line 341)

support32bit : boolean

Does the device context support 32bit pixel manipulation using array buffer views?

Source code: system/Device.js (Line 476)

touch : boolean

Is touch available?

Source code: system/Device.js (Line 230)

trident : boolean

Set to true if running a Trident version of Internet Explorer (IE11+)

Source code: system/Device.js (Line 299)

tridentVersion : number

If running in Internet Explorer 11 this will contain the major version number. See http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx

Source code: system/Device.js (Line 305)

typedArray : boolean

Does the browser support TypedArrays?

Source code: system/Device.js (Line 204)

vibration : boolean

Does the device support the Vibration API?

Source code: system/Device.js (Line 210)

vp9Video : boolean

Can this device play vp9 video files?

Source code: system/Device.js (Line 424)

wav : boolean

Can this device play wav files?

Source code: system/Device.js (Line 379)

webApp : boolean

Set to true if running as a WebApp, i.e. within a WebView

Source code: system/Device.js (Line 335)

webAudio : boolean

Is the WebAudio API available?

Source code: system/Device.js (Line 355)

webGL : boolean

Is webGL available?

Source code: system/Device.js (Line 162)

webm : boolean

Can this device play webm files?

Source code: system/Device.js (Line 392)

webmVideo : boolean

Can this device play webm video files?

Source code: system/Device.js (Line 418)

<internal> wheelEvent

Properties:
Name Type Argument Description
wheelType string <nullable>

The newest type of Wheel/Scroll event supported: 'wheel', 'mousewheel', 'DOMMouseScroll'

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source code: system/Device.js (Line 243)

windows : boolean

Is running on windows?

Source code: system/Device.js (Line 136)

windowsPhone : boolean

Is running on a Windows Phone?

Source code: system/Device.js (Line 142)

worker : boolean

Is worker available?

Source code: system/Device.js (Line 186)

Public Methods

<static> whenReady(handler, context, nonPrimer)

Add a device-ready handler and ensure the device ready sequence is started.

Phaser.Device will not activate or initialize until at least one whenReady handler is added, which is normally done automatically be calling new Phaser.Game(..).

The handler is invoked when the device is considered "ready", which may be immediately if the device is already "ready". See deviceReadyAt.

Parameters
Name Type Argument Default Description
handler function

Callback to invoke when the device is ready. It is invoked with the given context the Phaser.Device object is supplied as the first argument.

context object <optional>

Context in which to invoke the handler

nonPrimer boolean <optional>
false

If true the device ready check will not be started.

Source code: system/Device.js (Line 536)

canPlayAudio(type) → {boolean}

Check whether the host environment can play audio.

Parameters
Name Type Description
type string

One of 'mp3, 'ogg', 'm4a', 'wav', 'webm' or 'opus'.

Returns
boolean -

True if the given file type is supported by the browser, otherwise false.

Source code: system/Device.js (Line 1194)

canPlayVideo(type) → {boolean}

Check whether the host environment can play video files.

Parameters
Name Type Description
type string

One of 'mp4, 'ogg', 'webm' or 'mpeg'.

Returns
boolean -

True if the given file type is supported by the browser, otherwise false.

Source code: system/Device.js (Line 1233)

isAndroidStockBrowser()

Detect if the host is a an Android Stock browser. This is available before the device "ready" event.

Authors might want to scale down on effects and switch to the CANVAS rendering method on those devices.

Source code: system/Device.js (Line 1299)
Example
var defaultRenderingMode = Phaser.Device.isAndroidStockBrowser() ? Phaser.CANVAS : Phaser.AUTO;

isConsoleOpen()

Check whether the console is open. Note that this only works in Firefox with Firebug and earlier versions of Chrome. It used to work in Chrome, but then they removed the ability: http://src.chromium.org/viewvc/blink?view=revision&revision=151136

Source code: system/Device.js (Line 1264)