Automate Browser Extensions

abstract This section describes how to automate browser extensions using Sahi Pro in BROWSER mode.
warning
  • Steps mentioned below are experimental in nature. They may not work for every browser extension.
  • Thus, it is recommended to use Sahi Pro Desktop Add-on to automate browser extensions.
  • Add below property in the userdata.properties file to identify the elements of the browser extension using Sahi Pro Desktop Add-on.
    windows.allow_identification_for_browsers=chrome,msedge

Automate an extension in Google Chrome

  1. Download the extension's source in a directory. One way to download the source is using the Chrome extension source viewer extension. After downloading the zip file, extract it to a new folder.
  2. Add the below lines to all HTML files present in the extension's source content. Below script files inject Sahi's JavaScript and thus facilitate automating HTML pages.
    <script src="https://sahi.example.com/_s_/sprc/concat.js,common.js,listen.js,actions.js,touch.js,sfl.js,language_pack.js" id="_sahi_concat" ></script>
    <script src="https://sahi.example.com/_s_/dyn/SessionState_config/sahiconfig.js"></script>
  3. Open the manifest.json file of the extension. Add the following line to the end before the closing curly braces '}'.
    ,"content_security_policy": "script-src 'self' https://sahi.example.com 'unsafe-eval'; object-src 'self'"
  4. Start Sahi. Launch Chrome from Sahi Dashboard. Navigate to chrome://extensions/.
  5. Enable Developer mode. Click on the Load unpacked button and select the extension source directory (downloaded and modified).
  6. Click on details for the newly added extension. Allow in incognito.
  7. Navigate to chrome://extensions/shortcuts. Set a shortcut to activate the extension e.g 'Ctrl + Q'. This shortcut key can be triggered on the HTML body using _keyPress API in Sahi script.
    _keyPress(document.body, 'Q', "CTRL");
  8. Exit from Chrome and close Sahi.
  9. We have now added this extension to one Chrome profile folder in Sahi at sahi_pro\userdata\browser\chrome\profiles\sahi0. We need to add these changes to other profile folders.
    1. Open sahi_pro\userdata\browser\chrome\profiles directory.
    2. Except sahi0 directory, delete all the other directories like sahi1, sahi2, and so on.
    3. Then recreate Chrome profile folders like sahi1, sahi2, and so on by duplicating the contents of the sahi0 folder.