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.
client => {
    // Example of setting custom user-agent
    client
        // Open page and create screenshot with default User-Agent
        .url('https://www.bing.com/')
        .waitForElementVisible('[type=search]', 1000)
        .takeScreenshot('default_user_agent.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('[type=search]', 1000)
        .takeScreenshot('custom_user_agent.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('[type=search]', 1000)
        .takeScreenshot('empty_user_agent.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('[type=search]', 1000)
        .takeScreenshot('reverted_user_agent.png');
}
User-Agent will revert to original value in browser built-in pages and WebRTC dump.