Fastest way to transfer object from background script to content script

Viewed 20

I need to transfer a simple object with my web extensions settings.

What is the fastest way to transfer them to my content script so I could load stuff instantly?

I've tried stuff like messaging and through ports but it's all a bit slow.

My fallback if I don't find a good answer is doing:

const myCode = `
mutationObserver that waits until head exists and then add an element with a stringified object inside`;

chrome.scripting.executing({runAt:"document_start", code:myCode})

I have a mutation observer since this site loads it's document slowly and instead of just storing it as a function so the main content script can call it is because in Firefox the script loads too fast for the window to store it or something. I am not sure why it does that in Firefox.

And for some reason that mutationObserver is 2 times faster than messaging and ports.

0 Answers
Related