Webdriverio: Is there any way to add extension to chrome in webdriverio?

Created on 2 Apr 2015  ·  4Comments  ·  Source: webdriverio/webdriverio

Actually, I need to open pages with extension installed in any browser (not specifically chrome). So it can be firefox, or phantomjs(not sure if it is possible at all).

So, is there any way to run chrome/firefox/phantom via webdriverio with preinstalled extension , and if there is - how can I do it?

Thanks in advance!

Most helpful comment

yep, that works

var data = await fs.readFileSync('./ext.zip');
options.desiredCapabilities.chromeOptions.extensions = [data.toString('base64')];

All 4 comments

Yes there is! You can have chromeOptions property in your desiredCapability. This object has a property called extensions that takes the base64 string of your crx file. You will find more information https://sites.google.com/a/chromium.org/chromedriver/capabilities

yep, that works

var data = await fs.readFileSync('./ext.zip');
options.desiredCapabilities.chromeOptions.extensions = [data.toString('base64')];

Hello! Thanks for sharing your approach!
@d668 Maybe you had some similar problem while working on adding an extension to your tests??
I tried to add an extension, and after the running a test,
I got an error:
ERROR webdriver: Request failed due to unknown error: unknown error: cannot process extension #1 from unknown error: cannot read manifest

 maxInstances: 5,
        "goog:chromeOptions": {
            extensions: [(function () {
                try {
                    const webExt = fs.readFileSync('./extension.zip').toString('base64');
                    return webExt;
                } catch (e) {
                    console.log(e, 'An error occurred while to parse extension zip file!');
                }
            })()],
            args: ['--headless', '--disable-gpu']
        },

@Madebyspeedster you need to pack extension. Open chrome://extensions and click Pack extension. It will generate .crx pack and .pem key. After that you can use .pem key to generate packs for you own. You can use this library for that https://github.com/Constellation/crxmake

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Windyq picture Windyq  ·  4Comments

LaiaPR picture LaiaPR  ·  4Comments

briancullinan picture briancullinan  ·  4Comments

christian-bromann picture christian-bromann  ·  3Comments

davidsoderberg picture davidsoderberg  ·  4Comments