My question concerns the order of statement execution between the background script and a content script when a function in one invokes a function in the other.
For example, suppose a function in the background script posts a message to the content script using
portFromCS[id].postMessage(obj), which invokes a function in the content script, but there are still lines of code following the postMessage statement in the background script’s function.
Will execution move from the background script to the content script at the point of posting the message and begin again after the function in the content script invoked by that message completes/returns, or can both functions run concurrently? Does the background script even know that the function in the content script completed, apart from the content script posting a return message?
The fuller scenario is that a user action in the page is picked up by an event listener in the content script which posts a message to the background script requesting it to do something, such as retrieve data, after which the background script posts a message to the content script informing it of what to do with the data it is passing back.
I realize it doesn’t matter much in the respect that the scripts cannot share objects directly; however, I’m trying to figure out how to handle error catching properly; and in some cases timing may be important, although I’m not certain about that yet.