Studio & Workflow Tools

Get Useragent

Get browser user agent.

Get browser user agent.

Retrieves the browsers user agent string from navigator.userAgent and sends it to the native application for identification or environment detection.

TIP

BrowserHelper.GetUserAgent(browser) returns the live user agent in use by the browser, as opposed to MagicHelper.GetUserAgentString(browserType) which returns a templated user agent built from the locally installed browser version. TestUrlForPDF and DownloadPdfFile use BrowserHelper.GetUserAgent so their HttpClient requests present the same User-Agent header as the browser itself.

Examples

GPAL Fluent: High-level fluent C# API

//Returns the live user agent string actually presented by the browsers active automation engine (OttoMagic, Puppeteer, or Selenium via navigator.userAgent), falling back to MagicHelper.GetUserAgentString [hardcoded] if it cannot be determined.

string userAgent = BrowserHelper.GetUserAgent(browser);

MagicHelper: MagicHelper utility library

string userAgent = GPAL.MagicHelper.GetUserAgent();

Puppeteer Client: Puppeteer-style C# client

string userAgent = browser.PuppeteerClient.GetUserAgent().Execute<string>();

Puppeteer Communicator: Low-level communicator

string userAgent = await browser.PuppeteerCommunicator.GetUserAgent(sessionId);

REST Client: Direct REST/HTTP client

GPAL.OttoMagicClient.GetUserAgent().Execute();