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
- 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.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'"
- Start Sahi. Launch Chrome from Sahi Dashboard. Navigate to chrome://extensions/.
- Enable Developer mode. Click on the
Load unpacked
button 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 API 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\profiles
directory. - Except
sahi0
directory, 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 thesahi0
folder.