Content_scripts document_start can not match storage, port

I am trying to implement the custom navigator.userAgent and other parameters.
But I found that I could not make my content_scripts execute before the page scripts were executed. I have set up document_start.

But because the content_scripts need to modify the useragnet according to the user configuration, so you need to get the user configuration from storage or background.

As the storage and port is asynchronous function, there is delay, and other content_scripts from the storage or background after the user configuration has been completed after the completion of the page script, the page has been read navigator.userAgent, plug-in modification is invalid.

Will the obstruction approach get storage? Or is there any other way to block and communicate with background?

Now feel document_start basic ineffective, the general plug-ins need to decide according to user configuration work, but because of the storage limit, resulting in even if set document_start, the actual script can not be implemented in document_start.

console log:

page-eater… page-eater.js:1:1
js1… a.html:1:1
Html page script is executed … a.html:4:5
browser.storage.local.get(config):config page-eater.js:17:9
In content script, received message from background script: page-eater.js:25:5
postMessage(config)… page-eater.js:26:5

page-eater.js

console.log(“page-eater…”);

var script1 = document.createElement(‘script’);
script1.type = “text/javascript”;

var scriptText = console.log("js1..."); ;

var scriptTextNode = document.createTextNode(scriptText);

script1.appendChild(scriptTextNode);
var node = (document.documentElement || document.head || document.body );
node.insertBefore(script1, node.firstChild);

browser.storage.local.get(“config”).then(function (data) {
if (“config” in data) {
console.debug(“browser.storage.local.get(config):” + data.config);
}
});

var myPort = browser.runtime.connect({name: “port-from-cs”});

myPort.onMessage.addListener(function (m) {
console.log("In content script, received message from background script: ");
console.log(m);
});

background.js

browser.storage.local.set({“config”:“config”});

function connected(portFromCS) {
portFromCS.postMessage(“postMessage(config)…”);
}

browser.runtime.onConnect.addListener(connected);