Cross-document messages API is no longer receiving updates.
Please use our for any new development.
Cross-document messaging, when enabled via the &xdocMsg=true
query parameter, allows you to issue commands to the embedded iFrame via Javascript via .
Messages without any parameters can be passed directly as strings, e.g.
Copy postMessage('requestSession', '*')
Messages with parameters should be passed as objects with the message name in the type
field. E.g.
Copy postMessage({ type: 'mouseclick', x: 100, y:100 }, '*')
Sendable Messages
requestSession
Equivalent to clicking play
Copy postMessage('requestSession', '*')
Taps the home button for iOS apps when available
Copy postMessage('emitHomeButton', '*')
rotateLeft
Rotates counter-clockwise
Copy postMessage('rotateLeft', '*')
rotateRight
Rotates clockwise
Copy postMessage('rotateRight', '*')
setScale
Sets device scale to a value between 10 and 100
Copy postMessage({ type: 'setScale', value: 50 })
saveScreenshot
Prompts user to download screenshot
Copy postMessage('saveScreenshot', '*')
getScreenshot
Sends screenshot data directly to parent window. See the screenshot
event the iFrame posts to the parent.
Copy postMessage('getScreenshot', '*')
heartbeat
Sends heartbeat to prevent inactivity timeout
Copy postMessage('heartbeat', '*')
mouseclick
Sends click event at the provided coordinates
Copy postMessage({ type: 'mouseclick', x: 100, y:100 }, '*')
pasteText
Pastes the provided text
Copy postMessage({ type: 'pasteText', value: 'Hello World' }, '*')
keypress
Sends keypress. key
should be a string that identifies the key pressed, e.g. 'a'
. Acceptable values on Android also include 'volumeUp'
and 'volumeDown'
.
Copy postMessage({ type: 'keypress', key: 'a', shiftKey: true }, '*') // would send 'A"
language
Sets language, restarts app
Copy postMessage({ type: 'language', value: 'fr' }, '*')
location
Sets location. value
should be 2-length array that contains [latitude, longitude]
Copy postMessage({ type: 'location', value: [50.0, -100.0] }, '*')
url
Opens deep-link or regular URL in Safari
Copy postMessage({ type: 'url', value: 'https://appetize.io' }, '*')
shakeDevice
Send shake gesture to iOS apps
Copy postMessage('shakeDevice', '*')
androidKeycodeMenu
Sends Android KEYCODE_MENU command
Copy postMessage('androidKeycodeMenu', '*')
adbShellCommand
Executes an adb shell command on an Android device.
If a session is already running the command will be executed immediately. If the session has not been started, the command will execute upon start.
Copy postMessage({
type: 'adbShellCommand',
value: 'am start -a android.intent.action.VIEW -d https://appetize.io/'
}, '*')
biometryMatch
(Android 8+ only) simulate a matching fingerprint
Copy postMessage('biometryMatch', '*')
biometryNonMatch
(Android 8+ only) simulate a non-matching fingerprint
Copy postMessage('biometryNonMatch', '*')
disableInteractions
Disables all user interactions
Copy postMessage('disableInteractions', '*')
enableInteractions
Re-enables all user interactions
Copy postMessage('enableInteractions', '*')
restartApp
Kills and restarts app in same session
Copy postMessage('restartApp', '*')
endSession
Ends the session
Copy postMessage('endSession', '*')
Receivable Messages
The iFrame also posts messages to the parent window via message
event. You can listen for them with an event handler on the window:
Copy window.addEventListener('message', (event) => {
const type = typeof event.data === 'string' ? event.data : event.data.type
console.log(type)
})
userInteractionReceived
Session has received an interaction from the user
Copy {
data: {
type: "userInteractionReceived",
value: {
altKey: boolean,
shiftKey: boolean,
timeStamp: number,
type: string,
xPos: number,
yPost: number
}
}
}
heartbeatReceived
Heartbeat event received
Copy {
data: "heartbeatReceived"
}
orientationChanged
Device orientation has changed
Copy {
data: {
type: "orientationChanged",
value: "landscape" | "portrait"
}
}
sessionRequested
Session has been requested
Copy {
data: "sessionRequested"
}
userError
An error occurred while starting session
Copy {
data: {
type: "userError",
value: string // error message
}
}
sessionQueued
You have entered a system-level queue (awaiting device availability)
Copy {
data: "sessionQueued"
}
sessionQueuedPosition
Position of session queue
Copy {
data: {
type: "sessionQueuedPosition",
position: number
}
}
accountQueued
You have entered an account-level queue (concurrent users)
Copy {
data: "accountQueued"
}
accountQueuedPosition
Account queue position
Copy {
data: {
type: "accountQueuedPosition",
position: number
}
}
appLaunch
App launch command sent
Copy {
data: "appLaunch"
}
firstFrameReceived
First frame received
Copy {
data: "firstFrameReceived"
}
timeoutWarning
Session is about to timeout in 10 seconds
Copy {
data: "timeoutWarning"
}
sessionEnded
Session has ended
Copy {
data: "sessionEnded"
}
screenshot
Screenshot data received
Copy {
data: {
type: "screenshot",
data: string // base64 encoded image data
}
}
sessionConnecting
Passes the identifying token for the session
Copy {
data: {
type: "sessionConnecting",
token: string,
path: string
}
}
URL to view dev tools for the device (only if network intercept enabled)
Copy {
data: {
type: "chromeDevToolsUrl",
value: string
}
}
interceptResponse
Intercepted network response.
This is only emitted if network intercept enabled (proxy=intercept
query param)
Copy {
data: {
type: "interceptResponse",
value: {
cache: object
request: {
bodySize: number
cookies: Array<{ name: string, value: string }>
headers: Array<{ name: string, value: string }>
headersSize: number
httpVersion: string
method: string
queryString: Array<{ name: string, value: string }>
url: string
}
requestId: string
serverIPAddress: string
}
}
}
interceptRequest
Intercepted network request.
This is only emitted if network intercept enabled (proxy=intercept
query param)
Copy {
data: {
type: "interceptRequest",
value: {
cache: object
request: {
bodySize: number
cookies: Array<{ name: string, value: string }>
headers: Array<{ name: string, value: string }>
headersSize: number
httpVersion: string
method: string
queryString: Array<{ name: string, value: string }>
url: string
}
requestId: string
serverIPAddress: string
}
}
}
debug
Logged messages from the device.
This is only emitted if debug log is enabled (debug=true
query param)
Copy {
data: {
type: "debug",
value: string
}
}
deviceDimensions
The dimensions of the current device. If the screenOnly
query param is true, the dimensions will be for the screen.
Copy {
data: {
type: "deviceDimensions",
value: {
width: number,
height: number
}
}
}
app
Information for the application
Copy {
data: {
type: "app",
value: {
name: "Example",
appDisplayName: "Example",
bundle: "com.example.app",
publicKey: "p7nww3n6ubq73r1nh9jtauqy8w",
platform: "ios"
}
}
}