Selenium: [JavaScript] Loading extensions from file in Chrome doesn't work in 4.0.0-alpha.1

Created on 22 Nov 2018  路  4Comments  路  Source: SeleniumHQ/selenium

馃挜 Regression Report

Loading a Chrome extension in 4.0.0-alpha.1 doesn't work, it throws unknown error: cannot process extension #1 from unknown error: cannot base64 decode

Last working Selenium version

Worked up to version: 3.6.0

Stopped working in version: 4.0.0-alpha.1

To Reproduce

Loading an extension like:

 chromeOptions.addExtensions(
      path.resolve(moduleRootPath, 'vendor', 'browsertime-extension.crx')
   );

doesn't work. See https://github.com/sitespeedio/browsertime/blob/master/lib/chrome/webdriver/index.js#L100-L105

Detailed steps to reproduce the behavior:

Expected behavior

You should be able to load extensions from file in Chrome.

Test script reproducing this issue (when applicable)

I think this was introduced here: https://github.com/SeleniumHQ/selenium/commit/9976795d0357aa19f95d6c73c9f203449e182fbf#diff-cc4a7b2914982158b85fcd2ff2a60ea2

I can have a go to see if I can fix it the coming days, if I get the environment working.

Environment

OS: OS X
Browser: Chrome
Browser version: 70.0.3538.10
Browser Driver version: ChromeDriver 2.43
Language Bindings version: JavaScript 4.0.0-alpha.1
Selenium Grid version (if applicable):

C-nodejs

Most helpful comment

@SebastienGllmt thanks, yes. You could even simplify to:

fs.readFileSync(path.resolve(__dirname, 'my_extension.crx'), { encoding: 'base64' })

The changelog needs to mention that the functionality changed.

All 4 comments

I had a quick go at it and I could see that the serialization of the Chrome capabilities object never runs: https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/chrome.js#L658-L671

So that the Chromedriver gets the full path to the extension instead of the BASE64 encoded version.

@jleyba any chance you can help me with this? I had a go some time ago but didn't fully understand how it should work so I could fix the issue.

@soulgalore I managed to get it working by passing in a Buffer instead of a filepath

const fs = require('fs');
function encode(file) {
  var stream = fs.readFileSync(file);
  return new Buffer.from(stream).toString('base64');
}

...
new Builder()
  .setChromeOptions(new chrome.Options()
      .addExtensions(encode(path.resolve(__dirname, 'my_extension.crx'))));

@SebastienGllmt thanks, yes. You could even simplify to:

fs.readFileSync(path.resolve(__dirname, 'my_extension.crx'), { encoding: 'base64' })

The changelog needs to mention that the functionality changed.

Was this page helpful?
0 / 5 - 0 ratings