executeScripts executes twice (7.0.9) (Chrome)

Hi,

It seems that executeScripts executes twice in 7.0.9 version.

How to reproduce?
Create a simple macro with only one command:

executeScript console.log(‘asd’)

Run and check console in Chrome.

The new version will show 2 results, while the older UI.Visions will show it once.

1 Like

Do you have a video of this issue for me? In my test it runs only once:

I do not have the app to record video, but here is a screenshot with the log and console:

I’ve updated it to 7.0.10 and the issue still exists.

I’ve tried disabling all other extensions but this also didn’t help.

I do not have XModules installed, maybe this is the issue?

Chrome version 64 bit 101.0.4951.54.

Edit2. On other laptop the console.log shows 3 results.
Edit3. On my laptop somehow I got 3 results also. Trying to figure out why sometimes it is 2 and 3, but never 1. I got 3 results when I had many tabs opened but can’t reproduce the 3 results again.

Edit4. I’ve installed beta 7.0.11 and it seems like it is working the same way as in your video - 1 result and few “Refused to execute inline script because it violates the following Content Security Policy…” errors.

The only way to produce 2 console.log results after installing 7.0.11 is by opening a completly new tab and running 7.0.10 there.

E.g.,
If you run 7.0.11 on X tab and then run 7.0.10 on the same tab - the console log will show 1 result for both cases.

If you run 7.0.10 on X tab and then run 7.0.11 on the same tab - the console log will show 2 results for both cases.

To reset this behaviour you need to open a completly new tab.

Hi there, I’ve got exactly the same problem here suddenly(or maybe just because it upgrade without my caution?).
All executeScript commands ran correctly before, and all of a sudden it appears that it ran twice every time…
I’ve checked over the broswer, the web app, and OS(windows vs. Ubuntu), and finally focus this error on UV.RPA…
So have you pointed out the root cause and fixed it in the latest version?

Looks like the bug is back in 7.0.14 :frowning_face:

It was fine in 7.0.11 for sure.

Thanks for the info. It is a bit strange because we actually did not touch this command with the update - but it seems somehow there was a side effect.

Hi users and developers,
It’s glad that I’ve figured out the root cause of this issue, and has a (maybe not perfect) solution to that.
I’d like to share it with you in case you’re bothering by this weird issue.

Phenomenon
executeScript scripts will be executed twice(or more) each time (I’ve seen 4 times on a speedy ubuntu server);
Root cause: in source code level, this is caused by duplicated injection of “inject.js” into the main page document.
Details of issue:
Injection is done in the function “insertScript” with dynamically created node and insertion into main page document.
And to indicate the injection is finished & ready, there’s a flag in the document which will be set through postMessage to the injected “inject.js”, as following code shows:
(code snippet from “content_script.js”)
function untilInjected() {

const injected = document.body.getAttribute(‘data-injected’);
// by XJP: bugfix v2(maybe final version^_^) for duplicate injection
if (injected) {
return Promise.resolve(api);
utils_1.insertScript(web_extension_1.default.runtime.getURL(‘inject.js’));

  return ts_utils_1.retry(() => {
      log_1.default('sending INJECT_READY');
      return cs_postmessage_1.postMessage(window, window, { cmd: '**INJECT_READY**' }, '*', 500);
  }
  ...

(code snippet from “inject.js”)

(0, _cs_postmessage.onMessage)(window, function (_ref) {
var cmd = _ref.cmd,
args = _ref.args;
switch (cmd) {
case ‘INJECT_READY’:
{
document.body.setAttribute(‘data-injected’, ‘done’);
return true;
}

This is an elegant design.
But the result is not ideal.
Because of **async execution fact** of javascript.

In a word, this “postMessage” and set-flag action will not block the execution of the whole script.
Thus after the injection action started and before the flag is set(usually this “gap” is several milliseconds or even 1 second, depending on the speed of the computer), the injection will be triggered multiple times, because of multiple times window/frame initiation and updates.

Bug Fix

Introduce a new transient state of “injecting” showing that the injection is started but not succeeded, thus prevent duplicate injection, and will not affect the normal processes waiting for real injection ready.
(all bugfix codes are in “content_script.js”)

var insertScript = exports.insertScript = function insert Script(file) {
// by XJP: set “doing” flag at the beginning could stop any second request for injection.
document.body.setAttribute(‘data-injected’, ‘injecting’);
var s = document.constructor.prototype.createElement.call(document, ‘script’);
s.setAttribute(‘type’, ‘text/javascript’);
s.setAttribute(‘src’, file);
document.documentElement.appendChild(s);
s.parentNode.removeChild(s);
};

function untilInjected() {

const injected = document.body.getAttribute(‘data-injected’);
// by XJP: bugfix v2(maybe final version^_^) for duplicate injection
if (injected && injected == “done”) {
return Promise.resolve(api);
}else if (injected != “injecting”){ // by XJP: otherwise if injection has started, DO NOT inject AGAIN.
utils_1.insertScript(web_extension_1.default.runtime.getURL(‘inject.js’));
}
return ts_utils_1.retry(() => {

Two functions modified: set “injecting” flag in insertScript(), check this flag in untilInjected().

@admin you could check this solution, and think of fix it officially in your later release.
@matmat there may be some trivial problem when you try to modify scripts in the installed extension folder, there’s already solution to this in the internet, thus it’s not included in this thread.