Manipulate UI when tab is not in focus

136 views
Skip to first unread message

William A.

unread,
Mar 23, 2023, 10:10:52 PM3/23/23
to Chromium Extensions
With chrome extension, is there a way to manipulate contents of a UI when the tab is not in focus? 

For example, say if I am running js script that randomly click on various places on the front end, what if I want to continuously do this even when the browser is minimised? How can I do that? 

Any help will be deeply appreciated. 

Regards
William

Simeon Vincent

unread,
Mar 24, 2023, 1:58:41 AM3/24/23
to William A., Chromium Extensions

When a tab is in the background, Chrome will throttle and may even discard tabs. I'm not aware of any techniques that will prevent Chrome from discarding an inactive tab. In fact, in issue 1425632 a Chromium engineer expressly says that "not running `beforeunload`", which has historically been a way to prevent a tab from being unloaded, "is by design and we recommend web developers use different approaches to be more resilient to tabs unexpectedly going away." 

Can you share more about what you're trying to do? You mentioned a script that will "randomly click on various places on [a website]"; what's the point of that kind of background activity? Based on your answer folks here may be able to provide more useful guidance.

Simeon - dotproto


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/194808e9-a651-4422-94ce-7f3ebfce612dn%40chromium.org.

William A.

unread,
Mar 24, 2023, 10:16:33 AM3/24/23
to Simeon Vincent, Chromium Extensions
Thank you Simon for the reply. This is very helpful. 

We were just planning some features that runs on the UI, it is still in the planning stages. Will think over this and get back. 

Regards
William A. 

hrg...@gmail.com

unread,
Mar 24, 2023, 5:54:19 PM3/24/23
to Chromium Extensions, William A., Chromium Extensions, Simeon Vincent
You can prevent a tab being discarded with this:
chrome.tabs.update(tabId, {autoDiscardable: false})  

You can prevent a tab being throttled by playing almost-silent audio in the tab every 5 minutes or less.

Simeon Vincent

unread,
Mar 30, 2023, 3:49:17 AM3/30/23
to hrg...@gmail.com, Chromium Extensions, William A.
Good call, Hr, I totally forgot about that!

Out of curiosity, have you tested to make sure this prevents Memory Saver from discarding a tab? The property name implies it should, but I wouldn't be surprised if this hasn't been explicitly considered yet.

Simeon - @dotproto

hrg...@gmail.com

unread,
Mar 30, 2023, 9:59:17 PM3/30/23
to Chromium Extensions, Simeon Vincent, Chromium Extensions, William A., hrg...@gmail.com
The autoDiscardable boolean flag controls the "Auto Discardable" column in chrome://discards. When a tab has this column unchecked, it will not be automatically discarded by the browser but it can still be discarded programmatically via chrome.tabs.discard() or manually by clicking on "Urgent discard" in chrome://discards.
Reply all
Reply to author
Forward
0 new messages