Automate Browser Extensions
This section describes how to automate browser extensions using Sahi Pro in BROWSER mode.
Automate an extension in Google Chrome
Section titled “Automate an extension in Google Chrome”-
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.
-
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> -
Open the
manifest.jsonfile of the extension. Add the following lines to the end before the closing curly braces ‘}’.,"content_security_policy": {"extension_pages": "script-src 'self'; object-src 'self'"} -
Start Sahi. Launch Chrome from Sahi Dashboard. Navigate to chrome://extensions/.
-
Enable Developer mode. Click on the
Load unpackedbutton and select the extension source directory (downloaded and modified). -
Click on details for the newly added extension. Allow in incognito.
-
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 function in Sahi script.
_keyPress(document.body, 'Q', "CTRL"); -
Exit from Chrome and close Sahi.
-
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.- Open
sahi_pro\userdata\browser\chrome\profilesdirectory. - Except
sahi0directory, delete all the other directories likesahi1,sahi2, and so on. - Then recreate Chrome profile folders like
sahi1,sahi2, and so on by duplicating the contents of thesahi0folder.
- Open

