Run content script on already opened tabs

1,233 views
Skip to first unread message

Nikhil Parmar Parmar

unread,
May 31, 2022, 1:48:44 AM5/31/22
to Chromium Extensions
Hello,

I am trying to run content script in already opened tabs. If I reload the tab, it is working fine.

NOTE: I am running script via manifest file only. I cannot use chrome.scripting.executeScript.

Menifest V3 file:

"content_scripts": [
 {
    "matches": ["http://*/*", "https://*/*", "<all_urls>"],
    "js":["contentScript.bundle.js"],
    "css": ["content.styles.css"],
    "run_at":"document_idle"
  }
]

Usama Tahir

unread,
May 31, 2022, 4:16:30 AM5/31/22
to Chromium Extensions, nik...@loot.discount
Hi,

There will be no content script injected on already opened tabs. Static declaration of content script is injected on matched URL patterns at document_start, document_end or document_idle i.e. almost at start or after DOM is loaded. So in above mentioned constraints I would suggest getting all tabs URLs and IDs and try reloading the already opened pages programatically or you have to use programmatic injection of content script accordingly. 

For reloading tab you can this out 

wOxxOm

unread,
May 31, 2022, 10:10:11 AM5/31/22
to Chromium Extensions, usamam...@gmail.com, nik...@loot.discount
Use chrome.scripting.exectuteScript as shown in this topic:
Reply all
Reply to author
Forward
0 new messages