Inject JS Activity Works In IE But Does Not Work In Chrome

Resolution when Inject JS activity works in IE but does not work in Chrome.

The scripts injected with the “Inject JS” activity, run in the context of the extension content script (not in the context of the web page). Indicating that all the JS environment defined in the page, is not available for the injected scripts. However, the scripts have access to the DOM of the page.

That is the reason why the injected script might not be able to access some of the references and "System.Runtime.InteropServices.COMException: ReferenceError: is not defined" error is obtained, whereas the same script might work in IE when called using the activity.

  • If scripts are run via debugger console, the context of the page is located, by default. This is called ‘Top’. See the below screenshot:

![](upload://vlgfCA1UBPBHcAJtAWpJD4KP2iF.html)

  • Use the dropdown and select the extension space, called “UiPath Web Automation”. This will be available only after indicating in the Browser from Studio or UiExplorer (or after automation is run, that targets the Browser). After selecting it should look like this:

![](upload://vEopK9DmsDZBGocyGYGyixLPk1s.html)

  • Now verify in the console if the script executes successfully. This is the behavior with respect extension based browser automation (Chrome / Edge / Firefox).

However “Inject JS” works with this script if used in Internet Explorer or with WebDriver automation. In these cases, run in the context of the page (there’s no extension) so access is present to the full JS context. Try using webdriver automation to inject the scripts.

Note: Web driver automation is available starting from the 2019.10 version of Studio

Read more on the WebDriver Protocol .

A post was split to a new topic: Inject JS via Edge Browser

1 Debugger Console Location

2 UiPath Web Automation

Hello,

Please find the images.

Thank you,
Support KB Team