heroku-buildpack-google-chrome icon indicating copy to clipboard operation
heroku-buildpack-google-chrome copied to clipboard

Fail to set user agent correctly

Open khoan opened this issue 7 years ago • 0 comments

$ heroku stack -r tech
=== ⬢ testapp Available Stacks
* heroku-16
  cedar-14
  container
$ heroku buildpacks
=== Buildpack URLs
1. heroku/ruby
2. https://github.com/heroku/heroku-buildpack-google-chrome
3. https://github.com/heroku/heroku-buildpack-chromedriver
$ cat bin/test
#!/usr/bin/env ruby

puts ENV['AGENT'] # =>Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0

require 'selenium-webdriver'

options = Selenium::WebDriver::Chrome::Options.new(
  args: [
    "user-agent=#{ENV['AGENT']}"
  ],
  binary: ENV['GOOGLE_CHROME_SHIM']
)
driver = Selenium::WebDriver.for(:chrome, options: options)
driver.get('https://google.com')
puts driver.execute_script('return navigator.userAgent') # => Mozilla/5.0
$ heroku run bin/test
Running bin/test on ⬢ testapp... up, run.9802 (Free)
Mozilla/5.0

workaround is to use custom script that quotes $@

$ cat bin/chrome
#!/usr/bin/env bash
exec $HOME/.apt/opt/google/chrome/chrome --headless --no-sandbox --disable-gpu --remote-debugging-port=9222 "$@"

khoan avatar Dec 22 '17 08:12 khoan