Chrome extension manifest v3: executing script before website's scripts

123 views
Skip to first unread message

Eugene Bos

unread,
Dec 18, 2023, 1:31:09 PM12/18/23
to Chromium Extensions
I'm using a content script that receives data from `chrome.storage.local.get` and then executes.

I want it to complete all execution before the website's scripts start executing.

The problem is: that getting data from `chrome.storage.local.get` takes time and is asynchronous, so it starts to execute before the website's scripts but finishes after.

Is there a way to fix it? Like, block the main thread before it finishes or something? Or pass information to it without using `chrome.storage.local.get`? Or should I delay all requests of the page with `chrome.webRequest`?

  "content_scripts": [
    {
      "run_at": "document_start",
      "matches": ["<all_urls>"],
      "js": ["content.js"],
      "match_about_blank" : true
    }
  ],


content.js:
(async () => {
   // website's scripts are not yet executed
   let data = await chrome.storage.local.get("data");
   // website's scripts are already executed
})();


Jackie Han

unread,
Dec 19, 2023, 8:45:58 AM12/19/23
to Eugene Bos, Chromium Extensions
As your own explanation, there is no good way to stop the page code from executing.

--
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/ddd4c6f0-691d-4d65-812f-5d065c41586cn%40chromium.org.
Reply all
Reply to author
Forward
0 new messages