The ClientWorker class represents a mobile device connected to your Uplink session. It provides methods for managing browsers on the device and querying device information.
Browser operations
worker.launch()
Launches a new browser on this device.
worker.launch(): Promise<Browser>
Returns: Promise<Browser> - New browser instance
Example:
const device = await client.worker()
const browser = await device.launch()
console.log('Browser launched on device:', device.address)
worker.connect()
Connects to an existing browser on this device by its handle.
worker.connect(handle: string): Promise<Browser>
Parameters:
handle: Browser handle identifier
Returns: Promise<Browser> - Connected browser instance
Example:
// Save browser handle for later reconnection
const browser = await device.launch()
const handle = browser.handle
// Later, reconnect to the same browser
const sameBrowser = await device.connect(handle)
worker.browsers()
Lists all browsers currently running on this device.
worker.browsers(): Promise<Browser[]>
Returns: Promise<Browser[]> - Array of browser instances
Example:
const browsers = await device.browsers()
console.log(`${browsers.length} browsers on this device`)
for (const browser of browsers) {
const pages = await browser.pages()
console.log(`Browser ${browser.handle} has ${pages.length} pages`)
}
worker.getDeviceInfo()
Gets device information including model, platform, and OS version.
worker.getDeviceInfo(): Promise<WorkerInfo>
Returns: Promise<WorkerInfo> - Device information object
Example:
const info = await device.getDeviceInfo()
console.log('Device model:', info.deviceModel) // "iPhone 14 Pro"
console.log('Platform:', info.platform) // "iOS"
console.log('OS version:', info.platformVersion) // "17.2"
console.log('Type:', info.deviceType) // "phone"
WorkerInfo type
interface WorkerInfo {
deviceModel: string // Device model name
platform: string // "iOS" or "Android"
platformVersion: string // OS version number
deviceType: string // "phone" or "tablet"
}
Device management
worker.terminate()
Terminates this device’s connection to the session.
worker.terminate(): Promise<void>
Returns: Promise<void>
Example:
await device.terminate()
console.log('Device terminated')
Terminating a device closes all browsers running on it and disconnects the device from the session. This action cannot be undone.
Properties
worker.address
The unique address identifier for this device.
Example:
const device = await client.worker()
console.log('Device address:', device.address)
Complete examples
Device-specific automation
const client = await uplink.client.connect(sessionUrl)
// Get a specific device
const device = await client.worker()
// Get device info
const info = await device.getDeviceInfo()
console.log(`Using ${info.deviceModel} running ${info.platform} ${info.platformVersion}`)
// Launch browser on this device
const browser = await device.launch()
const page = await browser.newPage()
await page.goto('https://example.com')
// Cleanup
await browser.close()
Multi-device coordination
const client = await uplink.client.connect(sessionUrl)
// Wait for multiple devices
const device1 = await client.worker()
const device2 = await client.worker()
const info1 = await device1.getDeviceInfo()
const info2 = await device2.getDeviceInfo()
console.log('Device 1:', info1.deviceModel, info1.platform)
console.log('Device 2:', info2.deviceModel, info2.platform)
// Run tests in parallel
await Promise.all([
runTest(device1, 'Test A'),
runTest(device2, 'Test B')
])
async function runTest(device, testName) {
const browser = await device.launch()
const page = await browser.newPage()
console.log(`[${testName}] Running on ${device.address}`)
await page.goto('https://example.com')
await browser.close()
}
client.on('worker-connected', async (device) => {
const info = await device.getDeviceInfo()
if (info.platform === 'iOS') {
console.log('iOS device detected, running iOS-specific tests')
await runIOSTests(device)
} else if (info.platform === 'Android') {
console.log('Android device detected, running Android-specific tests')
await runAndroidTests(device)
}
})
async function runIOSTests(device) {
const browser = await device.launch()
const page = await browser.newPage()
// iOS-specific test logic
await page.goto('https://example.com')
await page.setUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)')
await browser.close()
}
async function runAndroidTests(device) {
const browser = await device.launch()
const page = await browser.newPage()
// Android-specific test logic
await page.goto('https://example.com')
await page.setUserAgent('Mozilla/5.0 (Linux; Android 13)')
await browser.close()
}
Browser management
const device = await client.worker()
// Launch multiple browsers on the same device
const browser1 = await device.launch()
const browser2 = await device.launch()
// List all browsers
const allBrowsers = await device.browsers()
console.log(`${allBrowsers.length} browsers running on device`)
// Clean up all browsers
for (const browser of allBrowsers) {
await browser.close()
}