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
Worked up to version: 3.6.0
Stopped working in version: 4.0.0-alpha.1
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:
You should be able to load extensions from file in Chrome.
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.
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):
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.
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.