I use an extension in Chrome (Bulk URL Opener). This extension opens multiple links at an interval of seconds. It also opens a new tab (x1) that has play and pause buttons. When pressing the play button, the extension starts opening new tabs to the right and keeps opening. When pressing the pause button, it stops the opening of a new tab.
What I want AutoHotkey to do here is to read the number of tabs opened in Chrome. If there are less than 10 tabs, then I want AutoHotkey to give input to the x1 tab and start the opening of the new tab. Also, if the number of opened tabs is more than 12, then I want AutoHotkey to give input again to the x1 tab and stop the opening of a new tab.
Basically, I want only 10 or 12 tabs to be opened in Chrome at once and if I close a tab or two I want a new tab to be automatically opened. Is there a way that I can achieve this?
Read this source: https://dev.to/dcodeyt/send-data-between-tabs-with-javascript-2oa
Initializing a channel happens like this:
const channel = new BroadcastChannel("my-channel");
This is how you can receive a message:
channel.addEventListener("message", e => {
console.log(e.data);
});
This is how you can post a message
channel.postMessage("Hello world");
Now, knowing all these, let's see the
If you open tabs, you will open some URL for each of them. Assuming that you are in control of the source-code of the pages you open, you can do the following:
message event listener both on your main tab and the open tabsExample
const channel = new BroadcastChannel("my-channel");
channel.addEventListener("message", e => {
if (e.data === "ping") channel.postMessage("pong");
});
var pongCount = 0;
var pongLimit = 12;
const channel = new BroadcastChannel("my-channel");
channel.addEventListener("message", e => {
if (e.data === "pong") pongCount++;
});
setInterval(function() {
pongCount = 0;
channel.postMessage("ping");
setTimeout(function() {
for (let pongIndex = pongCount + 1; pongIndex < pongLimit; pongIndex++) {
//open a tab
}
}, 100);
}, 1000);
Note that the tick code needs to be in the main tab
EDIT
It seems that there is no access to the pages that are being loaded. If that's the case, one can implement a proxy app that will transmit the request to the target pages to bypass Chrome's restrictions and have wrapper pages where you have full access in terms of source-code and therefore that would be able to send and receive messages.
Alternatively one can use the chrome.tabs extension, like
chrome.tabs.query({windowType:'normal'}, function(tabs) {
console.log('Number of open tabs in all normal browser windows:',tabs.length);
});
But for that purpose, the given extension will be needed to be installed: https://developer.chrome.com/docs/extensions/reference/tabs/