Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watir Webdriver Load Chrome Extension

I'm trying to load a chrome extension with Watir, and I'm having issues. I found this related question: Ability to launch chrome with extensions loaded with watir-webdriver. However, I am still having the same issue after following that.

require 'rubygems'
require 'watir-webdriver'
require 'ruby-debug'
require 'nokogiri'

browser = Watir::Browser.new :chrome, :switches => %w[--load-extension=~/.config/google-chrome/Default/Extensions/anepbdekljkmmimmhbniglnnanmmkoja/0.1.12_0]

sleep(10)
browser.close

I also tried copying the extension from /Extensions to /Desktop and loading from there to no avail.

The error I get is Could not load extension from ... Manifest File Missing or Unreadable. The Manifest file does indeed exist and seems to be a correct file in JSON format.

Trying to load different extensions fails as well.

like image 901
Kishan Avatar asked Sep 02 '25 16:09

Kishan


1 Answers

Download the chrome extension crx file,

Store the args or any other option need to pass in the watir_opts hash 
 watir_opts[:extensions] = ['path of *.crx file']
 browser = Watir::Browser.new :chrome, options: watir_opts

This worked for me. Note: I didn't encode using 'base64' gem

like image 171
user3572816 Avatar answered Sep 05 '25 14:09

user3572816