Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add an unpacked extension from file Selenium node.js

I would like to know how i can add an unpacked extension that i have on my computeur to my chrome webdriver using this : https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/chrome_exports_Options.html#addExtensions I don't really understand what im supposed to do with it.. Thanks in advance to everybody that will help me =) P.S : Im using these node packages : selenium-webdriver, fs

like image 514
Zayonx Avatar asked Oct 29 '25 02:10

Zayonx


1 Answers

import {Builder, Capabilities} from 'selenium-webdriver';
import {Options, ServiceBuilder, setDefaultService} from 'selenium-webdriver/chrome';
import * as chromedriver from 'chromedriver';
import * as path from 'path';
import * as fs from 'fs';

const encodeExt = file => {
  const stream = fs.readFileSync(path.resolve(file));
  return Buffer.from(stream).toString('base64');
};

const service = new ServiceBuilder(chromedriver.path).build();
setDefaultService(service);

const driver = new Builder()
  .withCapabilities(Capabilities.chrome())
  .setChromeOptions(new Options()
    .addExtensions(encodeExt('./3.5.2_0.crx')))        <-----+
  .build();                                                  |
                                                             |
                                                             |
                  this line here! ----------------------------

And this is how to download the .crx file: https://www.maketecheasier.com/download-save-chrome-extension/

like image 150
Moshe Quantz Avatar answered Oct 30 '25 22:10

Moshe Quantz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!