I am currently writing code for a chrome extension where it switches to random tabs and performs various actions. I am writing the code in Javascript but I am willing to use python. How can I make the code scroll down to the bottom of the page and back up within a certain time?
Here is the background.js file of the extension:
// Set up a timer to perform actions every 5 seconds
setInterval(performActions, 5000);
function performActions() {
// Get a list of all open tabs in the current window
chrome.tabs.query({currentWindow: true}, function(tabs) {
// Select the third tab with a higher probability
var tab;
if (Math.random() < 0.8) {
tab = tabs[2];
} else {
tab = tabs[Math.floor(Math.random() * (tabs.length - 1))];
}
// Activate the selected tab
chrome.tabs.update(tab.id, {active: true});
// Send a message to the selected tab's content script
chrome.tabs.sendMessage(tab.id, {action: 'scroll'});
});
}
I tried to use the "window.scrollTo" and it didn't work. I also tried to use the pynput module. I don't know what the issue is.