teampoltergeist / poltergeist

A PhantomJS driver for Capybara

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

User agent does not persist across windows

afn opened this issue · comments

Meta

Poltergeist Version:
1.15.0

Expected Behavior

After calling capybara_session.driver.add_headers('User-Agent' => 'foo'), I would expect all subsequent requests within that session to have User-Agent set to foo, even if there are new windows created during that session.

Actual Behavior

The headers are only set in the initial window. Thus, if a new window is opened, either by clicking a link with _target=blank or by explicitly opening a new window, the user agent reverts back to the default PhantomJS agent.

Steps to reproduce

capybara_session = Capybara::Session.new(:poltergeist)
capybara_session.driver.add_headers('User-Agent' => 'foo')
capybara_session.visit 'http://whatsmyuseragent.org/'
puts capybara_session.find('.user-agent').text
# => foo
capybara_session.switch_to_window capybara_session.open_new_window
capybara_session.visit 'http://whatsmyuseragent.org/'
puts capybara_session.find('.user-agent').text
# => Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1

1.15.0 is slightly outdated - does this still happen on 1.17.0 ? and what version of PhantomJS are you using?

@twalpole Yes, it still happens in master. I'm running PhantomJS 2.1.1 (but this doesn't seem to be a PhantomJS bug).

Check out PR #916 above.

Closed via PR #916