Let me rewrite the question. I have tested the code and the issue should be reproduceable.
There are two html files, test1.html and test2.html, and two js files: file1.js and file2.js.

test1.html:

```
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
    <p>Hello, It's test1 page!</p>
    <button onclick = "func0()">populate contacts</button>
    <script src="file1.js"></script>
</body>
</html>

```

As you can see, file1.js is included in test1.html.

test2.html:

```
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
    <p>Turn to test2 page now!</p>
    <button onclick = "func2()">Try me</button>
    <script src="file1.js"></script>
    <script src="file2.js"></script>
</body>
</html>

```

both file1.js and file2.js are included in test2.html.

file1.js:

```
"use strict";

var contacts = [];

function func0() {
    contacts.push('mike');
    contacts.push('tom');
    contacts.push('joe');
    window.location.replace("test2.html");
}

function func1(msgType, uuid) {
    if(isArrayEmpty(contacts)) {
        alert("contacts is empty");
        return;
    }
    contacts.forEach(function(contact) {
        console.log(contact + " sends msg with type = " + msgType + ", and msg id = " + uuid);
    });
}

function isArrayEmpty(array) {
    if (!Array.isArray(array) || !array.length) {
        return true;
    }
    return false;
}

```

file2.js:

```
"use strict";

function func2() {
    func1('OPEN', '1234');
}

```

As you can see, func1 of file1.js was invoked by func2 of file2.js. But the variable contacts declared in file1.js was empty.
Thus the loop over contacts were not actually done. contacts should not be empty as func0 of file1.js populated values to it. func0 was invoked by clicking "populate contacts" button in test1.html.

That's actually happened in my read code.

Seek an answer here.

Edit on 03/31/2021: can anybody help on this?