0

I am trying to add request headers for modHeaders in chrome through Selenium with ruby.

I have tried this code but no luck. Mod Header extension has added to browser but unable to add request headers to that extension.

Please help me to find the problem in my code.

Thank you.

require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome, 
   :desired_capabilities =>Selenium::WebDriver::Remote::Capabilities.chrome({
        'chromeOptions' => {
            'extensions' => [Base64.strict_encode64(File.open('C:\Users\balinasr\Downloads\mod.crx', 'rb').read) ],
            'prefs'=> {
                'modifyheaders.headers.name'=>'aaa',
                'modifyheaders.headers.value'=>'bbb'
             }
         }
    })

1 Answers1

0

I know it isn't the exact answer you're looking for, but this is the Java code I use. After some googling and researching, setting the values in the LocalStorage of the browser was too difficult for me :). What I did is create a Chrome user with the plugin configured which I load when starting the chromedriver.

//to start the ChromeDriver with a plugin (from local.properties f.e.)
    if (System.getProperty(CHROME_USER_DATA_DIR) == null && chromeUserDataDir != null && !chromeUserDataDir
        .equalsIgnoreCase("@null")) {
        options.addArguments("user-data-dir="+chromeUserDataDir);
        if (System.getProperty(CHROME_EXTENSION1) == null && chromeExtension1 != null && !chromeExtension1
            .equalsIgnoreCase("@null")){
            options.addArguments("load-extension="+chromeUserDataDir+chromeExtension1);
        }
    }

The parameters are:

chrome.user.data.dir=C:/Users/[user]/AppData/Local/Google/Chrome SxS/User Data/Default/
chrome.user.extension1=Extensions/idgpnmonknjnojddfkpgkljpfnnfcklj/2.1.1_0/
Blitzoff
  • 133
  • 4
  • 11
  • I'm honestly not sure how local storage and headers are related, but in Ruby you have: `driver.session_storage` and `driver.local_storage`. Setting a storage value in chrome is as easy as `driver.local_storage['foo1'] = 'bar1'` – titusfortner Dec 01 '16 at 23:57