Set User-Agent

Set User-Agent #

client.setUserAgent((userAgent: string));

Changes User-Agent header for outgoing requests and navigator.userAgent.

To reset User-Agent to its default value, pass null as the new value.
Setting User-Agent to an empty string will actually update the User-Agent to empty string.
function(client) {
// Example of setting custom user-agent
    client
        // Open page and create screenshot with default User-Agent
        .url('http://www.xhaus.com/headers')
        .waitForElementVisible('body', 1000)
        .takeScreenshot('UADefault.png')
        // Set custom User-Agent value
        .setUserAgent('Custom User Agent')
        // Refresh the page
        .refresh()
        // Wait for the page to load and create screenshot with changed User-Agent
        .waitForElementVisible('body', 1000)
        .takeScreenshot('UACustom.png')
        // Set User-Agent to empty string value
        .setUserAgent('')
        // Refresh the page
        .refresh()
        // Wait for the page to load and create screenshot with empty User-Agent
        .waitForElementVisible('body', 1000)
        .takeScreenshot('UAEmpty.png')
        // Reset User-Agent to original value
        .setUserAgent(null)
        // Refresh the page
        .refresh()
        // Wait for the page to load and create screenshot with reset User-Agent
        .waitForElementVisible('body', 1000)
        .takeScreenshot('UARevert.png');
}
User-Agent will revert to original value in browser built-in pages and WebRTC dump.