When using the PhantomJS browser to open web pages, you are faced with interesting/annoying problems. One such issue I encountered was that a custom click handler was not being executed on a specific page – while generally working on other pages.
In the browser log, the following error was showing up:
Sys.WebForms.PageRequestManager is undefined.
Sys.WebForms.PageRequestManager is undefined error in IE11, working fine in IE10 and below
So what is the solution? Yes, let’s spoof the user agent.
When using pure PhantomJS, this can be achieved by setting the
page.settings.userAgent property (see PhantomJS API).
When using PhantomJS via Selenium Webdriver, you can pass the property as a capability when creating the browser object. In WebDriverJS (node.js) this results in the following:
var browser = webdriver.Capabilities.phantomjs(); browser.set('phantomjs.page.settings.userAgent', '
'); var driver = new webdriver.Builder() .withCapabilities(browser) .build();
As indicated here: How to change selenium user agent in selenium-webdriver nodejs land?. If you are unsure what to use as a user agent string, you can simply use your current browser’s one by visiting whatismyuseragent.com or useragentstring.com which also provides an extensive list of used user agent strings.