MV3 Content Script Limits..

168 views
Skip to first unread message

Sonny Chee

unread,
Mar 12, 2022, 5:15:45 PM3/12/22
to Chromium Extensions
Hey Guys,

My understanding is that under MV3, content scripts (unlike the background service worker) can run for however long they want.  I didn't see any specific changes to them in migrating from mv2 to mv3...

wOxxOm

unread,
Mar 13, 2022, 11:29:04 AM3/13/22
to Chromium Extensions, sonny...@gmail.com
The "isolated world" where the content scripts run doesn't mean they are separate from the page. Content scripts run in the page as an integral part of the page, just like any other page script, so it's impossible to pause them separately from the page. They run as long as the page itself.

Sonny Chee

unread,
Mar 13, 2022, 2:02:37 PM3/13/22
to Chromium Extensions, wOxxOm, Sonny Chee
When you say: 


"They run as long as the page itself."

Does that mean, they run as long as the tab is open? More concretely, if I have setTimeout( function, 10*60*1000 ), can I be certain that the function will be execute in 10 minutes?

hrg...@gmail.com

unread,
Mar 13, 2022, 6:04:40 PM3/13/22
to Chromium Extensions, sonny...@gmail.com, wOxxOm
 
can I be certain that the function will be execute in 10 minutes?

You can't be certain because:
  1. A tab can navigate to another page, causing your content script to be unloaded
  2. A tab can be automatically discarded  by the browser if it needs to release RAM
  3. A tab that hasn't been visible for more than 5 minutes will be throttled down and setTimeout will run at most once per minute.

 

wOxxOm

unread,
Mar 13, 2022, 6:50:47 PM3/13/22
to Chromium Extensions, hrg...@gmail.com, sonny...@gmail.com, wOxxOm
The page can also clear your timer intentionally or accidentally because timers aren't isolated, so it's more reliable to use chrome.alarms API in the background script  and send a message to the content script when the alarm goes off.
Reply all
Reply to author
Forward
0 new messages